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

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Oct. 15, 2013, 3:25 p.m.
Message ID <23df7670d1694ef1dd12.1381850733@juju>
Download mbox | patch
Permalink /patch/2781/
State Superseded
Headers show

Comments

Katsunori FUJIWARA - Oct. 15, 2013, 3:25 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1381849966 -32400
#      Wed Oct 16 00:12:46 2013 +0900
# Node ID 23df7670d1694ef1dd12da89262128e534e96ac0
# Parent  afa45683e56a3de54e7048f0aff99fa28187d3b0
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