bookmarks: resolve divergent bookmarks when moving active bookmark forward stable
authorSean Farley <sean.michael.farley@gmail.com>
Wed, 01 May 2013 15:34:45 -0500
branchstable
changeset 19110 741d94aa92e4
parent 19109 26c51e87e807
child 19111 6439d78e14fb
bookmarks: resolve divergent bookmarks when moving active bookmark forward This patch resolves divergent bookmarks between the current active bookmark MARK and the new destination. This situation can arise when pulling new changesets, abandoning your current changesets actively bookmarked with MARK via strip, and then doing a bare update. The non-divergent but active bookmark MARK is then moved to a common ancestor of the new changesets and the abandoned changesets. Test coverage is added.
mercurial/bookmarks.py
tests/test-bookmarks-current.t
--- a/mercurial/bookmarks.py	Wed May 01 15:31:39 2013 -0500
+++ b/mercurial/bookmarks.py	Wed May 01 15:34:45 2013 -0500
@@ -171,6 +171,7 @@
     return deleted
 
 def update(repo, parents, node):
+    deletefrom = parents
     marks = repo._bookmarks
     update = False
     cur = repo._bookmarkcurrent
@@ -180,11 +181,15 @@
     if marks[cur] in parents:
         old = repo[marks[cur]]
         new = repo[node]
+        divs = [repo[b] for b in marks
+                if b.split('@', 1)[0] == cur.split('@', 1)[0]]
+        anc = repo.changelog.ancestors([new.rev()])
+        deletefrom = [b.node() for b in divs if b.rev() in anc or b == new]
         if old.descendant(new):
             marks[cur] = new.node()
             update = True
 
-    if deletedivergent(repo, parents, cur):
+    if deletedivergent(repo, deletefrom, cur):
         update = True
 
     if update:
--- a/tests/test-bookmarks-current.t	Wed May 01 15:31:39 2013 -0500
+++ b/tests/test-bookmarks-current.t	Wed May 01 15:34:45 2013 -0500
@@ -133,21 +133,27 @@
      X                         0:719295282060
      Z                         0:719295282060
 
-bare update moves the active bookmark forward
+bare update moves the active bookmark forward and clear the divergent bookmarks
 
   $ echo a > a
   $ hg ci -Am1
   adding a
+  $ echo b >> a
+  $ hg ci -Am2
+  $ hg bookmark X@1 -r 1
+  $ hg bookmark X@2 -r 2
   $ hg update X
   0 files updated, 0 files merged, 1 files removed, 0 files unresolved
   $ hg bookmarks
    * X                         0:719295282060
+     X@1                       1:cc586d725fbe
+     X@2                       2:49e1c4e84c58
      Z                         0:719295282060
   $ hg update
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   updating bookmark X
   $ hg bookmarks
-   * X                         1:cc586d725fbe
+   * X                         2:49e1c4e84c58
      Z                         0:719295282060
 
 test deleting .hg/bookmarks.current when explicitly updating