changeset 32499:a3583852861a

match: handle exact matching using new exactmatcher
author Martin von Zweigbergk <martinvonz@google.com>
date Wed, 17 May 2017 09:26:15 -0700
parents bd56bea5ecf8
children 369c2d5eeea3
files mercurial/match.py
diffstat 1 files changed, 34 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/match.py	Fri May 12 16:33:33 2017 -0700
+++ b/mercurial/match.py	Wed May 17 09:26:15 2017 -0700
@@ -142,9 +142,12 @@
                 kindpats.append((kind, pats, source))
             return kindpats
 
-    m = matcher(root, cwd, normalize, patterns, include=None,
-                default=default, exact=exact, auditor=auditor, ctx=ctx,
-                listsubrepos=listsubrepos, warn=warn, badfn=badfn)
+    if exact:
+        m = exactmatcher(root, cwd, patterns, badfn)
+    else:
+        m = matcher(root, cwd, normalize, patterns, include=None,
+                    default=default, exact=exact, auditor=auditor, ctx=ctx,
+                    listsubrepos=listsubrepos, warn=warn, badfn=badfn)
     if include:
         im = matcher(root, cwd, normalize, [], include=include, default=default,
                      exact=False, auditor=auditor, ctx=ctx,
@@ -158,7 +161,7 @@
     return m
 
 def exact(root, cwd, files, badfn=None):
-    return match(root, cwd, files, exact=True, badfn=badfn)
+    return exactmatcher(root, cwd, files, badfn=badfn)
 
 def always(root, cwd):
     return match(root, cwd, [])
@@ -406,6 +409,33 @@
         return ('<matcher files=%r, patterns=%r, includes=%r>' %
                 (self._files, self.patternspat, self.includepat))
 
+class exactmatcher(basematcher):
+    '''Matches the input files exactly. They are interpreted as paths, not
+    patterns (so no kind-prefixes).
+    '''
+
+    def __init__(self, root, cwd, files, badfn=None):
+        super(exactmatcher, self).__init__(root, cwd, badfn)
+
+        if isinstance(files, list):
+            self._files = files
+        else:
+            self._files = list(files)
+        self.matchfn = self.exact
+
+    @propertycache
+    def _dirs(self):
+        return set(util.dirs(self._fileset)) | {'.'}
+
+    def visitdir(self, dir):
+        return dir in self._dirs
+
+    def isexact(self):
+        return True
+
+    def __repr__(self):
+        return ('<exactmatcher files=%r>' % self._files)
+
 class differencematcher(basematcher):
     '''Composes two matchers by matching if the first matches and the second
     does not. Well, almost... If the user provides a pattern like "-X foo foo",