# HG changeset patch # User FUJIWARA Katsunori # Date 1444330427 -32400 # Node ID 6e715040c1725b5debce888c4f7d3fdbf55cc900 # Parent 4688945f316cff0ee877e20177d39a4ce70a92ce 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 -r 4688945f316c -r 6e715040c172 mercurial/commands.py --- a/mercurial/commands.py Fri Oct 09 03:53:47 2015 +0900 +++ b/mercurial/commands.py Fri Oct 09 03:53:47 2015 +0900 @@ -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)