Patchwork [3,of,3,V6] bookmarks: reuse @number bookmark, if it refers changeset referred remotely

login
register
mail settings
Submitter Katsunori FUJIWARA
Date March 17, 2015, 1:39 p.m.
Message ID <3e09fdade47be896bf28.1426599556@juju>
Download mbox | patch
Permalink /patch/8117/
State Accepted
Commit ca4b89683078a7199e108799afdeb5943b8a97c3
Headers show

Comments

Katsunori FUJIWARA - March 17, 2015, 1:39 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1426584024 -32400
#      Tue Mar 17 18:20:24 2015 +0900
# Node ID 3e09fdade47be896bf28f8fa3c413b98a105bcfc
# Parent  5faf9e4e8446f875978b84b4dff2e7b7b30c2389
bookmarks: reuse @number bookmark, if it refers changeset referred remotely

Before this patch, "@number" 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 "@number" suffixed bookmarks.

This patch reuses "@number" suffixed bookmark, if it refers the
changeset which is referred by the same bookmark in the remote
repository.
Matt Mackall - March 18, 2015, 9:03 p.m.
On Tue, 2015-03-17 at 22:39 +0900, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> # Date 1426584024 -32400
> #      Tue Mar 17 18:20:24 2015 +0900
> # Node ID 3e09fdade47be896bf28f8fa3c413b98a105bcfc
> # Parent  5faf9e4e8446f875978b84b4dff2e7b7b30c2389
> bookmarks: reuse @number bookmark, if it refers changeset referred remotely

These are queued for default, thanks. We've got a 'seq' problem, which
we'll need to sort out:

http://markmail.org/message/v3qqmfu4rzynzzl2

Patch

diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -362,11 +362,14 @@  def compare(repo, srcmarks, dstmarks,
 
     return results
 
-def _diverge(ui, b, path, localmarks):
+def _diverge(ui, b, path, localmarks, remotenode):
     '''Return appropriate diverged bookmark for specified ``path``
 
     This returns None, if it is failed to assign any divergent
     bookmark name.
+
+    This reuses already existing one with "@number" suffix, if it
+    refers ``remotenode``.
     '''
     if b == '@':
         b = ''
@@ -383,7 +386,7 @@  def _diverge(ui, b, path, localmarks):
     # assign a unique "@number" suffix newly
     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
@@ -417,9 +420,10 @@  def updatefromremote(ui, repo, remotemar
             changed.append((b, bin(scid), status,
                             _("importing bookmark %s\n") % (b)))
         else:
-            db = _diverge(ui, b, path, localmarks)
+            snode = bin(scid)
+            db = _diverge(ui, b, path, localmarks, snode)
             if db:
-                changed.append((db, bin(scid), warn,
+                changed.append((db, snode, 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
@@ -182,6 +182,24 @@  divergent bookmarks
   $ hg bookmarks | grep '^   X' | grep -v ':000000000000'
      X                         1:9b140be10808
      X@foo                     2:0d2164f0ce0d
+
+(test that remotely diverged bookmarks are reused if they aren't changed)
+
+  $ hg bookmarks | grep '^   @'
+     @                         1:9b140be10808
+     @1                        2:0d2164f0ce0d
+     @foo                      2:0d2164f0ce0d
+  $ hg pull ../a
+  pulling from ../a
+  searching for changes
+  no changes found
+  warning: failed to assign numbered name to divergent bookmark 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"