match: add basic wrapper for boolean function
authorYuya Nishihara <yuya@tcha.org>
Sat, 09 Jun 2018 21:13:24 +0900
changeset 38577 76838305b9dd
parent 38576 a3130208db1c
child 38578 2d487b9cac07
match: add basic wrapper for boolean function This serves as a generic wrapper for fileset predicates. In future patches, a fileset expression will be mapped to a tree of matchers for a better support of match attributes such as visitdir(). For example, $ hg debugwalk -v 'set:contrib/** and binary()' * matcher: <intersectionmatcher m1=<patternmatcher patterns='(?:contrib/.*$)'>, m2=<predicatematcher pred=binary>> ...
mercurial/match.py
--- a/mercurial/match.py	Sun Jun 10 17:19:31 2018 +0900
+++ b/mercurial/match.py	Sat Jun 09 21:13:24 2018 +0900
@@ -375,6 +375,20 @@
     def __repr__(self):
         return r'<nevermatcher>'
 
+class predicatematcher(basematcher):
+    """A matcher adapter for a simple boolean function"""
+
+    def __init__(self, root, cwd, predfn, predrepr=None, badfn=None):
+        super(predicatematcher, self).__init__(root, cwd, badfn)
+        self.matchfn = predfn
+        self._predrepr = predrepr
+
+    @encoding.strmethod
+    def __repr__(self):
+        s = (stringutil.buildrepr(self._predrepr)
+             or pycompat.byterepr(self.matchfn))
+        return '<predicatenmatcher pred=%s>' % s
+
 class patternmatcher(basematcher):
 
     def __init__(self, root, cwd, kindpats, ctx=None, listsubrepos=False,