comparison mercurial/treediscovery.py @ 43076:2372284d9457

formatting: blacken the codebase This is using my patch to black (https://github.com/psf/black/pull/826) so we don't un-wrap collection literals. Done with: hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S # skip-blame mass-reformatting only # no-check-commit reformats foo_bar functions Differential Revision: https://phab.mercurial-scm.org/D6971
author Augie Fackler <augie@google.com>
date Sun, 06 Oct 2019 09:45:02 -0400
parents e7aa113b14f7
children 687b865b95ad
comparison
equal deleted inserted replaced
43075:57875cf423c9 43076:2372284d9457
16 ) 16 )
17 from . import ( 17 from . import (
18 error, 18 error,
19 pycompat, 19 pycompat,
20 ) 20 )
21
21 22
22 def findcommonincoming(repo, remote, heads=None, force=False): 23 def findcommonincoming(repo, remote, heads=None, force=False):
23 """Return a tuple (common, fetch, heads) used to identify the common 24 """Return a tuple (common, fetch, heads) used to identify the common
24 subset of nodes between repo and remote. 25 subset of nodes between repo and remote.
25 26
77 while unknown: 78 while unknown:
78 n = unknown.popleft() 79 n = unknown.popleft()
79 if n[0] in seen: 80 if n[0] in seen:
80 continue 81 continue
81 82
82 repo.ui.debug("examining %s:%s\n" 83 repo.ui.debug("examining %s:%s\n" % (short(n[0]), short(n[1])))
83 % (short(n[0]), short(n[1]))) 84 if n[0] == nullid: # found the end of the branch
84 if n[0] == nullid: # found the end of the branch
85 pass 85 pass
86 elif n in seenbranch: 86 elif n in seenbranch:
87 repo.ui.debug("branch already found\n") 87 repo.ui.debug("branch already found\n")
88 continue 88 continue
89 elif n[1] and knownnode(n[1]): # do we know the base? 89 elif n[1] and knownnode(n[1]): # do we know the base?
90 repo.ui.debug("found incomplete branch %s:%s\n" 90 repo.ui.debug(
91 % (short(n[0]), short(n[1]))) 91 "found incomplete branch %s:%s\n"
92 search.append(n[0:2]) # schedule branch range for scanning 92 % (short(n[0]), short(n[1]))
93 )
94 search.append(n[0:2]) # schedule branch range for scanning
93 seenbranch.add(n) 95 seenbranch.add(n)
94 else: 96 else:
95 if n[1] not in seen and n[1] not in fetch: 97 if n[1] not in seen and n[1] not in fetch:
96 if knownnode(n[2]) and knownnode(n[3]): 98 if knownnode(n[2]) and knownnode(n[3]):
97 repo.ui.debug("found new changeset %s\n" % 99 repo.ui.debug("found new changeset %s\n" % short(n[1]))
98 short(n[1])) 100 fetch.add(n[1]) # earliest unknown
99 fetch.add(n[1]) # earliest unknown
100 for p in n[2:4]: 101 for p in n[2:4]:
101 if knownnode(p): 102 if knownnode(p):
102 base.add(p) # latest known 103 base.add(p) # latest known
103 104
104 for p in n[2:4]: 105 for p in n[2:4]:
105 if p not in req and not knownnode(p): 106 if p not in req and not knownnode(p):
106 r.append(p) 107 r.append(p)
107 req.add(p) 108 req.add(p)
108 seen.add(n[0]) 109 seen.add(n[0])
109 110
110 if r: 111 if r:
111 reqcnt += 1 112 reqcnt += 1
112 progress.increment() 113 progress.increment()
113 repo.ui.debug("request %d: %s\n" % 114 repo.ui.debug(
114 (reqcnt, " ".join(map(short, r)))) 115 "request %d: %s\n" % (reqcnt, " ".join(map(short, r)))
116 )
115 for p in pycompat.xrange(0, len(r), 10): 117 for p in pycompat.xrange(0, len(r), 10):
116 with remote.commandexecutor() as e: 118 with remote.commandexecutor() as e:
117 branches = e.callcommand('branches', { 119 branches = e.callcommand(
118 'nodes': r[p:p + 10], 120 'branches', {'nodes': r[p : p + 10],}
119 }).result() 121 ).result()
120 122
121 for b in branches: 123 for b in branches:
122 repo.ui.debug("received %s:%s\n" % 124 repo.ui.debug(
123 (short(b[0]), short(b[1]))) 125 "received %s:%s\n" % (short(b[0]), short(b[1]))
126 )
124 unknown.append(b) 127 unknown.append(b)
125 128
126 # do binary search on the branches we found 129 # do binary search on the branches we found
127 while search: 130 while search:
128 newsearch = [] 131 newsearch = []
138 f = 1 141 f = 1
139 for i in l: 142 for i in l:
140 repo.ui.debug("narrowing %d:%d %s\n" % (f, len(l), short(i))) 143 repo.ui.debug("narrowing %d:%d %s\n" % (f, len(l), short(i)))
141 if knownnode(i): 144 if knownnode(i):
142 if f <= 2: 145 if f <= 2:
143 repo.ui.debug("found new branch changeset %s\n" % 146 repo.ui.debug(
144 short(p)) 147 "found new branch changeset %s\n" % short(p)
148 )
145 fetch.add(p) 149 fetch.add(p)
146 base.add(i) 150 base.add(i)
147 else: 151 else:
148 repo.ui.debug("narrowed branch search to %s:%s\n" 152 repo.ui.debug(
149 % (short(p), short(i))) 153 "narrowed branch search to %s:%s\n"
154 % (short(p), short(i))
155 )
150 newsearch.append((p, i)) 156 newsearch.append((p, i))
151 break 157 break
152 p, f = i, f * 2 158 p, f = i, f * 2
153 search = newsearch 159 search = newsearch
154 160
155 # sanity check our fetch list 161 # sanity check our fetch list
156 for f in fetch: 162 for f in fetch:
157 if knownnode(f): 163 if knownnode(f):
158 raise error.RepoError(_("already have changeset ") 164 raise error.RepoError(_("already have changeset ") + short(f[:4]))
159 + short(f[:4]))
160 165
161 base = list(base) 166 base = list(base)
162 if base == [nullid]: 167 if base == [nullid]:
163 if force: 168 if force:
164 repo.ui.warn(_("warning: repository is unrelated\n")) 169 repo.ui.warn(_("warning: repository is unrelated\n"))
165 else: 170 else:
166 raise error.Abort(_("repository is unrelated")) 171 raise error.Abort(_("repository is unrelated"))
167 172
168 repo.ui.debug("found new changesets starting at " + 173 repo.ui.debug(
169 " ".join([short(f) for f in fetch]) + "\n") 174 "found new changesets starting at "
175 + " ".join([short(f) for f in fetch])
176 + "\n"
177 )
170 178
171 progress.complete() 179 progress.complete()
172 repo.ui.debug("%d total queries\n" % reqcnt) 180 repo.ui.debug("%d total queries\n" % reqcnt)
173 181
174 return base, list(fetch), heads 182 return base, list(fetch), heads