# HG changeset patch # User Martin von Zweigbergk # Date 1495087362 25200 # Node ID f9445b52868731c1c947b432e438c1cc2402d809 # Parent 9f781f43f2cecc3a39b63a2404e93c601c54cfbf 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 -r 9f781f43f2ce -r f9445b528687 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]