[PATCH v4 STABLE] bookmarks: correctly update current bookmarks on rebase (issue2277)

David Schleimer dschleimer at fb.com
Fri Jun 22 13:53:40 CDT 2012


# HG changeset patch
# User David Schleimer <dschleimer at fb.com>
# Date 1340390431 25200
# Branch stable
# Node ID faadc9e008d7d90a1f349f102f1abf14ccf70e6e
# Parent  01eb882489371c2f2f4de3500497cade12df2883
bookmarks: correctly update current bookmarks on rebase (issue2277)

When you rebased with a currently active bookmark, that bookmark would
always point at the new tip, regardless of what revision it pointed at
before the rebase.

All bookmarks will now point at the equivalent post-rebase commit.
However, the currently active bookmark will cease to be active unless
it points at the new tip post-rebase.  Rebase will always leave the
new tip as the working copy parent, which is incompatible with having
an active bookmark that points at some other revision.  The common
case should be that the active bookmark will point at the new tip
post-rebase.

diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -247,6 +247,9 @@
 
         # Keep track of the current bookmarks in order to reset them later
         currentbookmarks = repo._bookmarks.copy()
+        activebookmark = repo._bookmarkcurrent
+        if activebookmark:
+            bookmarks.unsetcurrent(repo)
 
         sortedstate = sorted(state)
         total = len(sortedstate)
@@ -336,6 +339,11 @@
             util.unlinkpath(repo.sjoin('undo'))
         if skipped:
             ui.note(_("%d revisions have been skipped\n") % len(skipped))
+
+        if (activebookmark and
+            repo['tip'].node() == repo._bookmarks[activebookmark]):
+                bookmarks.setcurrent(repo, activebookmark)
+
     finally:
         release(lock, wlock)
 
@@ -483,13 +491,11 @@
 
 def updatebookmarks(repo, nstate, originalbookmarks, **opts):
     'Move bookmarks to their correct changesets'
-    current = repo._bookmarkcurrent
     for k, v in originalbookmarks.iteritems():
         if v in nstate:
             if nstate[v] != nullmerge:
-                # reset the pointer if the bookmark was moved incorrectly
-                if k != current:
-                    repo._bookmarks[k] = nstate[v]
+                # update the bookmarks for revs that have moved
+                repo._bookmarks[k] = nstate[v]
 
     bookmarks.write(repo)
 
diff --git a/tests/test-rebase-bookmarks.t b/tests/test-rebase-bookmarks.t
--- a/tests/test-rebase-bookmarks.t
+++ b/tests/test-rebase-bookmarks.t
@@ -36,8 +36,10 @@
   adding d
   created new head
 
+  $ hg book W
+
   $ hg tglog 
-  @  3: 'D' bookmarks:
+  @  3: 'D' bookmarks: W
   |
   | o  2: 'C' bookmarks: Y Z
   | |
@@ -60,7 +62,7 @@
   $ hg tglog 
   @  3: 'C' bookmarks: Y Z
   |
-  o  2: 'D' bookmarks:
+  o  2: 'D' bookmarks: W
   |
   | o  1: 'B' bookmarks: X
   |/
@@ -82,7 +84,30 @@
   |
   o  2: 'B' bookmarks: X
   |
-  o  1: 'D' bookmarks:
+  o  1: 'D' bookmarks: W
   |
   o  0: 'A' bookmarks:
   
+
+Keep active bookmark on the correct changeset
+
+  $ cd ..
+  $ hg clone -q a a3
+
+  $ cd a3
+  $ hg up -q X
+
+  $ hg rebase -d W
+  saved backup bundle to $TESTTMP/a3/.hg/strip-backup/*-backup.hg (glob)
+
+  $ hg tglog
+  @  3: 'C' bookmarks: Y Z
+  |
+  o  2: 'B' bookmarks: X
+  |
+  o  1: 'D' bookmarks: W
+  |
+  o  0: 'A' bookmarks:
+  
+
+  $ cd ..


More information about the Mercurial-devel mailing list