Patchwork [4,of,5] match: make subdirmatcher extend basematcher

login
register
mail settings
Submitter via Mercurial-devel
Date May 24, 2017, 12:04 a.m.
Message ID <af9dcab6479262b7ac8a.1495584276@martinvonz.svl.corp.google.com>
Download mbox | patch
Permalink /patch/20874/
State Accepted
Headers show

Comments

via Mercurial-devel - May 24, 2017, 12:04 a.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1495087362 25200
#      Wed May 17 23:02:42 2017 -0700
# Node ID af9dcab6479262b7ac8a570ac8607534079e6f84
# Parent  21907ffdb1183eee1659b439efeb7bc737287d32
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).

Patch

diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -408,7 +408,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:
@@ -439,11 +439,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 + "/")]
@@ -453,7 +452,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
@@ -479,6 +477,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]