Mercurial > hg-stable
changeset 33405:6aa643762641
match: inverse _anypats(), making it _prefix()
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Tue, 11 Jul 2017 09:42:32 -0700 |
parents | 0d5afd360e9e |
children | 168ba5c4dfcb |
files | mercurial/match.py |
diffstat | 1 files changed, 10 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/match.py Tue Jul 11 20:53:55 2017 -0700 +++ b/mercurial/match.py Tue Jul 11 09:42:32 2017 -0700 @@ -373,7 +373,7 @@ super(patternmatcher, self).__init__(root, cwd, badfn) self._files = _explicitfiles(kindpats) - self._anypats = _anypats(kindpats) + self._prefix = _prefix(kindpats) self._pats, self.matchfn = _buildmatch(ctx, kindpats, '$', listsubrepos, root) @@ -382,7 +382,7 @@ return set(util.dirs(self._fileset)) | {'.'} def visitdir(self, dir): - if self.prefix() and dir in self._fileset: + if self._prefix and dir in self._fileset: return 'all' return ('.' in self._fileset or dir in self._fileset or @@ -391,7 +391,7 @@ for parentdir in util.finddirs(dir))) def prefix(self): - return not self._anypats + return self._prefix def __repr__(self): return ('<patternmatcher patterns=%r>' % self._pats) @@ -404,7 +404,7 @@ self._pats, self.matchfn = _buildmatch(ctx, kindpats, '(?:/|$)', listsubrepos, root) - self._anypats = _anypats(kindpats) + self._prefix = _prefix(kindpats) roots, dirs = _rootsanddirs(kindpats) # roots are directories which are recursively included. self._roots = set(roots) @@ -412,8 +412,7 @@ self._dirs = set(dirs) def visitdir(self, dir): - if not self._anypats and dir in self._roots: - # The condition above is essentially self.prefix() for includes + if self._prefix and dir in self._roots: return 'all' return ('.' in self._roots or dir in self._roots or @@ -948,10 +947,12 @@ filable = [kp for kp in kindpats if kp[0] not in ('rootfilesin',)] return _roots(filable) -def _anypats(kindpats): +def _prefix(kindpats): + '''Whether all the patterns match a prefix (i.e. recursively)''' for kind, pat, source in kindpats: - if kind in ('glob', 're', 'relglob', 'relre', 'set', 'rootfilesin'): - return True + if kind not in ('path', 'relpath'): + return False + return True _commentre = None