matcher: make e.g. 'relpath:.' lead to fast paths
authorMartin von Zweigbergk <martinvonz@google.com>
Wed, 19 Nov 2014 15:56:58 -0800
changeset 24447 d44d53bc9a1e
parent 24446 582cfcc843c7
child 24448 55c449345b10
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).
mercurial/match.py
mercurial/scmutil.py
--- a/mercurial/match.py	Wed Mar 25 14:56:54 2015 -0400
+++ 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):
@@ -84,10 +93,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
--- a/mercurial/scmutil.py	Wed Mar 25 14:56:54 2015 -0400
+++ 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'):