Patchwork [2,of,3,V6] bookmarks: check @pathalias suffix before available @number for efficiency

login
register
mail settings
Submitter Katsunori FUJIWARA
Date March 17, 2015, 1:39 p.m.
Message ID <5faf9e4e8446f875978b.1426599555@juju>
Download mbox | patch
Permalink /patch/8116/
State Accepted
Commit 194e1e3ebc29b1ee8e06c680f975b3a939f78f7e
Headers show

Comments

Katsunori FUJIWARA - March 17, 2015, 1:39 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1426584024 -32400
#      Tue Mar 17 18:20:24 2015 +0900
# Node ID 5faf9e4e8446f875978b84b4dff2e7b7b30c2389
# Parent  d58e76af194826a9cb20408bdc36407a2bc55c7c
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

Patch

diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -370,13 +370,6 @@  def _diverge(ui, b, path, localmarks):
     '''
     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 @@  def _diverge(ui, b, path, localmarks):
         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")