bookmarks: delete divergent bookmarks on merge
authorDavid Soria Parra <dsp@php.net>
Sat, 12 May 2012 21:28:10 +0200
changeset 16706 a270ec977ba6
parent 16705 c2d9ef43ff6c
child 16707 f8dee1a8f844
bookmarks: delete divergent bookmarks on merge
mercurial/bookmarks.py
mercurial/localrepo.py
tests/test-bookmarks-merge.t
--- a/mercurial/bookmarks.py	Sun May 13 13:18:06 2012 +0200
+++ b/mercurial/bookmarks.py	Sat May 12 21:28:10 2012 +0200
@@ -150,13 +150,20 @@
 def update(repo, parents, node):
     marks = repo._bookmarks
     update = False
-    mark = repo._bookmarkcurrent
-    if mark and marks[mark] in parents:
-        old = repo[marks[mark]]
-        new = repo[node]
-        if new in old.descendants():
-            marks[mark] = new.node()
-            update = True
+    cur = repo._bookmarkcurrent
+    if not cur:
+        return False
+
+    toupdate = [b for b in marks if b.split('@', 1)[0] == cur.split('@', 1)[0]]
+    for mark in toupdate:
+        if mark and marks[mark] in parents:
+            old = repo[marks[mark]]
+            new = repo[node]
+            if new in old.descendants() and mark == cur:
+                marks[cur] = new.node()
+                update = True
+            if mark != cur:
+                del marks[mark]
     if update:
         repo._writebookmarks(marks)
     return update
--- a/mercurial/localrepo.py	Sun May 13 13:18:06 2012 +0200
+++ b/mercurial/localrepo.py	Sat May 12 21:28:10 2012 +0200
@@ -1187,7 +1187,7 @@
                 raise
 
             # update bookmarks, dirstate and mergestate
-            bookmarks.update(self, p1, ret)
+            bookmarks.update(self, [p1, p2], ret)
             for f in changes[0] + changes[1]:
                 self.dirstate.normal(f)
             for f in changes[2]:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-bookmarks-merge.t	Sat May 12 21:28:10 2012 +0200
@@ -0,0 +1,31 @@
+# init
+
+  $ hg init
+  $ echo a > a
+  $ hg add a
+  $ hg commit -m'a'
+  $ echo b > b
+  $ hg add b
+  $ hg commit -m'b'
+  $ hg up -C 0
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ echo c > c
+  $ hg add c
+  $ hg commit -m'c'
+  created new head
+
+# test merging of diverged bookmarks
+  $ hg bookmark -r 1 "c@diverge"
+  $ hg bookmark -r 1 b
+  $ hg bookmark c
+  $ hg bookmarks
+     b                         1:d2ae7f538514
+   * c                         2:d36c0562f908
+     c@diverge                 1:d2ae7f538514
+  $ hg merge "c@diverge"
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  (branch merge, don't forget to commit)
+  $ hg commit -m'merge'
+  $ hg bookmarks
+     b                         1:d2ae7f538514
+   * c                         3:b8f96cf4688b