Patchwork [07,of,17] match: handle exact matching using new exactmatcher

login
register
mail settings
Submitter via Mercurial-devel
Date May 25, 2017, 6:24 p.m.
Message ID <fcae8bf1d1fbb5d7deb1.1495736688@martinvonz.svl.corp.google.com>
Download mbox | patch
Permalink /patch/20909/
State Accepted
Headers show

Comments

via Mercurial-devel - May 25, 2017, 6:24 p.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1495038375 25200
#      Wed May 17 09:26:15 2017 -0700
# Node ID fcae8bf1d1fbb5d7deb15b4dfa8f7a3ea768eef2
# Parent  64552de63b1b8d50927699c09c27ab148be4e39a
match: handle exact matching using new exactmatcher

Patch

diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -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, [])
@@ -408,6 +411,30 @@ 
         return ('<matcher files=%r, patterns=%r, includes=%r>' %
                 (self._files, self.patternspat, self.includepat))
 
+class exactmatcher(basematcher):
+
+    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",