Patchwork [2,of,2] rebase: clean up rebasestate from active transaction

login
register
mail settings
Submitter Jun Wu
Date June 25, 2017, 4:14 a.m.
Message ID <bbb1c46eef6fd1973d29.1498364066@x1c>
Download mbox | patch
Permalink /patch/21691/
State Accepted
Headers show

Comments

Jun Wu - June 25, 2017, 4:14 a.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1498364028 25200
#      Sat Jun 24 21:13:48 2017 -0700
# Node ID bbb1c46eef6fd1973d2912ff88c732017aa80713
# Parent  244ca1b15233614b2de9aa6e6c0ed12670150777
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r bbb1c46eef6f
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.
Yuya Nishihara - June 26, 2017, 12:35 p.m.
On Sat, 24 Jun 2017 21:14:26 -0700, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark@fb.com>
> # Date 1498364028 25200
> #      Sat Jun 24 21:13:48 2017 -0700
> # Node ID bbb1c46eef6fd1973d2912ff88c732017aa80713
> # Parent  244ca1b15233614b2de9aa6e6c0ed12670150777
> # Available At https://bitbucket.org/quark-zju/hg-draft
> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r bbb1c46eef6f
> rebase: clean up rebasestate from active transaction

This seems a straightforward fix. Queued, thanks.

Patch

diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -1149,4 +1149,8 @@  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)
 
diff --git a/mercurial/transaction.py b/mercurial/transaction.py
--- a/mercurial/transaction.py
+++ b/mercurial/transaction.py
@@ -293,4 +293,10 @@  class transaction(object):
         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
diff --git a/tests/test-rebase-scenario-global.t b/tests/test-rebase-scenario-global.t
--- a/tests/test-rebase-scenario-global.t
+++ b/tests/test-rebase-scenario-global.t
@@ -955,3 +955,3 @@  Testing rebase being called inside anoth
 
   $ [ -f .hg/rebasestate ] && echo 'WRONG: rebasestate should not exist'
-  WRONG: rebasestate should not exist
+  [1]