comparison mercurial/match.py @ 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 67dc32d4e790
children 2d487b9cac07
comparison
equal deleted inserted replaced
38576:a3130208db1c 38577:76838305b9dd
372 def visitdir(self, dir): 372 def visitdir(self, dir):
373 return False 373 return False
374 374
375 def __repr__(self): 375 def __repr__(self):
376 return r'<nevermatcher>' 376 return r'<nevermatcher>'
377
378 class predicatematcher(basematcher):
379 """A matcher adapter for a simple boolean function"""
380
381 def __init__(self, root, cwd, predfn, predrepr=None, badfn=None):
382 super(predicatematcher, self).__init__(root, cwd, badfn)
383 self.matchfn = predfn
384 self._predrepr = predrepr
385
386 @encoding.strmethod
387 def __repr__(self):
388 s = (stringutil.buildrepr(self._predrepr)
389 or pycompat.byterepr(self.matchfn))
390 return '<predicatenmatcher pred=%s>' % s
377 391
378 class patternmatcher(basematcher): 392 class patternmatcher(basematcher):
379 393
380 def __init__(self, root, cwd, kindpats, ctx=None, listsubrepos=False, 394 def __init__(self, root, cwd, kindpats, ctx=None, listsubrepos=False,
381 badfn=None): 395 badfn=None):