Patchwork [STABLE] rebase: restore active bookmark after rebase --continue

login
register
mail settings
Submitter Durham Goode
Date March 12, 2013, 5:35 p.m.
Message ID <35ce5a69947465b2a6b8.1363109707@dev350.prn1.facebook.com>
Download mbox | patch
Permalink /patch/1112/
State Accepted
Commit 72412afe4c2872fc3197aeee06f6841c76e19772
Headers show

Comments

Durham Goode - March 12, 2013, 5:35 p.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1363041448 25200
#      Mon Mar 11 15:37:28 2013 -0700
# Node ID 35ce5a69947465b2a6b8c4012897cd20a83a17f9
# Parent  018d68a30fe19e2d2c73d765306ba3156bb4957c
rebase: restore active bookmark after rebase --continue

When a rebase has conflicts and the user uses rebase --continue, the previously
active bookmark was not being made active once again. With this change that
bookmark is made active again, just as if the rebase had never been interrupted.

This changes the rebasestate file format, but should handle old formats correctly.
Since the file is transient, this is even less of a problem.

Adds a test to verify the new behavior. I manually tested continuing rebases
with and without an active bookmark, and with and without being on the bookmark
being rebased.
Bryan O'Sullivan - March 12, 2013, 5:44 p.m.
On Tue, Mar 12, 2013 at 10:35 AM, Durham Goode <durham@fb.com> wrote:

> rebase: restore active bookmark after rebase --continue
>

Applied, thanks.

Patch

diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -112,6 +112,7 @@ 
     Returns 0 on success, 1 if nothing to rebase.
     """
     originalwd = target = None
+    activebookmark = None
     external = nullrev
     state = {}
     skipped = set()
@@ -159,7 +160,7 @@ 
                 ui.warn(_('tool option will be ignored\n'))
 
             (originalwd, target, state, skipped, collapsef, keepf,
-                                keepbranchesf, external) = restorestatus(repo)
+                keepbranchesf, external, activebookmark) = restorestatus(repo)
             if abortf:
                 return abort(repo, originalwd, target, state)
         else:
@@ -245,7 +246,7 @@ 
 
         # Keep track of the current bookmarks in order to reset them later
         currentbookmarks = repo._bookmarks.copy()
-        activebookmark = repo._bookmarkcurrent
+        activebookmark = activebookmark or repo._bookmarkcurrent
         if activebookmark:
             bookmarks.unsetcurrent(repo)
 
@@ -258,7 +259,7 @@ 
                 ui.progress(_("rebasing"), pos, ("%d:%s" % (rev, repo[rev])),
                             _('changesets'), total)
                 storestatus(repo, originalwd, target, state, collapsef, keepf,
-                                                    keepbranchesf, external)
+                            keepbranchesf, external, activebookmark)
                 p1, p2 = defineparents(repo, rev, target, state,
                                                         targetancestors)
                 if len(repo.parents()) == 2:
@@ -516,7 +517,7 @@ 
     marks.write()
 
 def storestatus(repo, originalwd, target, state, collapse, keep, keepbranches,
-                                                                external):
+                external, activebookmark):
     'Store the current status to allow recovery'
     f = repo.opener("rebasestate", "w")
     f.write(repo[originalwd].hex() + '\n')
@@ -525,6 +526,7 @@ 
     f.write('%d\n' % int(collapse))
     f.write('%d\n' % int(keep))
     f.write('%d\n' % int(keepbranches))
+    f.write('%s\n' % (activebookmark or ''))
     for d, v in state.iteritems():
         oldrev = repo[d].hex()
         if v > nullmerge:
@@ -545,6 +547,7 @@ 
         target = None
         collapse = False
         external = nullrev
+        activebookmark = None
         state = {}
         f = repo.opener("rebasestate")
         for i, l in enumerate(f.read().splitlines()):
@@ -560,6 +563,10 @@ 
                 keep = bool(int(l))
             elif i == 5:
                 keepbranches = bool(int(l))
+            elif i == 6 and not (len(l) == 81 and ':' in l):
+                # line 6 is a recent addition, so for backwards compatibility
+                # check that the line doesn't look like the oldrev:newrev lines
+                activebookmark = l
             else:
                 oldrev, newrev = l.split(':')
                 if newrev in (str(nullmerge), str(revignored)):
@@ -577,7 +584,7 @@ 
         repo.ui.debug('computed skipped revs: %s\n' % skipped)
         repo.ui.debug('rebase status resumed\n')
         return (originalwd, target, state, skipped,
-                collapse, keep, keepbranches, external)
+                collapse, keep, keepbranches, external, activebookmark)
     except IOError, err:
         if err.errno != errno.ENOENT:
             raise
diff --git a/tests/test-rebase-conflicts.t b/tests/test-rebase-conflicts.t
--- a/tests/test-rebase-conflicts.t
+++ b/tests/test-rebase-conflicts.t
@@ -7,7 +7,7 @@ 
   > publish=False
   > 
   > [alias]
-  > tglog = log -G --template "{rev}:{phase} '{desc}' {branches}\n"
+  > tglog = log -G --template "{rev}:{phase} '{desc}' {branches} {bookmarks}\n"
   > EOF
 
   $ hg init a
@@ -36,11 +36,12 @@ 
   $ echo l3 >> extra2
   $ hg add extra2
   $ hg ci -m L3
+  $ hg bookmark mybook
 
   $ hg phase --force --secret 4
 
   $ hg tglog
-  @  5:secret 'L3'
+  @  5:secret 'L3'  mybook
   |
   o  4:secret 'L2'
   |
@@ -81,7 +82,7 @@ 
   saved backup bundle to $TESTTMP/a/.hg/strip-backup/*-backup.hg (glob)
 
   $ hg tglog
-  @  5:secret 'L3'
+  @  5:secret 'L3'  mybook
   |
   o  4:secret 'L2'
   |
@@ -118,4 +119,8 @@ 
   $ hg cat -r 5 common
   resolved merge
 
+Bookmark stays active after --continue
+  $ hg bookmarks
+   * mybook                    5:d67b21408fc0
+
   $ cd ..