Patchwork [11,of,15,V5] bookmarks: reuse "@num"-ed bookmark, if it refers changeset referred remotely

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Nov. 8, 2013, 3:54 a.m.
Message ID <555202e6df3b5ab422b3.1383882861@juju>
Download mbox | patch
Permalink /patch/2882/
State Superseded
Headers show

Comments

Katsunori FUJIWARA - Nov. 8, 2013, 3:54 a.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1383882352 -32400
#      Fri Nov 08 12:45:52 2013 +0900
# Node ID 555202e6df3b5ab422b380e46dc2110ea07a8f25
# Parent  31ed0b6c7d150db68a09a8dc82ba24d7e9948f1c
bookmarks: reuse "@num"-ed bookmark, if it refers changeset referred remotely

Before this patch, "@num" suffixed bookmark may be newly created at
each "hg pull" from the remote repository, if the bookmark in remote
repository diverges from one in local one.

This causes unexpected increase of "@num" suffixed bookmarks.

This patch reuses "@num" suffixed bookmark, if it refers the changeset
which is referred by the same bookmark in the remote repository.

Patch

diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -325,7 +325,7 @@ 
 
     return results
 
-def _diverge(ui, b, path, localmarks):
+def _diverge(ui, b, path, localmarks, remotenode):
     if b == '@':
         b = ''
     # try to use an @pathalias suffix
@@ -336,7 +336,7 @@ 
     # find a unique @ suffix
     for x in range(1, 100):
         n = '%s@%d' % (b, x)
-        if n not in localmarks:
+        if n not in localmarks or localmarks[n] == remotenode:
             return n
     return None
 
@@ -355,9 +355,10 @@ 
         changed.append((b, bin(scid), ui.status,
                         _("updating bookmark %s\n") % (b)))
     for b, scid, dcid in diverge:
-        db = _diverge(ui, b, path, localmarks)
+        snode = bin(scid)
+        db = _diverge(ui, b, path, localmarks, snode)
         if db:
-            changed.append((db, bin(scid), ui.warn,
+            changed.append((db, snode, ui.warn,
                             _("divergent bookmark %s stored as %s\n") %
                             (b, db)))
         else:
diff --git a/tests/test-bookmarks-pushpull.t b/tests/test-bookmarks-pushpull.t
--- a/tests/test-bookmarks-pushpull.t
+++ b/tests/test-bookmarks-pushpull.t
@@ -173,6 +173,20 @@ 
   $ hg bookmarks | grep '^   X' | grep -v ':000000000000'
      X                         1:9b140be10808
      X@foo                     2:0d2164f0ce0d
+  $ hg bookmarks | grep '^   @'
+     @                         1:9b140be10808
+     @1                        2:0d2164f0ce0d
+     @foo                      2:0d2164f0ce0d
+  $ hg pull ../a
+  pulling from ../a
+  searching for changes
+  no changes found
+  warning: fail to assign new divergent bookmark to X
+  divergent bookmark @ stored as @1
+  $ hg bookmarks | grep '^   @'
+     @                         1:9b140be10808
+     @1                        2:0d2164f0ce0d
+     @foo                      2:0d2164f0ce0d
   $ python $TESTTMP/seq.py 1 100 | while read i; do hg bookmarks -d "X@${i}"; done
   $ hg bookmarks -d "@1"
   $ hg push -f ../a