Mercurial > hg
changeset 38577:76838305b9dd
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>>
...
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 09 Jun 2018 21:13:24 +0900 |
parents | a3130208db1c |
children | 2d487b9cac07 |
files | mercurial/match.py |
diffstat | 1 files changed, 14 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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,