Mercurial > hg
comparison mercurial/match.py @ 33319:3c84591e7321
match: move matchers from sparse into core
The sparse extension contains some matcher types that are
generic and can exist in core.
As part of the move, the classes now inherit from basematcher.
always(), files(), and isexact() have been dropped because
they match the default implementations in basematcher.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Thu, 06 Jul 2017 17:39:24 -0700 |
parents | a9808bd1449e |
children | a21819f439fe |
comparison
equal
deleted
inserted
replaced
33318:526255fe7899 | 33319:3c84591e7321 |
---|---|
638 return self._matcher.anypats() | 638 return self._matcher.anypats() |
639 | 639 |
640 def __repr__(self): | 640 def __repr__(self): |
641 return ('<subdirmatcher path=%r, matcher=%r>' % | 641 return ('<subdirmatcher path=%r, matcher=%r>' % |
642 (self._path, self._matcher)) | 642 (self._path, self._matcher)) |
643 | |
644 class forceincludematcher(basematcher): | |
645 """A matcher that returns true for any of the forced includes before testing | |
646 against the actual matcher.""" | |
647 def __init__(self, matcher, includes): | |
648 self._matcher = matcher | |
649 self._includes = includes | |
650 | |
651 def __call__(self, value): | |
652 return value in self._includes or self._matcher(value) | |
653 | |
654 def anypats(self): | |
655 return True | |
656 | |
657 def prefix(self): | |
658 return False | |
659 | |
660 def __repr__(self): | |
661 return ('<forceincludematcher matcher=%r, includes=%r>' % | |
662 (self._matcher, sorted(self._includes))) | |
663 | |
664 class unionmatcher(basematcher): | |
665 """A matcher that is the union of several matchers.""" | |
666 def __init__(self, matchers): | |
667 self._matchers = matchers | |
668 | |
669 def __call__(self, value): | |
670 for match in self._matchers: | |
671 if match(value): | |
672 return True | |
673 return False | |
674 | |
675 def anypats(self): | |
676 return True | |
677 | |
678 def prefix(self): | |
679 return False | |
680 | |
681 def __repr__(self): | |
682 return ('<unionmatcher matchers=%r>' % self._matchers) | |
683 | |
684 class negatematcher(basematcher): | |
685 def __init__(self, matcher): | |
686 self._matcher = matcher | |
687 | |
688 def __call__(self, value): | |
689 return not self._matcher(value) | |
690 | |
691 def anypats(self): | |
692 return True | |
693 | |
694 def __repr__(self): | |
695 return ('<negatematcher matcher=%r>' % self._matcher) | |
643 | 696 |
644 def patkind(pattern, default=None): | 697 def patkind(pattern, default=None): |
645 '''If pattern is 'kind:pat' with a known kind, return kind.''' | 698 '''If pattern is 'kind:pat' with a known kind, return kind.''' |
646 return _patsplit(pattern, default)[0] | 699 return _patsplit(pattern, default)[0] |
647 | 700 |