[PATCH] matcher: make e.g. 'relpath:.' lead to fast paths

Martin von Zweigbergk martinvonz at google.com
Wed Mar 25 13:10:21 CDT 2015


# HG changeset patch
# User Martin von Zweigbergk <martinvonz at google.com>
# Date 1416441418 28800
#      Wed Nov 19 15:56:58 2014 -0800
# Node ID ceb8a0ada1179719f2d28ddb09a669d81d7227d2
# Parent  a0cb16381f4d89940520187e14baaec5e92455e3
matcher: make e.g. 'relpath:.' lead to fast paths

Several commands take the fast path when match.always() is
true. However, when the user passes "." on the command line, that
results in a matcher for which match.always() == False. Let's make it
so such matchers return True, and have an empty list of .files(). This
makes e.g. "hg log ." as fast as "hg log" and "hg revert ." as fast as
"hg revert --all" (when run from repo root).

diff -r a0cb16381f4d -r ceb8a0ada117 mercurial/match.py
--- a/mercurial/match.py	Sat Jan 17 12:39:44 2015 +0900
+++ b/mercurial/match.py	Wed Nov 19 15:56:58 2014 -0800
@@ -34,6 +34,15 @@
         other.append((kind, pat))
     return fset, other
 
+def _kindpatsalwaysmatch(kindpats):
+    """"Checks whether the kindspats match everything, as e.g.
+    'relpath:.' does.
+    """
+    for kind, pat in kindpats:
+        if pat != '' or kind not in ['relpath', 'glob']:
+            return False
+    return True
+
 class match(object):
     def __init__(self, root, cwd, patterns, include=[], exclude=[],
                  default='glob', exact=False, auditor=None, ctx=None):
@@ -83,10 +92,11 @@
             matchfns.append(self.exact)
         elif patterns:
             kindpats = _normalize(patterns, default, root, cwd, auditor)
-            self._files = _roots(kindpats)
-            self._anypats = self._anypats or _anypats(kindpats)
-            self.patternspat, pm = _buildmatch(ctx, kindpats, '$')
-            matchfns.append(pm)
+            if not _kindpatsalwaysmatch(kindpats):
+                self._files = _roots(kindpats)
+                self._anypats = self._anypats or _anypats(kindpats)
+                self.patternspat, pm = _buildmatch(ctx, kindpats, '$')
+                matchfns.append(pm)
 
         if not matchfns:
             m = util.always
diff -r a0cb16381f4d -r ceb8a0ada117 mercurial/scmutil.py
--- a/mercurial/scmutil.py	Sat Jan 17 12:39:44 2015 +0900
+++ b/mercurial/scmutil.py	Wed Nov 19 15:56:58 2014 -0800
@@ -725,6 +725,8 @@
     def badfn(f, msg):
         ctx.repo().ui.warn("%s: %s\n" % (m.rel(f), msg))
     m.bad = badfn
+    if m.always():
+        pats = []
     return m, pats
 
 def match(ctx, pats=[], opts={}, globbed=False, default='relpath'):


More information about the Mercurial-devel mailing list