rebase: clean up rebasestate from active transaction

Previously, rebase assumes the following pattern:

    rebase:
        with transaction as tr: # top-level
            ...
        tr.__close__ writes rebasestate
        unlink('rebasestate')

However it's possible that "rebase" was called inside a transaction:

    with transaction as tr1:
        rebase:
            with transaction as tr2: # not top-level
                ...
            tr2.__close__ does not write rebasestate
            unlink('rebasestate')
    tr1.__close__ writes rebasestate

That leaves a rebasestate on disk incorrectly.

This patch adds "removefilegenerator" to notify transaction code that the
state file is no longer needed therefore fixes the issue.
This commit is contained in:
Jun Wu 2017-06-24 21:13:48 -07:00
parent 5fde6e7067
commit e906874924
3 changed files with 11 additions and 1 deletions

View File

@ -1148,6 +1148,10 @@ def restorecollapsemsg(repo, isabort):
def clearstatus(repo):
'Remove the status files'
_clearrebasesetvisibiliy(repo)
# Make sure the active transaction won't write the state file
tr = repo.currenttransaction()
if tr:
tr.removefilegenerator('rebasestate')
repo.vfs.unlinkpath("rebasestate", ignoremissing=True)
def needupdate(repo, state):

View File

@ -292,6 +292,12 @@ class transaction(object):
# but for bookmarks that are handled outside this mechanism.
self._filegenerators[genid] = (order, filenames, genfunc, location)
@active
def removefilegenerator(self, genid):
"""reverse of addfilegenerator, remove a file generator function"""
if genid in self._filegenerators:
del self._filegenerators[genid]
def _generatefiles(self, suffix='', group=gengroupall):
# write files registered for generation
any = False

View File

@ -954,4 +954,4 @@ Testing rebase being called inside another transaction
rebasing 2:dc0947a82db8 "C" (C tip)
$ [ -f .hg/rebasestate ] && echo 'WRONG: rebasestate should not exist'
WRONG: rebasestate should not exist
[1]