match: make subdirmatcher extend basematcher
authorMartin von Zweigbergk <martinvonz@google.com>
Wed, 17 May 2017 23:02:42 -0700
changeset 32460 f9445b528687
parent 32459 9f781f43f2ce
child 32461 2b5953a49f14
match: make subdirmatcher extend basematcher This makes the subdirmatcher not depend on the main matcher, giving us more freedom to modify that (specifically, it will lose it _always field in a while).
mercurial/match.py
--- a/mercurial/match.py	Fri May 19 10:17:08 2017 -0700
+++ b/mercurial/match.py	Wed May 17 23:02:42 2017 -0700
@@ -409,7 +409,7 @@
                 (self._files, self.patternspat, self.includepat,
                  self.excludepat))
 
-class subdirmatcher(matcher):
+class subdirmatcher(basematcher):
     """Adapt a matcher to work on a subdirectory only.
 
     The paths are remapped to remove/insert the path as needed:
@@ -440,11 +440,10 @@
     """
 
     def __init__(self, path, matcher):
-        self._root = matcher._root
-        self._cwd = matcher._cwd
+        super(subdirmatcher, self).__init__(matcher._root, matcher._cwd)
         self._path = path
         self._matcher = matcher
-        self._always = matcher._always
+        self._always = matcher.always()
 
         self._files = [f[len(path) + 1:] for f in matcher._files
                        if f.startswith(path + "/")]
@@ -454,7 +453,6 @@
         if matcher.prefix():
             self._always = any(f == path for f in matcher._files)
 
-        self._anypats = matcher._anypats
         # Some information is lost in the superclass's constructor, so we
         # can not accurately create the matching function for the subdirectory
         # from the inputs. Instead, we override matchfn() and visitdir() to
@@ -480,6 +478,12 @@
             dir = self._path + "/" + dir
         return self._matcher.visitdir(dir)
 
+    def always(self):
+        return self._always
+
+    def anypats(self):
+        return self._matcher.anypats()
+
 def patkind(pattern, default=None):
     '''If pattern is 'kind:pat' with a known kind, return kind.'''
     return _patsplit(pattern, default)[0]