diff mercurial/bookmarks.py @ 24353:3f6bf9f29e7b

bookmarks: prevent divergent bookmark from being updated unexpectedly Before this patch, "@99" suffixed bookmark may be updated unexpectedly by the bookmark value on the remote side at "hg pull", if all of "@1" to "@99" suffixed bookmarks exist in the local repository, because variable "n" still refers "@99" suffixed bookmark after the loop to examine "@num" suffixes, even though it already exists in the local repository. This patch prevents divergent bookmark from being updated unexpectedly, and shows warning message in such situation. This patch uses original python script "seq.py" instead of "seq" command to create sequence numbers in the test, because "seq" command may not be available: it isn't defined in recent POSIX specification (POSIX.1-2001 2013 Edition or XPG7)
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Tue, 17 Mar 2015 18:20:24 +0900
parents 6ddc86eedc3b
children 194e1e3ebc29
line wrap: on
line diff
--- a/mercurial/bookmarks.py	Wed Mar 18 11:41:36 2015 -0700
+++ b/mercurial/bookmarks.py	Tue Mar 17 18:20:24 2015 +0900
@@ -363,6 +363,11 @@
     return results
 
 def _diverge(ui, b, path, localmarks):
+    '''Return appropriate diverged bookmark for specified ``path``
+
+    This returns None, if it is failed to assign any divergent
+    bookmark name.
+    '''
     if b == '@':
         b = ''
     # find a unique @ suffix
@@ -370,6 +375,8 @@
         n = '%s@%d' % (b, x)
         if n not in localmarks:
             break
+    else:
+        n = None
     # try to use an @pathalias suffix
     # if an @pathalias already exists, we overwrite (update) it
     if path.startswith("file:"):
@@ -411,9 +418,13 @@
                             _("importing bookmark %s\n") % (b)))
         else:
             db = _diverge(ui, b, path, localmarks)
-            changed.append((db, bin(scid), warn,
-                            _("divergent bookmark %s stored as %s\n")
-                            % (b, db)))
+            if db:
+                changed.append((db, bin(scid), warn,
+                                _("divergent bookmark %s stored as %s\n") %
+                                (b, db)))
+            else:
+                warn(_("warning: failed to assign numbered name "
+                       "to divergent bookmark %s\n") % (b))
     for b, scid, dcid in adddst + advdst:
         if b in explicit:
             explicit.discard(b)