bookmarks: check @pathalias suffix before available @number for efficiency
authorFUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Tue, 17 Mar 2015 18:20:24 +0900
changeset 24354 194e1e3ebc29
parent 24353 3f6bf9f29e7b
child 24355 ca4b89683078
bookmarks: check @pathalias suffix before available @number for efficiency Before this patch, available "@number" suffix is searched before "@pathalias" suffix, even though the latter has higher priority than the former if the latter exits. This patch checks "@pathalias" suffix before available "@number" for efficiency. When an URL has multiple path definitions, the first one is used for "pathalias" after this patch, even though the last one is used before this patch, because: - this choice can terminate loop immediately for efficiency - such case seems to be rare
mercurial/bookmarks.py
--- a/mercurial/bookmarks.py	Tue Mar 17 18:20:24 2015 +0900
+++ b/mercurial/bookmarks.py	Tue Mar 17 18:20:24 2015 +0900
@@ -370,13 +370,6 @@
     '''
     if b == '@':
         b = ''
-    # find a unique @ suffix
-    for x in range(1, 100):
-        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:"):
@@ -385,8 +378,15 @@
         if u.startswith("file:"):
             u = util.url(u).path
         if path == u:
-            n = '%s@%s' % (b, p)
-    return n
+            return '%s@%s' % (b, p)
+
+    # assign a unique "@number" suffix newly
+    for x in range(1, 100):
+        n = '%s@%d' % (b, x)
+        if n not in localmarks:
+            return n
+
+    return None
 
 def updatefromremote(ui, repo, remotemarks, path, trfunc, explicit=()):
     ui.debug("checking for updated bookmarks\n")