[PATCH 10 of 15 V4] bookmarks: check "@pathalias" suffix before "@number" ones for efficiency

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Tue Oct 15 10:25:32 CDT 2013


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1381849966 -32400
#      Wed Oct 16 00:12:46 2013 +0900
# Node ID afa45683e56a3de54e7048f0aff99fa28187d3b0
# Parent  4caa72f350d910aa9454903a25293ec0ed5bce8b
bookmarks: check "@pathalias" suffix before "@number" ones for efficiency

Before this patch, "@number" suffixes are checked before "@pathalias"
suffix, even though the latter has higher priority than the former if
the latter exits.

This patch checks "@pathalias" suffix before "@number" ones for
efficiency.

When there are two or more path aliases for the same URL, this patch
uses one matched first, even though old implementation uses one
matched last.

diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -328,19 +328,17 @@
 def _diverge(ui, b, path, localmarks):
     if b == '@':
         b = ''
+    # try to use an @pathalias suffix
+    # if an @pathalias already exists, we overwrite (update) it
+    for p, u in ui.configitems("paths"):
+        if path == u:
+            return '%s@%s' % (b, p)
     # 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
-    for p, u in ui.configitems("paths"):
-        if path == u:
-            n = '%s@%s' % (b, p)
-    return n
+            return n
+    return None
 
 def updatefromremote(ui, repo, remotemarks, path):
     ui.debug("checking for updated bookmarks\n")


More information about the Mercurial-devel mailing list