comparison hgext/narrow/narrowcommands.py @ 42416:8381b7067f17

narrow: refactor code around widening complicated by previous patch Previous patch while adding support for using narrow_widen wireproto command, complicated the code a bit. This patch refactors that. Differential Revision: https://phab.mercurial-scm.org/D6437
author Pulkit Goyal <7895pulkit@gmail.com>
date Thu, 23 May 2019 02:48:25 +0530
parents c767e655ffda
children 383fdfa6bba9
comparison
equal deleted inserted replaced
42415:c767e655ffda 42416:8381b7067f17
276 repo.setnarrowpats(newincludes, newexcludes) 276 repo.setnarrowpats(newincludes, newexcludes)
277 repo.setnewnarrowpats = setnewnarrowpats 277 repo.setnewnarrowpats = setnewnarrowpats
278 # silence the devel-warning of applying an empty changegroup 278 # silence the devel-warning of applying an empty changegroup
279 overrides = {('devel', 'all-warnings'): False} 279 overrides = {('devel', 'all-warnings'): False}
280 280
281 common = commoninc[0]
281 with ui.uninterruptible(): 282 with ui.uninterruptible():
282 common = commoninc[0]
283 if ellipsesremote: 283 if ellipsesremote:
284 ds = repo.dirstate 284 ds = repo.dirstate
285 p1, p2 = ds.p1(), ds.p2() 285 p1, p2 = ds.p1(), ds.p2()
286 with ds.parentchange(): 286 with ds.parentchange():
287 ds.setparents(node.nullid, node.nullid) 287 ds.setparents(node.nullid, node.nullid)
288 if isoldellipses:
288 with wrappedextraprepare: 289 with wrappedextraprepare:
289 if isoldellipses: 290 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
314 with ds.parentchange():
315 ds.setparents(p1, p2)
316 else: 291 else:
292 known = []
293 if ellipsesremote:
294 known = [node.hex(ctx.node()) for ctx in
295 repo.set('::%ln', common)
296 if ctx.node() != node.nullid]
317 with remote.commandexecutor() as e: 297 with remote.commandexecutor() as e:
318 bundle = e.callcommand('narrow_widen', { 298 bundle = e.callcommand('narrow_widen', {
319 'oldincludes': oldincludes, 299 'oldincludes': oldincludes,
320 'oldexcludes': oldexcludes, 300 'oldexcludes': oldexcludes,
321 'newincludes': newincludes, 301 'newincludes': newincludes,
322 'newexcludes': newexcludes, 302 'newexcludes': newexcludes,
323 'cgversion': '03', 303 'cgversion': '03',
324 'commonheads': common, 304 'commonheads': common,
325 'known': [], 305 'known': known,
326 'ellipses': False, 306 'ellipses': ellipsesremote,
327 }).result() 307 }).result()
328 308
329 with repo.transaction('widening') as tr: 309 trmanager = exchange.transactionmanager(repo, 'widen', remote.url())
330 with repo.ui.configoverride(overrides, 'widen'): 310 with trmanager, repo.ui.configoverride(overrides, 'widen'):
331 tgetter = lambda: tr 311 op = bundle2.bundleoperation(repo, trmanager.transaction,
332 bundle2.processbundle(repo, bundle, 312 source='widen')
333 transactiongetter=tgetter) 313 # TODO: we should catch error.Abort here
314 bundle2.processbundle(repo, bundle, op=op)
315
316 if ellipsesremote:
317 with ds.parentchange():
318 ds.setparents(p1, p2)
334 319
335 with repo.transaction('widening'): 320 with repo.transaction('widening'):
336 repo.setnewnarrowpats() 321 repo.setnewnarrowpats()
337 narrowspec.updateworkingcopy(repo) 322 narrowspec.updateworkingcopy(repo)
338 narrowspec.copytoworkingcopy(repo) 323 narrowspec.copytoworkingcopy(repo)