Mercurial > public > mercurial-scm > hg
diff hgext/histedit.py @ 26584:e28102403d1b
histedit: delete histedit statefile on any exception during abort
When an user aborts a histedit, many things could go wrong. At a minimum, after
a histedit abort failure, their repository should be out of that state. We've
found situations where the user could not exit the histedit state without
manually deleting the histedit state file. This patch ensures that if any
exception happens during an abort, the histedit statefile will be deleted so
that users are out of the histedit state and can at least manually get the repo
back to a workable condition.
author | Christian Delahousse <cdelahousse@fb.com> |
---|---|
date | Mon, 05 Oct 2015 16:44:45 -0700 |
parents | 49b568a4e539 |
children | 56b2bcea2529 |
line wrap: on
line diff
--- a/hgext/histedit.py Tue Oct 06 15:09:28 2015 -0700 +++ b/hgext/histedit.py Mon Oct 05 16:44:45 2015 -0700 @@ -812,26 +812,35 @@ state.write() return elif goal == 'abort': - state.read() - tmpnodes, leafs = newnodestoabort(state) - ui.debug('restore wc to old parent %s\n' % node.short(state.topmost)) + try: + state.read() + tmpnodes, leafs = newnodestoabort(state) + ui.debug('restore wc to old parent %s\n' + % node.short(state.topmost)) + + # Recover our old commits if necessary + if not state.topmost in repo and state.backupfile: + backupfile = repo.join(state.backupfile) + f = hg.openpath(ui, backupfile) + gen = exchange.readbundle(ui, f, backupfile) + changegroup.addchangegroup(repo, gen, 'histedit', + 'bundle:' + backupfile) + os.remove(backupfile) - # Recover our old commits if necessary - if not state.topmost in repo and state.backupfile: - backupfile = repo.join(state.backupfile) - f = hg.openpath(ui, backupfile) - gen = exchange.readbundle(ui, f, backupfile) - changegroup.addchangegroup(repo, gen, 'histedit', - 'bundle:' + backupfile) - os.remove(backupfile) - - # check whether we should update away - if repo.unfiltered().revs('parents() and (%n or %ln::)', - state.parentctxnode, leafs | tmpnodes): - hg.clean(repo, state.topmost) - cleanupnode(ui, repo, 'created', tmpnodes) - cleanupnode(ui, repo, 'temp', leafs) - state.clear() + # check whether we should update away + if repo.unfiltered().revs('parents() and (%n or %ln::)', + state.parentctxnode, leafs | tmpnodes): + hg.clean(repo, state.topmost) + cleanupnode(ui, repo, 'created', tmpnodes) + cleanupnode(ui, repo, 'temp', leafs) + except Exception: + if state.inprogress(): + ui.warn(_('warning: encountered an exception during histedit ' + '--abort; the repository may not have been completely ' + 'cleaned up\n')) + raise + finally: + state.clear() return else: cmdutil.checkunfinished(repo)