Mercurial > hg
diff mercurial/match.py @ 43964:8f67735344ae
tests: convert the `root` arg of matchmod.match() to local path separators
This fixes tests that broke with 8b1a9ba375e5, complaining that "X not under
root /repo". The vast majority of real uses are to pass `repo.root`, which is
normalized by `wdirvfs.base` being set to the result of `os.path.realpath()`.
Failure to convert looks like this:
--- c:/Users/Matt/hg/tests/test-match.py.out
+++ c:/Users/Matt/hg/tests/test-match.py.err
@@ -0,0 +1,48 @@
+ERROR: testVisitchildrensetGlob (__main__.IncludeMatcherTests)
+
+Traceback (most recent call last):
+ File "c:\Users\Matt\hg\tests\test-match.py", line 180, in testVisitchildrensetGlob
+ m = matchmod.match(b'/repo', b'', include=[b'glob:dir/z*'])
+ File "c:\Users\Matt\hg\mercurial\match.py", line 271, in match
+ kindpats = normalize(include, b'glob', root, cwd, auditor, warn)
+ File "c:\Users\Matt\hg\mercurial\match.py", line 322, in _donormalize
+ pat = pathutil.canonpath(root, cwd, pat, auditor=auditor)
+ File "c:\Users\Matt\hg\mercurial\pathutil.py", line 251, in canonpath
+ _(b"%s not under root '%s'") % (myname, root), hint=hint
+Abort: dir/z* not under root '/repo'
+ERROR: testVisitdirGlob (__main__.IncludeMatcherTests)
Differential Revision: https://phab.mercurial-scm.org/D7724
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Thu, 26 Dec 2019 16:45:56 -0500 |
parents | 5685ce2ea3bf |
children | 8a81fa44f7bb |
line wrap: on
line diff
--- 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