comparison mercurial/commands.py @ 26581:6e715040c172

commands: use dirstateguard instead of begin/end-parentchange for backout Before this patch, "hg backout" uses 'begin'/'end'-'parentchange()' of 'dirstate' class to avoid writing incomplete dirstate changes out at failure. But this framework doesn't work as expected, if 'dirstate.write()' is invoked between them. In fact, in-memory dirstate changes may be written out at 'repo.status()' implied by 'merge.update()', even before this patch. To restore dirstate as expected at failure of "hg backout", this patch uses 'dirstateguard' instead of 'begin'/'end'-'parentchange()'.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Fri, 09 Oct 2015 03:53:47 +0900
parents 4688945f316c
children 56b2bcea2529
comparison
equal deleted inserted replaced
26580:4688945f316c 26581:6e715040c172
545 try: 545 try:
546 branch = repo.dirstate.branch() 546 branch = repo.dirstate.branch()
547 bheads = repo.branchheads(branch) 547 bheads = repo.branchheads(branch)
548 rctx = scmutil.revsingle(repo, hex(parent)) 548 rctx = scmutil.revsingle(repo, hex(parent))
549 if not opts.get('merge') and op1 != node: 549 if not opts.get('merge') and op1 != node:
550 dsguard = cmdutil.dirstateguard(repo, 'backout')
550 try: 551 try:
551 ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), 552 ui.setconfig('ui', 'forcemerge', opts.get('tool', ''),
552 'backout') 553 'backout')
553 repo.dirstate.beginparentchange()
554 stats = mergemod.update(repo, parent, True, True, False, 554 stats = mergemod.update(repo, parent, True, True, False,
555 node, False) 555 node, False)
556 repo.setparents(op1, op2) 556 repo.setparents(op1, op2)
557 repo.dirstate.endparentchange() 557 dsguard.close()
558 hg._showstats(repo, stats) 558 hg._showstats(repo, stats)
559 if stats[3]: 559 if stats[3]:
560 repo.ui.status(_("use 'hg resolve' to retry unresolved " 560 repo.ui.status(_("use 'hg resolve' to retry unresolved "
561 "file merges\n")) 561 "file merges\n"))
562 return 1 562 return 1
565 "don't forget to commit.\n") 565 "don't forget to commit.\n")
566 ui.status(msg % short(node)) 566 ui.status(msg % short(node))
567 return 0 567 return 0
568 finally: 568 finally:
569 ui.setconfig('ui', 'forcemerge', '', '') 569 ui.setconfig('ui', 'forcemerge', '', '')
570 lockmod.release(dsguard)
570 else: 571 else:
571 hg.clean(repo, node, show_stats=False) 572 hg.clean(repo, node, show_stats=False)
572 repo.dirstate.setbranch(branch) 573 repo.dirstate.setbranch(branch)
573 cmdutil.revert(ui, repo, rctx, repo.dirstate.parents()) 574 cmdutil.revert(ui, repo, rctx, repo.dirstate.parents())
574 575