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

login
register
mail settings
Submitter Siddharth Agarwal
Date Aug. 13, 2015, 12:35 a.m.
Message ID <87cad2d2cba314c33d78.1439426108@devbig136.prn2.facebook.com>
Download mbox | patch
Permalink /patch/10198/
State Accepted
Headers show

Comments

Siddharth Agarwal - Aug. 13, 2015, 12:35 a.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@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.
Pierre-Yves David - Aug. 13, 2015, 7:37 a.m.
On 08/12/2015 05:35 PM, Siddharth Agarwal wrote:
> # HG changeset patch
> # User Siddharth Agarwal <sid0@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

I forgot to mention it, but this is pushed to main for some times.

Direct access is however broken with current core tip (because revrange 
is no longer specific.

Patch

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: