comparison 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
comparison
equal deleted inserted replaced
43963:bbcf78c4ff90 43964:8f67735344ae
180 'include:<path>' - a file of patterns to read and include 180 'include:<path>' - a file of patterns to read and include
181 'subinclude:<path>' - a file of patterns to match against files under 181 'subinclude:<path>' - a file of patterns to match against files under
182 the same directory 182 the same directory
183 '<something>' - a pattern of the specified default type 183 '<something>' - a pattern of the specified default type
184 184
185 >>> def _match(root, *args, **kwargs):
186 ... return match(util.localpath(root), *args, **kwargs)
187
185 Usually a patternmatcher is returned: 188 Usually a patternmatcher is returned:
186 >>> match(b'/foo', b'.', [b're:.*\.c$', b'path:foo/a', b'*.py']) 189 >>> _match(b'/foo', b'.', [b're:.*\.c$', b'path:foo/a', b'*.py'])
187 <patternmatcher patterns='.*\\.c$|foo/a(?:/|$)|[^/]*\\.py$'> 190 <patternmatcher patterns='.*\\.c$|foo/a(?:/|$)|[^/]*\\.py$'>
188 191
189 Combining 'patterns' with 'include' (resp. 'exclude') gives an 192 Combining 'patterns' with 'include' (resp. 'exclude') gives an
190 intersectionmatcher (resp. a differencematcher): 193 intersectionmatcher (resp. a differencematcher):
191 >>> type(match(b'/foo', b'.', [b're:.*\.c$'], include=[b'path:lib'])) 194 >>> type(_match(b'/foo', b'.', [b're:.*\.c$'], include=[b'path:lib']))
192 <class 'mercurial.match.intersectionmatcher'> 195 <class 'mercurial.match.intersectionmatcher'>
193 >>> type(match(b'/foo', b'.', [b're:.*\.c$'], exclude=[b'path:build'])) 196 >>> type(_match(b'/foo', b'.', [b're:.*\.c$'], exclude=[b'path:build']))
194 <class 'mercurial.match.differencematcher'> 197 <class 'mercurial.match.differencematcher'>
195 198
196 Notice that, if 'patterns' is empty, an alwaysmatcher is returned: 199 Notice that, if 'patterns' is empty, an alwaysmatcher is returned:
197 >>> match(b'/foo', b'.', []) 200 >>> _match(b'/foo', b'.', [])
198 <alwaysmatcher> 201 <alwaysmatcher>
199 202
200 The 'default' argument determines which kind of pattern is assumed if a 203 The 'default' argument determines which kind of pattern is assumed if a
201 pattern has no prefix: 204 pattern has no prefix:
202 >>> match(b'/foo', b'.', [b'.*\.c$'], default=b're') 205 >>> _match(b'/foo', b'.', [b'.*\.c$'], default=b're')
203 <patternmatcher patterns='.*\\.c$'> 206 <patternmatcher patterns='.*\\.c$'>
204 >>> match(b'/foo', b'.', [b'main.py'], default=b'relpath') 207 >>> _match(b'/foo', b'.', [b'main.py'], default=b'relpath')
205 <patternmatcher patterns='main\\.py(?:/|$)'> 208 <patternmatcher patterns='main\\.py(?:/|$)'>
206 >>> match(b'/foo', b'.', [b'main.py'], default=b're') 209 >>> _match(b'/foo', b'.', [b'main.py'], default=b're')
207 <patternmatcher patterns='main.py'> 210 <patternmatcher patterns='main.py'>
208 211
209 The primary use of matchers is to check whether a value (usually a file 212 The primary use of matchers is to check whether a value (usually a file
210 name) matches againset one of the patterns given at initialization. There 213 name) matches againset one of the patterns given at initialization. There
211 are two ways of doing this check. 214 are two ways of doing this check.
212 215
213 >>> m = match(b'/foo', b'', [b're:.*\.c$', b'relpath:a']) 216 >>> m = _match(b'/foo', b'', [b're:.*\.c$', b'relpath:a'])
214 217
215 1. Calling the matcher with a file name returns True if any pattern 218 1. Calling the matcher with a file name returns True if any pattern
216 matches that file name: 219 matches that file name:
217 >>> m(b'a') 220 >>> m(b'a')
218 True 221 True
940 """Adapt a matcher to work on a subdirectory only. 943 """Adapt a matcher to work on a subdirectory only.
941 944
942 The paths are remapped to remove/insert the path as needed: 945 The paths are remapped to remove/insert the path as needed:
943 946
944 >>> from . import pycompat 947 >>> from . import pycompat
945 >>> m1 = match(b'/root', b'', [b'a.txt', b'sub/b.txt']) 948 >>> m1 = match(util.localpath(b'/root'), b'', [b'a.txt', b'sub/b.txt'])
946 >>> m2 = subdirmatcher(b'sub', m1) 949 >>> m2 = subdirmatcher(b'sub', m1)
947 >>> m2(b'a.txt') 950 >>> m2(b'a.txt')
948 False 951 False
949 >>> m2(b'b.txt') 952 >>> m2(b'b.txt')
950 True 953 True