comparison hgext/narrow/narrowcommands.py @ 42415:c767e655ffda

narrow: use narrow_widen wireproto command to widen in case of ellipses Few releases ago, we introduce narrow_widen wireproto command to be used to widen narrow repositories. Before this patch, that was used in non-ellipses cases only. In ellipses cases, we still do exchange.pull() which can pull more data than required. After this patch, the client will first check whether server supports doing ellipses widening using wireproto command or not by checking server's wireproto capability. If the server is upto date and support latest ellipses capability, we call the wireproto command. Otherwise we fallback to exchange.pull() like before. The compat code make sure that things works even if one of the client or server is old. The initial version of this patch does not had this compat code. It's added to help Google release things smoothly internally. I plan to drop the compat code before the upcoming major release. Due to change to wireproto command, the code looks a bit dirty, next patches will clean that up. Differential Revision: https://phab.mercurial-scm.org/D6436
author Pulkit Goyal <7895pulkit@gmail.com>
date Wed, 22 May 2019 02:59:48 +0530
parents 7d4ee14ff92d
children 8381b7067f17
comparison
equal deleted inserted replaced
42412:127937874395 42415:c767e655ffda
144 kwargs['includepats'] = include 144 kwargs['includepats'] = include
145 if exclude: 145 if exclude:
146 kwargs['excludepats'] = exclude 146 kwargs['excludepats'] = exclude
147 # calculate known nodes only in ellipses cases because in non-ellipses cases 147 # calculate known nodes only in ellipses cases because in non-ellipses cases
148 # we have all the nodes 148 # we have all the nodes
149 if wireprototypes.ELLIPSESCAP in pullop.remote.capabilities(): 149 if wireprototypes.ELLIPSESCAP1 in pullop.remote.capabilities():
150 kwargs['known'] = [node.hex(ctx.node()) for ctx in 150 kwargs['known'] = [node.hex(ctx.node()) for ctx in
151 repo.set('::%ln', pullop.common) 151 repo.set('::%ln', pullop.common)
152 if ctx.node() != node.nullid] 152 if ctx.node() != node.nullid]
153 if not kwargs['known']: 153 if not kwargs['known']:
154 # Mercurial serializes an empty list as '' and deserializes it as 154 # Mercurial serializes an empty list as '' and deserializes it as
251 # exchanging ellipses nodes. In future we should add ellipses as a client 251 # exchanging ellipses nodes. In future we should add ellipses as a client
252 # side requirement (maybe) to distinguish a client is shallow or not and 252 # side requirement (maybe) to distinguish a client is shallow or not and
253 # then send that information to server whether we want ellipses or not. 253 # then send that information to server whether we want ellipses or not.
254 # Theoretically a non-ellipses repo should be able to use narrow 254 # Theoretically a non-ellipses repo should be able to use narrow
255 # functionality from an ellipses enabled server 255 # functionality from an ellipses enabled server
256 ellipsesremote = wireprototypes.ELLIPSESCAP in remote.capabilities() 256 remotecap = remote.capabilities()
257 ellipsesremote = any(cap in remotecap
258 for cap in wireprototypes.SUPPORTED_ELLIPSESCAP)
259
260 # check whether we are talking to a server which supports old version of
261 # ellipses capabilities
262 isoldellipses = (ellipsesremote and wireprototypes.ELLIPSESCAP1 in
263 remotecap and wireprototypes.ELLIPSESCAP not in remotecap)
257 264
258 def pullbundle2extraprepare_widen(orig, pullop, kwargs): 265 def pullbundle2extraprepare_widen(orig, pullop, kwargs):
259 orig(pullop, kwargs) 266 orig(pullop, kwargs)
260 # The old{in,ex}cludepats have already been set by orig() 267 # The old{in,ex}cludepats have already been set by orig()
261 kwargs['includepats'] = newincludes 268 kwargs['includepats'] = newincludes
277 ds = repo.dirstate 284 ds = repo.dirstate
278 p1, p2 = ds.p1(), ds.p2() 285 p1, p2 = ds.p1(), ds.p2()
279 with ds.parentchange(): 286 with ds.parentchange():
280 ds.setparents(node.nullid, node.nullid) 287 ds.setparents(node.nullid, node.nullid)
281 with wrappedextraprepare: 288 with wrappedextraprepare:
282 with repo.ui.configoverride(overrides, 'widen'): 289 if isoldellipses:
283 exchange.pull(repo, remote, heads=common) 290 exchange.pull(repo, remote, heads=common)
291 else:
292 known = [node.hex(ctx.node()) for ctx in
293 repo.set('::%ln', common)
294 if ctx.node() != node.nullid]
295
296 with remote.commandexecutor() as e:
297 bundle = e.callcommand('narrow_widen', {
298 'oldincludes': oldincludes,
299 'oldexcludes': oldexcludes,
300 'newincludes': newincludes,
301 'newexcludes': newexcludes,
302 'cgversion': '03',
303 'commonheads': common,
304 'known': known,
305 'ellipses': True,
306 }).result()
307 trmanager = exchange.transactionmanager(repo, 'widen',
308 remote.url())
309 with trmanager:
310 op = bundle2.bundleoperation(repo,
311 trmanager.transaction, source='widen')
312 bundle2.processbundle(repo, bundle, op=op)
313
284 with ds.parentchange(): 314 with ds.parentchange():
285 ds.setparents(p1, p2) 315 ds.setparents(p1, p2)
286 else: 316 else:
287 with remote.commandexecutor() as e: 317 with remote.commandexecutor() as e:
288 bundle = e.callcommand('narrow_widen', { 318 bundle = e.callcommand('narrow_widen', {