comparison mercurial/match.py @ 33447:6f4e5e5940a5

match: write forceincludematcher using unionmatcher The forceincludematcher is simply a unionmatcher of a includematcher (matching paths recursively) with the given matcher. Since the forceincludematcher is only used by sparse, move it there. I don't have a good sparse repo setup to test performance impact on. Differential Revision: https://phab.mercurial-scm.org/D57
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 07 Jul 2017 14:39:59 -0700
parents 6aa643762641
children 04be8aec44a8
comparison
equal deleted inserted replaced
33446:fad6852cf879 33447:6f4e5e5940a5
644 return self._matcher.prefix() and not self._always 644 return self._matcher.prefix() and not self._always
645 645
646 def __repr__(self): 646 def __repr__(self):
647 return ('<subdirmatcher path=%r, matcher=%r>' % 647 return ('<subdirmatcher path=%r, matcher=%r>' %
648 (self._path, self._matcher)) 648 (self._path, self._matcher))
649
650 class forceincludematcher(basematcher):
651 """A matcher that returns true for any of the forced includes before testing
652 against the actual matcher."""
653 def __init__(self, matcher, includes):
654 self._matcher = matcher
655 self._includes = includes
656
657 def matchfn(self, f):
658 return f in self._includes or self._matcher(f)
659
660 def __repr__(self):
661 return ('<forceincludematcher matcher=%r, includes=%r>' %
662 (self._matcher, sorted(self._includes)))
663 649
664 class unionmatcher(basematcher): 650 class unionmatcher(basematcher):
665 """A matcher that is the union of several matchers.""" 651 """A matcher that is the union of several matchers."""
666 def __init__(self, matchers): 652 def __init__(self, matchers):
667 self._matchers = matchers 653 self._matchers = matchers