[PATCH evolve-ext V2] directaccess: don't try to partialmatch things that aren't hashes

Siddharth Agarwal sid0 at fb.com
Thu Aug 13 00:35:08 UTC 2015


# HG changeset patch
# User Siddharth Agarwal <sid0 at fb.com>
# Date 1439420885 25200
#      Wed Aug 12 16:08:05 2015 -0700
# Node ID 87cad2d2cba314c33d78cfa7f48b3f509960e84d
# Parent  3dec62fc266eff7c7aa20e3229ffbede1c33d208
directaccess: don't try to partialmatch things that aren't hashes

Trying to partialmatch identifiers like '.' turns out to be (a) pointless and
(b) extremely slow. On a repo with a million commits, with directaccess
enabled,

hg log -r .^::.

goes from 2.1 seconds to 0.5.

diff --git a/hgext/directaccess.py b/hgext/directaccess.py
--- a/hgext/directaccess.py
+++ b/hgext/directaccess.py
@@ -13,6 +13,7 @@ from mercurial import revset
 from mercurial import error
 from mercurial import commands
 from mercurial import hg
+from mercurial import util
 from mercurial.i18n import _
 
 cmdtable = {}
@@ -126,6 +127,8 @@ def extsetup(ui):
     extensions.wrapfunction(hg, 'repository', _repository)
     setupdirectaccess()
 
+hashre = util.re.compile('[0-9a-fA-F]{1,40}')
+
 def gethashsymbols(tree):
     # Returns the list of symbols of the tree that look like hashes
     # for example for the revset 3::abe3ff it will return ('abe3ff')
@@ -137,7 +140,9 @@ def gethashsymbols(tree):
             int(tree[1])
             return []
         except ValueError as e:
-            return [tree[1]]
+            if hashre.match(tree[1]):
+                return [tree[1]]
+            return []
     elif len(tree) == 3:
         return gethashsymbols(tree[1]) + gethashsymbols(tree[2])
     else:


More information about the Mercurial-devel mailing list