comparison mercurial/setdiscovery.py @ 35889:5cfdf6137af8

setdiscovery: don't call "heads" wire command when heads specified Our custom server has too many heads to announce (one per code review, plus a public head), but it still lets the user request one of them by doing hg pull -r <some expression> After the client has resolved the expression to a set of nodeids by calling the "lookup" wire command, it will start the discovery phase. Before this patch, that doesn't take the requested heads into account and unconditionally calls the server's "heads" command to find all its heads. One consequence of that the "all remote heads known locally" case triggers if the client already had the public head and the user will see a "no changes found" message that's unrelated to the head they requested. That message confused me for a while. More imporantly, it also means that pullop.cgresult incorrectly (given our arguably misbehaving server) gets set to 0 (no changesets added), which confused some of our extensions. This patch makes it so the client skips the "heads" command if the user requested specific revisions. Since the "heads" command is normally batched with the first "known" command and calculating the list of heads is probably cheap, I don't expect much improvement in speed from this. Differential Revision: https://phab.mercurial-scm.org/D1962
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 01 Feb 2018 10:29:24 -0800
parents f77121b6bf1b
children 613954a17a25
comparison
equal deleted inserted replaced
35888:8a7140ec4c89 35889:5cfdf6137af8
128 """return a random subset of sample of at most desiredlen item""" 128 """return a random subset of sample of at most desiredlen item"""
129 if len(sample) > desiredlen: 129 if len(sample) > desiredlen:
130 sample = set(random.sample(sample, desiredlen)) 130 sample = set(random.sample(sample, desiredlen))
131 return sample 131 return sample
132 132
133 def findcommonheads(ui, local, remote, 133 def findcommonheads(ui, local, remote, heads=None,
134 initialsamplesize=100, 134 initialsamplesize=100,
135 fullsamplesize=200, 135 fullsamplesize=200,
136 abortwhenunrelated=True, 136 abortwhenunrelated=True,
137 ancestorsof=None): 137 ancestorsof=None):
138 '''Return a tuple (common, anyincoming, remoteheads) used to identify 138 '''Return a tuple (common, anyincoming, remoteheads) used to identify
153 roundtrips += 1 153 roundtrips += 1
154 ownheads = dag.heads() 154 ownheads = dag.heads()
155 sample = _limitsample(ownheads, initialsamplesize) 155 sample = _limitsample(ownheads, initialsamplesize)
156 # indices between sample and externalized version must match 156 # indices between sample and externalized version must match
157 sample = list(sample) 157 sample = list(sample)
158 batch = remote.iterbatch() 158 if heads:
159 batch.heads() 159 srvheadhashes = heads
160 batch.known(dag.externalizeall(sample)) 160 yesno = remote.known(dag.externalizeall(sample))
161 batch.submit() 161 else:
162 srvheadhashes, yesno = batch.results() 162 batch = remote.iterbatch()
163 batch.heads()
164 batch.known(dag.externalizeall(sample))
165 batch.submit()
166 srvheadhashes, yesno = batch.results()
163 167
164 if cl.tip() == nullid: 168 if cl.tip() == nullid:
165 if srvheadhashes != [nullid]: 169 if srvheadhashes != [nullid]:
166 return [nullid], True, srvheadhashes 170 return [nullid], True, srvheadhashes
167 return [nullid], False, [] 171 return [nullid], False, []