195 >>> def _match(root, *args, **kwargs): |
195 >>> def _match(root, *args, **kwargs): |
196 ... return match(util.localpath(root), *args, **kwargs) |
196 ... return match(util.localpath(root), *args, **kwargs) |
197 |
197 |
198 Usually a patternmatcher is returned: |
198 Usually a patternmatcher is returned: |
199 >>> _match(b'/foo', b'.', [br're:.*\.c$', b'path:foo/a', b'*.py']) |
199 >>> _match(b'/foo', b'.', [br're:.*\.c$', b'path:foo/a', b'*.py']) |
200 <patternmatcher patterns='.*\\.c$|foo/a(?:/|$)|[^/]*\\.py$'> |
200 <patternmatcher patterns='[^/]*\\.py$|foo/a(?:/|$)|.*\\.c$'> |
201 |
201 |
202 Combining 'patterns' with 'include' (resp. 'exclude') gives an |
202 Combining 'patterns' with 'include' (resp. 'exclude') gives an |
203 intersectionmatcher (resp. a differencematcher): |
203 intersectionmatcher (resp. a differencematcher): |
204 >>> type(_match(b'/foo', b'.', [br're:.*\.c$'], include=[b'path:lib'])) |
204 >>> type(_match(b'/foo', b'.', [br're:.*\.c$'], include=[b'path:lib'])) |
205 <class 'mercurial.match.intersectionmatcher'> |
205 <class 'mercurial.match.intersectionmatcher'> |
612 True |
612 True |
613 >>> m(b'lib.h') # matches glob:*.h |
613 >>> m(b'lib.h') # matches glob:*.h |
614 True |
614 True |
615 |
615 |
616 >>> m.files() |
616 >>> m.files() |
617 ['', 'foo/a', 'b', ''] |
617 [b'', b'foo/a', b'', b'b'] |
618 >>> m.exact(b'foo/a') |
618 >>> m.exact(b'foo/a') |
619 True |
619 True |
620 >>> m.exact(b'b') |
620 >>> m.exact(b'b') |
621 True |
621 True |
622 >>> m.exact(b'lib.h') # exact matches are for (rel)path kinds |
622 >>> m.exact(b'lib.h') # exact matches are for (rel)path kinds |
623 False |
623 False |
624 """ |
624 """ |
625 |
625 |
626 def __init__(self, root, kindpats, badfn=None): |
626 def __init__(self, root, kindpats, badfn=None): |
627 super(patternmatcher, self).__init__(badfn) |
627 super(patternmatcher, self).__init__(badfn) |
|
628 kindpats.sort() |
628 |
629 |
629 self._files = _explicitfiles(kindpats) |
630 self._files = _explicitfiles(kindpats) |
630 self._prefix = _prefix(kindpats) |
631 self._prefix = _prefix(kindpats) |
631 self._pats, self.matchfn = _buildmatch(kindpats, b'$', root) |
632 self._pats, self.matchfn = _buildmatch(kindpats, b'$', root) |
632 |
633 |