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

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Oct. 15, 2013, 3:25 p.m.
Message ID <afa45683e56a3de54e70.1381850732@juju>
Download mbox | patch
Permalink /patch/2783/
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 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.

Patch

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")