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

David Schleimer dschleimer at fb.com
Thu Jun 21 14:10:01 CDT 2012


# HG changeset patch
# User David Schleimer <dschleimer at fb.com>
# Date 1340305788 25200
# Node ID 29e0541bd0ecaa2aa60cf59c49c0f0edd2c1d2f4
# Parent  132ea1736751cb02b16992cf421e7de8bad888a1
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.  In
addition, if there was a currently active bookmark before the rebase,
it will remain active after rebase, and the revision it points to will
be the parent of the working copy.

diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -248,6 +248,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)
@@ -337,6 +340,12 @@
             util.unlinkpath(repo.sjoin('undo'))
         if skipped:
             ui.note(_("%d revisions have been skipped\n") % len(skipped))
+
+        if activebookmark:
+            ui.note(_("updating to %s bookmark") % activebookmark)
+            hg.clean(repo, repo._bookmarks[activebookmark], show_stats=False)
+            bookmarks.setcurrent(repo, activebookmark)
+
     finally:
         release(lock, wlock)
 
@@ -486,13 +495,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,9 +84,28 @@
   |
   o  2: 'B' bookmarks: X
   |
-  o  1: 'D' bookmarks:
+  o  1: 'D' bookmarks: W
   |
   o  0: 'A' bookmarks:
   
 
   $ 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/6c81ed0049f8-backup.hg
+
+  $ hg tglog
+  o  3: 'C' bookmarks: Y Z
+  |
+  @  2: 'B' bookmarks: X
+  |
+  o  1: 'D' bookmarks: W
+  |
+  o  0: 'A' bookmarks:
+  
+
+  $ cd ..


More information about the Mercurial-devel mailing list