From patchwork Thu Oct 8 18:59:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [6, of, 6] commands: use dirstateguard instead of begin/end-parentchange for backout From: Katsunori FUJIWARA X-Patchwork-Id: 10886 Message-Id: To: mercurial-devel@selenic.com Date: Fri, 09 Oct 2015 03:59:05 +0900 # HG changeset patch # User FUJIWARA Katsunori # Date 1444330427 -32400 # Fri Oct 09 03:53:47 2015 +0900 # Node ID e3faacb44a12089395756401d91b45fe67436c44 # Parent f4ff0385ec32d5192ce67fc6228ec87333335b14 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()'. diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -547,14 +547,14 @@ bheads = repo.branchheads(branch) rctx = scmutil.revsingle(repo, hex(parent)) if not opts.get('merge') and op1 != node: + dsguard = cmdutil.dirstateguard(repo, 'backout') try: ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), 'backout') - repo.dirstate.beginparentchange() stats = mergemod.update(repo, parent, True, True, False, node, False) repo.setparents(op1, op2) - repo.dirstate.endparentchange() + dsguard.close() hg._showstats(repo, stats) if stats[3]: repo.ui.status(_("use 'hg resolve' to retry unresolved " @@ -567,6 +567,7 @@ return 0 finally: ui.setconfig('ui', 'forcemerge', '', '') + lockmod.release(dsguard) else: hg.clean(repo, node, show_stats=False) repo.dirstate.setbranch(branch)