[PATCH 5 of 5] match: remove special-casing of always-matching patterns in patternmatcher

Martin von Zweigbergk martinvonz at google.com
Tue May 30 02:50:35 EDT 2017


# HG changeset patch
# User Martin von Zweigbergk <martinvonz at google.com>
# Date 1495224975 25200
#      Fri May 19 13:16:15 2017 -0700
# Node ID 417eb24effd52d19642d3e5113f77cfeab0d8c10
# Parent  7a00646bfff19e9589927a5c0fa46502baaea2aa
match: remove special-casing of always-matching patterns in patternmatcher

This moves the optimization for patterns that match everything to the
caller, so we can remove it from patternmatcher.

Note that we need to teach alwaysmatcher to use relative paths now in
cases like "hg files .." from inside mercurial/, because while it
still matches everything, paths should be printed relative to the
working directory.

diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -146,8 +146,11 @@
         m = exactmatcher(root, cwd, patterns, badfn)
     elif patterns:
         kindpats = normalize(patterns, default, root, cwd, auditor, warn)
-        m = patternmatcher(root, cwd, kindpats, ctx=ctx,
-                           listsubrepos=listsubrepos, badfn=badfn)
+        if _kindpatsalwaysmatch(kindpats):
+            m = alwaysmatcher(root, cwd, badfn, relativeuipath=True)
+        else:
+            m = patternmatcher(root, cwd, kindpats, ctx=ctx,
+                               listsubrepos=listsubrepos, badfn=badfn)
     else:
         # It's a little strange that no patterns means to match everything.
         # Consider changing this to match nothing (probably adding a
@@ -320,9 +323,9 @@
 class alwaysmatcher(basematcher):
     '''Matches everything.'''
 
-    def __init__(self, root, cwd, badfn=None):
+    def __init__(self, root, cwd, badfn=None, relativeuipath=False):
         super(alwaysmatcher, self).__init__(root, cwd, badfn,
-                                            relativeuipath=False)
+                                            relativeuipath=relativeuipath)
 
     def always(self):
         return True
@@ -342,26 +345,17 @@
                  badfn=None):
         super(patternmatcher, self).__init__(root, cwd, badfn)
 
-        if not _kindpatsalwaysmatch(kindpats):
-            self._files = _explicitfiles(kindpats)
-            self._anypats = _anypats(kindpats)
-            self.patternspat, pm = _buildmatch(ctx, kindpats, '$',
-                                               listsubrepos, root)
-            self._always = False
-            self.matchfn = pm
-        else:
-            self._anypats = False
-            self.patternspat = None
-            self._always = True
-            self.matchfn = lambda f: True
+        self._files = _explicitfiles(kindpats)
+        self._anypats = _anypats(kindpats)
+        self.patternspat, pm = _buildmatch(ctx, kindpats, '$', listsubrepos,
+                                           root)
+        self.matchfn = pm
 
     @propertycache
     def _dirs(self):
         return set(util.dirs(self._fileset)) | {'.'}
 
     def visitdir(self, dir):
-        if self.always():
-            return 'all'
         if self.prefix() and dir in self._fileset:
             return 'all'
         return ('.' in self._fileset or
@@ -373,9 +367,6 @@
     def anypats(self):
         return self._anypats
 
-    def always(self):
-        return self._always
-
     def __repr__(self):
         return ('<patternmatcher patterns=%r>' % self.patternspat)
 


More information about the Mercurial-devel mailing list