430 s = (stringutil.buildrepr(self._predrepr) |
430 s = (stringutil.buildrepr(self._predrepr) |
431 or pycompat.byterepr(self.matchfn)) |
431 or pycompat.byterepr(self.matchfn)) |
432 return '<predicatenmatcher pred=%s>' % s |
432 return '<predicatenmatcher pred=%s>' % s |
433 |
433 |
434 class patternmatcher(basematcher): |
434 class patternmatcher(basematcher): |
|
435 """Matches a set of (kind, pat, source) against a 'root' directory. |
|
436 |
|
437 >>> kindpats = [ |
|
438 ... ('re', '.*\.c$', ''), |
|
439 ... ('path', 'foo/a', ''), |
|
440 ... ('relpath', 'b', ''), |
|
441 ... ('glob', '*.h', ''), |
|
442 ... ] |
|
443 >>> m = patternmatcher('foo', kindpats) |
|
444 >>> bool(m('main.c')) # matches re:.*\.c$ |
|
445 True |
|
446 >>> bool(m('b.txt')) |
|
447 False |
|
448 >>> bool(m('foo/a')) # matches path:foo/a |
|
449 True |
|
450 >>> bool(m('a')) # does not match path:b, since 'root' is 'foo' |
|
451 False |
|
452 >>> bool(m('b')) # matches relpath:b, since 'root' is 'foo' |
|
453 True |
|
454 >>> bool(m('lib.h')) # matches glob:*.h |
|
455 True |
|
456 |
|
457 >>> m.files() |
|
458 ['.', 'foo/a', 'b', '.'] |
|
459 >>> m.exact('foo/a') |
|
460 True |
|
461 >>> m.exact('b') |
|
462 True |
|
463 >>> m.exact('lib.h') # exact matches are for (rel)path kinds |
|
464 False |
|
465 """ |
435 |
466 |
436 def __init__(self, root, kindpats, badfn=None): |
467 def __init__(self, root, kindpats, badfn=None): |
437 super(patternmatcher, self).__init__(badfn) |
468 super(patternmatcher, self).__init__(badfn) |
438 |
469 |
439 self._files = _explicitfiles(kindpats) |
470 self._files = _explicitfiles(kindpats) |