match: inverse _anypats(), making it _prefix()
authorMartin von Zweigbergk <martinvonz@google.com>
Tue, 11 Jul 2017 09:42:32 -0700
changeset 38802 6aa643762641b32f91b635be9aa81372503cabfa
parent 38801 0d5afd360e9ec118081c2e2ed5146af80086c49a
child 38803 168ba5c4dfcbe076747986a4d7305e0c93e5a9a7
push id549
push usergszorc@mozilla.com
push dateSat, 15 Jul 2017 21:13:22 +0000
match: inverse _anypats(), making it _prefix()
mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -368,57 +368,56 @@ class nevermatcher(basematcher):
 
 class patternmatcher(basematcher):
 
     def __init__(self, root, cwd, kindpats, ctx=None, listsubrepos=False,
                  badfn=None):
         super(patternmatcher, self).__init__(root, cwd, badfn)
 
         self._files = _explicitfiles(kindpats)
-        self._anypats = _anypats(kindpats)
+        self._prefix = _prefix(kindpats)
         self._pats, self.matchfn = _buildmatch(ctx, kindpats, '$', listsubrepos,
                                                root)
 
     @propertycache
     def _dirs(self):
         return set(util.dirs(self._fileset)) | {'.'}
 
     def visitdir(self, dir):
-        if self.prefix() and dir in self._fileset:
+        if self._prefix and dir in self._fileset:
             return 'all'
         return ('.' in self._fileset or
                 dir in self._fileset or
                 dir in self._dirs or
                 any(parentdir in self._fileset
                     for parentdir in util.finddirs(dir)))
 
     def prefix(self):
-        return not self._anypats
+        return self._prefix
 
     def __repr__(self):
         return ('<patternmatcher patterns=%r>' % self._pats)
 
 class includematcher(basematcher):
 
     def __init__(self, root, cwd, kindpats, ctx=None, listsubrepos=False,
                  badfn=None):
         super(includematcher, self).__init__(root, cwd, badfn)
 
         self._pats, self.matchfn = _buildmatch(ctx, kindpats, '(?:/|$)',
                                                listsubrepos, root)
-        self._anypats = _anypats(kindpats)
+        self._prefix = _prefix(kindpats)
         roots, dirs = _rootsanddirs(kindpats)
         # roots are directories which are recursively included.
         self._roots = set(roots)
         # dirs are directories which are non-recursively included.
         self._dirs = set(dirs)
 
     def visitdir(self, dir):
-        if not self._anypats and dir in self._roots:
-            # The condition above is essentially self.prefix() for includes
+        if self._prefix and dir in self._roots:
             return 'all'
         return ('.' in self._roots or
                 dir in self._roots or
                 dir in self._dirs or
                 any(parentdir in self._roots
                     for parentdir in util.finddirs(dir)))
 
     def __repr__(self):
@@ -943,20 +942,22 @@ def _explicitfiles(kindpats):
     >>> _explicitfiles([('rootfilesin', 'foo/bar', '')])
     []
     '''
     # Keep only the pattern kinds where one can specify filenames (vs only
     # directory names).
     filable = [kp for kp in kindpats if kp[0] not in ('rootfilesin',)]
     return _roots(filable)
 
-def _anypats(kindpats):
+def _prefix(kindpats):
+    '''Whether all the patterns match a prefix (i.e. recursively)'''
     for kind, pat, source in kindpats:
-        if kind in ('glob', 're', 'relglob', 'relre', 'set', 'rootfilesin'):
-            return True
+        if kind not in ('path', 'relpath'):
+            return False
+    return True
 
 _commentre = None
 
 def readpatternfile(filepath, warn, sourceinfo=False):
     '''parse a pattern file, returning a list of
     patterns. These patterns should be given to compile()
     to be validated and converted into a match function.