diff 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
line wrap: on
line diff
--- a/mercurial/match.py	Thu Jul 06 16:01:36 2017 -0700
+++ b/mercurial/match.py	Thu Jul 06 17:39:24 2017 -0700
@@ -641,6 +641,59 @@
         return ('<subdirmatcher path=%r, matcher=%r>' %
                 (self._path, self._matcher))
 
+class forceincludematcher(basematcher):
+    """A matcher that returns true for any of the forced includes before testing
+    against the actual matcher."""
+    def __init__(self, matcher, includes):
+        self._matcher = matcher
+        self._includes = includes
+
+    def __call__(self, value):
+        return value in self._includes or self._matcher(value)
+
+    def anypats(self):
+        return True
+
+    def prefix(self):
+        return False
+
+    def __repr__(self):
+        return ('<forceincludematcher matcher=%r, includes=%r>' %
+                (self._matcher, sorted(self._includes)))
+
+class unionmatcher(basematcher):
+    """A matcher that is the union of several matchers."""
+    def __init__(self, matchers):
+        self._matchers = matchers
+
+    def __call__(self, value):
+        for match in self._matchers:
+            if match(value):
+                return True
+        return False
+
+    def anypats(self):
+        return True
+
+    def prefix(self):
+        return False
+
+    def __repr__(self):
+        return ('<unionmatcher matchers=%r>' % self._matchers)
+
+class negatematcher(basematcher):
+    def __init__(self, matcher):
+        self._matcher = matcher
+
+    def __call__(self, value):
+        return not self._matcher(value)
+
+    def anypats(self):
+        return True
+
+    def __repr__(self):
+        return ('<negatematcher matcher=%r>' % self._matcher)
+
 def patkind(pattern, default=None):
     '''If pattern is 'kind:pat' with a known kind, return kind.'''
     return _patsplit(pattern, default)[0]