--- a/mercurial/match.py Fri Dec 27 16:47:47 2019 +0100
+++ b/mercurial/match.py Thu Dec 26 16:45:56 2019 -0500
@@ -182,35 +182,38 @@
the same directory
'<something>' - a pattern of the specified default type
+ >>> def _match(root, *args, **kwargs):
+ ... return match(util.localpath(root), *args, **kwargs)
+
Usually a patternmatcher is returned:
- >>> match(b'/foo', b'.', [b're:.*\.c$', b'path:foo/a', b'*.py'])
+ >>> _match(b'/foo', b'.', [b're:.*\.c$', b'path:foo/a', b'*.py'])
<patternmatcher patterns='.*\\.c$|foo/a(?:/|$)|[^/]*\\.py$'>
Combining 'patterns' with 'include' (resp. 'exclude') gives an
intersectionmatcher (resp. a differencematcher):
- >>> type(match(b'/foo', b'.', [b're:.*\.c$'], include=[b'path:lib']))
+ >>> type(_match(b'/foo', b'.', [b're:.*\.c$'], include=[b'path:lib']))
<class 'mercurial.match.intersectionmatcher'>
- >>> type(match(b'/foo', b'.', [b're:.*\.c$'], exclude=[b'path:build']))
+ >>> type(_match(b'/foo', b'.', [b're:.*\.c$'], exclude=[b'path:build']))
<class 'mercurial.match.differencematcher'>
Notice that, if 'patterns' is empty, an alwaysmatcher is returned:
- >>> match(b'/foo', b'.', [])
+ >>> _match(b'/foo', b'.', [])
<alwaysmatcher>
The 'default' argument determines which kind of pattern is assumed if a
pattern has no prefix:
- >>> match(b'/foo', b'.', [b'.*\.c$'], default=b're')
+ >>> _match(b'/foo', b'.', [b'.*\.c$'], default=b're')
<patternmatcher patterns='.*\\.c$'>
- >>> match(b'/foo', b'.', [b'main.py'], default=b'relpath')
+ >>> _match(b'/foo', b'.', [b'main.py'], default=b'relpath')
<patternmatcher patterns='main\\.py(?:/|$)'>
- >>> match(b'/foo', b'.', [b'main.py'], default=b're')
+ >>> _match(b'/foo', b'.', [b'main.py'], default=b're')
<patternmatcher patterns='main.py'>
The primary use of matchers is to check whether a value (usually a file
name) matches againset one of the patterns given at initialization. There
are two ways of doing this check.
- >>> m = match(b'/foo', b'', [b're:.*\.c$', b'relpath:a'])
+ >>> m = _match(b'/foo', b'', [b're:.*\.c$', b'relpath:a'])
1. Calling the matcher with a file name returns True if any pattern
matches that file name:
@@ -942,7 +945,7 @@
The paths are remapped to remove/insert the path as needed:
>>> from . import pycompat
- >>> m1 = match(b'/root', b'', [b'a.txt', b'sub/b.txt'])
+ >>> m1 = match(util.localpath(b'/root'), b'', [b'a.txt', b'sub/b.txt'])
>>> m2 = subdirmatcher(b'sub', m1)
>>> m2(b'a.txt')
False