[PATCH 4 of 5] match: make subdirmatcher extend basematcher
Martin von Zweigbergk
martinvonz at google.com
Tue May 23 20:04:36 EDT 2017
# HG changeset patch
# User Martin von Zweigbergk <martinvonz at 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).
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]
More information about the Mercurial-devel
mailing list