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

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Nov. 8, 2013, 3:54 a.m.
Message ID <31ed0b6c7d150db68a09.1383882860@juju>
Download mbox | patch
Permalink /patch/2880/
State Superseded
Headers show

Comments

Katsunori FUJIWARA - Nov. 8, 2013, 3:54 a.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1383882352 -32400
#      Fri Nov 08 12:45:52 2013 +0900
# Node ID 31ed0b6c7d150db68a09a8dc82ba24d7e9948f1c
# Parent  c78c40d11ff9c6cfa32bd6aed4fe781a613255b4
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")