diff --git a/mercurial/match.py b/mercurial/match.py --- a/mercurial/match.py +++ b/mercurial/match.py @@ -182,35 +182,38 @@ the same directory '' - 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']) 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'])) - >>> type(match(b'/foo', b'.', [b're:.*\.c$'], exclude=[b'path:build'])) + >>> type(_match(b'/foo', b'.', [b're:.*\.c$'], exclude=[b'path:build'])) Notice that, if 'patterns' is empty, an alwaysmatcher is returned: - >>> match(b'/foo', b'.', []) + >>> _match(b'/foo', b'.', []) 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') - >>> match(b'/foo', b'.', [b'main.py'], default=b'relpath') + >>> _match(b'/foo', b'.', [b'main.py'], default=b'relpath') - >>> match(b'/foo', b'.', [b'main.py'], default=b're') + >>> _match(b'/foo', b'.', [b'main.py'], default=b're') 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 diff --git a/tests/test-manifest.py b/tests/test-manifest.py --- a/tests/test-manifest.py +++ b/tests/test-manifest.py @@ -9,6 +9,7 @@ from mercurial import ( manifest as manifestmod, match as matchmod, + util, ) EMTPY_MANIFEST = b'' @@ -169,7 +170,7 @@ m[b'foo'] = want + b'+' self.assertEqual(want, m[b'foo']) # make sure the suffix survives a copy - match = matchmod.match(b'/repo', b'', [b're:foo']) + match = matchmod.match(util.localpath(b'/repo'), b'', [b're:foo']) m2 = m.matches(match) self.assertEqual(want, m2[b'foo']) self.assertEqual(1, len(m2)) @@ -186,7 +187,7 @@ def testMatchException(self): m = self.parsemanifest(A_SHORT_MANIFEST) - match = matchmod.match(b'/repo', b'', [b're:.*']) + match = matchmod.match(util.localpath(b'/repo'), b'', [b're:.*']) def filt(path): if path == b'foo': @@ -328,7 +329,9 @@ actually exist.''' m = self.parsemanifest(A_DEEPER_MANIFEST) - match = matchmod.match(b'/repo', b'', [b'a/f'], default=b'relpath') + match = matchmod.match( + util.localpath(b'/repo'), b'', [b'a/f'], default=b'relpath' + ) m2 = m.matches(match) self.assertEqual([], m2.keys()) @@ -348,7 +351,7 @@ '''Tests matches() for what should be a full match.''' m = self.parsemanifest(A_DEEPER_MANIFEST) - match = matchmod.match(b'/repo', b'', [b'']) + match = matchmod.match(util.localpath(b'/repo'), b'', [b'']) m2 = m.matches(match) self.assertEqual(m.keys(), m2.keys()) @@ -358,7 +361,9 @@ match against all files within said directory.''' m = self.parsemanifest(A_DEEPER_MANIFEST) - match = matchmod.match(b'/repo', b'', [b'a/b'], default=b'relpath') + match = matchmod.match( + util.localpath(b'/repo'), b'', [b'a/b'], default=b'relpath' + ) m2 = m.matches(match) self.assertEqual( @@ -392,7 +397,9 @@ when not in the root directory.''' m = self.parsemanifest(A_DEEPER_MANIFEST) - match = matchmod.match(b'/repo', b'a/b', [b'.'], default=b'relpath') + match = matchmod.match( + util.localpath(b'/repo'), b'a/b', [b'.'], default=b'relpath' + ) m2 = m.matches(match) self.assertEqual( @@ -415,7 +422,7 @@ deeper than the specified directory.''' m = self.parsemanifest(A_DEEPER_MANIFEST) - match = matchmod.match(b'/repo', b'', [b'a/b/*/*.txt']) + match = matchmod.match(util.localpath(b'/repo'), b'', [b'a/b/*/*.txt']) m2 = m.matches(match) self.assertEqual( @@ -467,7 +474,7 @@ sorted(dirs), ) - match = matchmod.match(b'/repo', b'', [b'path:a/b/']) + match = matchmod.match(util.localpath(b'/repo'), b'', [b'path:a/b/']) dirs = [s._dir for s in m.walksubtrees(matcher=match)] self.assertEqual(sorted([b'a/b/', b'a/b/c/', b'a/b/d/']), sorted(dirs)) diff --git a/tests/test-match.py b/tests/test-match.py --- a/tests/test-match.py +++ b/tests/test-match.py @@ -66,7 +66,9 @@ class PatternMatcherTests(unittest.TestCase): def testVisitdirPrefix(self): - m = matchmod.match(b'/repo', b'', patterns=[b'path:dir/subdir']) + m = matchmod.match( + util.localpath(b'/repo'), b'', patterns=[b'path:dir/subdir'] + ) assert isinstance(m, matchmod.patternmatcher) self.assertTrue(m.visitdir(b'')) self.assertTrue(m.visitdir(b'dir')) @@ -76,7 +78,9 @@ self.assertFalse(m.visitdir(b'folder')) def testVisitchildrensetPrefix(self): - m = matchmod.match(b'/repo', b'', patterns=[b'path:dir/subdir']) + m = matchmod.match( + util.localpath(b'/repo'), b'', patterns=[b'path:dir/subdir'] + ) assert isinstance(m, matchmod.patternmatcher) self.assertEqual(m.visitchildrenset(b''), b'this') self.assertEqual(m.visitchildrenset(b'dir'), b'this') @@ -86,7 +90,9 @@ self.assertEqual(m.visitchildrenset(b'folder'), set()) def testVisitdirRootfilesin(self): - m = matchmod.match(b'/repo', b'', patterns=[b'rootfilesin:dir/subdir']) + m = matchmod.match( + util.localpath(b'/repo'), b'', patterns=[b'rootfilesin:dir/subdir'], + ) assert isinstance(m, matchmod.patternmatcher) self.assertFalse(m.visitdir(b'dir/subdir/x')) self.assertFalse(m.visitdir(b'folder')) @@ -96,7 +102,9 @@ self.assertFalse(m.visitdir(b'dir/subdir')) def testVisitchildrensetRootfilesin(self): - m = matchmod.match(b'/repo', b'', patterns=[b'rootfilesin:dir/subdir']) + m = matchmod.match( + util.localpath(b'/repo'), b'', patterns=[b'rootfilesin:dir/subdir'], + ) assert isinstance(m, matchmod.patternmatcher) self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), set()) self.assertEqual(m.visitchildrenset(b'folder'), set()) @@ -107,7 +115,9 @@ self.assertEqual(m.visitchildrenset(b'dir/subdir'), set()) def testVisitdirGlob(self): - m = matchmod.match(b'/repo', b'', patterns=[b'glob:dir/z*']) + m = matchmod.match( + util.localpath(b'/repo'), b'', patterns=[b'glob:dir/z*'] + ) assert isinstance(m, matchmod.patternmatcher) self.assertTrue(m.visitdir(b'')) self.assertTrue(m.visitdir(b'dir')) @@ -117,7 +127,9 @@ self.assertTrue(m.visitdir(b'dir/subdir/x')) def testVisitchildrensetGlob(self): - m = matchmod.match(b'/repo', b'', patterns=[b'glob:dir/z*']) + m = matchmod.match( + util.localpath(b'/repo'), b'', patterns=[b'glob:dir/z*'] + ) assert isinstance(m, matchmod.patternmatcher) self.assertEqual(m.visitchildrenset(b''), b'this') self.assertEqual(m.visitchildrenset(b'folder'), set()) @@ -129,7 +141,9 @@ class IncludeMatcherTests(unittest.TestCase): def testVisitdirPrefix(self): - m = matchmod.match(b'/repo', b'', include=[b'path:dir/subdir']) + m = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] + ) assert isinstance(m, matchmod.includematcher) self.assertTrue(m.visitdir(b'')) self.assertTrue(m.visitdir(b'dir')) @@ -139,7 +153,9 @@ self.assertFalse(m.visitdir(b'folder')) def testVisitchildrensetPrefix(self): - m = matchmod.match(b'/repo', b'', include=[b'path:dir/subdir']) + m = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] + ) assert isinstance(m, matchmod.includematcher) self.assertEqual(m.visitchildrenset(b''), {b'dir'}) self.assertEqual(m.visitchildrenset(b'dir'), {b'subdir'}) @@ -149,7 +165,9 @@ self.assertEqual(m.visitchildrenset(b'folder'), set()) def testVisitdirRootfilesin(self): - m = matchmod.match(b'/repo', b'', include=[b'rootfilesin:dir/subdir']) + m = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'rootfilesin:dir/subdir'] + ) assert isinstance(m, matchmod.includematcher) self.assertTrue(m.visitdir(b'')) self.assertTrue(m.visitdir(b'dir')) @@ -158,7 +176,9 @@ self.assertFalse(m.visitdir(b'folder')) def testVisitchildrensetRootfilesin(self): - m = matchmod.match(b'/repo', b'', include=[b'rootfilesin:dir/subdir']) + m = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'rootfilesin:dir/subdir'] + ) assert isinstance(m, matchmod.includematcher) self.assertEqual(m.visitchildrenset(b''), {b'dir'}) self.assertEqual(m.visitchildrenset(b'dir'), {b'subdir'}) @@ -167,7 +187,9 @@ self.assertEqual(m.visitchildrenset(b'folder'), set()) def testVisitdirGlob(self): - m = matchmod.match(b'/repo', b'', include=[b'glob:dir/z*']) + m = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'glob:dir/z*'] + ) assert isinstance(m, matchmod.includematcher) self.assertTrue(m.visitdir(b'')) self.assertTrue(m.visitdir(b'dir')) @@ -177,7 +199,9 @@ self.assertTrue(m.visitdir(b'dir/subdir/x')) def testVisitchildrensetGlob(self): - m = matchmod.match(b'/repo', b'', include=[b'glob:dir/z*']) + m = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'glob:dir/z*'] + ) assert isinstance(m, matchmod.includematcher) self.assertEqual(m.visitchildrenset(b''), {b'dir'}) self.assertEqual(m.visitchildrenset(b'folder'), set()) @@ -289,7 +313,9 @@ def testVisitdirM2SubdirPrefix(self): m1 = matchmod.alwaysmatcher() - m2 = matchmod.match(b'/repo', b'', patterns=[b'path:dir/subdir']) + m2 = matchmod.match( + util.localpath(b'/repo'), b'', patterns=[b'path:dir/subdir'] + ) dm = matchmod.differencematcher(m1, m2) self.assertEqual(dm.visitdir(b''), True) self.assertEqual(dm.visitdir(b'dir'), True) @@ -304,7 +330,9 @@ def testVisitchildrensetM2SubdirPrefix(self): m1 = matchmod.alwaysmatcher() - m2 = matchmod.match(b'/repo', b'', patterns=[b'path:dir/subdir']) + m2 = matchmod.match( + util.localpath(b'/repo'), b'', patterns=[b'path:dir/subdir'] + ) dm = matchmod.differencematcher(m1, m2) self.assertEqual(dm.visitchildrenset(b''), b'this') self.assertEqual(dm.visitchildrenset(b'dir'), b'this') @@ -320,8 +348,12 @@ # We're using includematcher instead of patterns because it behaves slightly # better (giving narrower results) than patternmatcher. def testVisitdirIncludeInclude(self): - m1 = matchmod.match(b'/repo', b'', include=[b'path:dir/subdir']) - m2 = matchmod.match(b'/repo', b'', include=[b'rootfilesin:dir']) + m1 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] + ) + m2 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'rootfilesin:dir'] + ) dm = matchmod.differencematcher(m1, m2) self.assertEqual(dm.visitdir(b''), True) self.assertEqual(dm.visitdir(b'dir'), True) @@ -335,8 +367,12 @@ self.assertEqual(dm.visitdir(b'dir/subdir/x'), True) def testVisitchildrensetIncludeInclude(self): - m1 = matchmod.match(b'/repo', b'', include=[b'path:dir/subdir']) - m2 = matchmod.match(b'/repo', b'', include=[b'rootfilesin:dir']) + m1 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] + ) + m2 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'rootfilesin:dir'] + ) dm = matchmod.differencematcher(m1, m2) self.assertEqual(dm.visitchildrenset(b''), {b'dir'}) self.assertEqual(dm.visitchildrenset(b'dir'), {b'subdir'}) @@ -405,7 +441,9 @@ def testVisitdirM2SubdirPrefix(self): m1 = matchmod.alwaysmatcher() - m2 = matchmod.match(b'/repo', b'', patterns=[b'path:dir/subdir']) + m2 = matchmod.match( + util.localpath(b'/repo'), b'', patterns=[b'path:dir/subdir'] + ) im = matchmod.intersectmatchers(m1, m2) self.assertEqual(im.visitdir(b''), True) self.assertEqual(im.visitdir(b'dir'), True) @@ -420,7 +458,9 @@ def testVisitchildrensetM2SubdirPrefix(self): m1 = matchmod.alwaysmatcher() - m2 = matchmod.match(b'/repo', b'', include=[b'path:dir/subdir']) + m2 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] + ) im = matchmod.intersectmatchers(m1, m2) self.assertEqual(im.visitchildrenset(b''), {b'dir'}) self.assertEqual(im.visitchildrenset(b'dir'), {b'subdir'}) @@ -434,8 +474,12 @@ # We're using includematcher instead of patterns because it behaves slightly # better (giving narrower results) than patternmatcher. def testVisitdirIncludeInclude(self): - m1 = matchmod.match(b'/repo', b'', include=[b'path:dir/subdir']) - m2 = matchmod.match(b'/repo', b'', include=[b'rootfilesin:dir']) + m1 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] + ) + m2 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'rootfilesin:dir'] + ) im = matchmod.intersectmatchers(m1, m2) self.assertEqual(im.visitdir(b''), True) self.assertEqual(im.visitdir(b'dir'), True) @@ -446,8 +490,12 @@ self.assertFalse(im.visitdir(b'dir/subdir/x')) def testVisitchildrensetIncludeInclude(self): - m1 = matchmod.match(b'/repo', b'', include=[b'path:dir/subdir']) - m2 = matchmod.match(b'/repo', b'', include=[b'rootfilesin:dir']) + m1 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] + ) + m2 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'rootfilesin:dir'] + ) im = matchmod.intersectmatchers(m1, m2) self.assertEqual(im.visitchildrenset(b''), {b'dir'}) self.assertEqual(im.visitchildrenset(b'dir'), b'this') @@ -460,8 +508,12 @@ # We're using includematcher instead of patterns because it behaves slightly # better (giving narrower results) than patternmatcher. def testVisitdirIncludeInclude2(self): - m1 = matchmod.match(b'/repo', b'', include=[b'path:dir/subdir']) - m2 = matchmod.match(b'/repo', b'', include=[b'path:folder']) + m1 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] + ) + m2 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:folder'] + ) im = matchmod.intersectmatchers(m1, m2) # FIXME: is True correct here? self.assertEqual(im.visitdir(b''), True) @@ -473,8 +525,12 @@ self.assertFalse(im.visitdir(b'dir/subdir/x')) def testVisitchildrensetIncludeInclude2(self): - m1 = matchmod.match(b'/repo', b'', include=[b'path:dir/subdir']) - m2 = matchmod.match(b'/repo', b'', include=[b'path:folder']) + m1 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] + ) + m2 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:folder'] + ) im = matchmod.intersectmatchers(m1, m2) # FIXME: is set() correct here? self.assertEqual(im.visitchildrenset(b''), set()) @@ -488,8 +544,12 @@ # We're using includematcher instead of patterns because it behaves slightly # better (giving narrower results) than patternmatcher. def testVisitdirIncludeInclude3(self): - m1 = matchmod.match(b'/repo', b'', include=[b'path:dir/subdir/x']) - m2 = matchmod.match(b'/repo', b'', include=[b'path:dir/subdir']) + m1 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:dir/subdir/x'] + ) + m2 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] + ) im = matchmod.intersectmatchers(m1, m2) self.assertEqual(im.visitdir(b''), True) self.assertEqual(im.visitdir(b'dir'), True) @@ -501,8 +561,12 @@ self.assertEqual(im.visitdir(b'dir/subdir/x'), True) def testVisitchildrensetIncludeInclude3(self): - m1 = matchmod.match(b'/repo', b'', include=[b'path:dir/subdir/x']) - m2 = matchmod.match(b'/repo', b'', include=[b'path:dir/subdir']) + m1 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:dir/subdir/x'] + ) + m2 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] + ) im = matchmod.intersectmatchers(m1, m2) self.assertEqual(im.visitchildrenset(b''), {b'dir'}) self.assertEqual(im.visitchildrenset(b'dir'), {b'subdir'}) @@ -516,8 +580,12 @@ # We're using includematcher instead of patterns because it behaves slightly # better (giving narrower results) than patternmatcher. def testVisitdirIncludeInclude4(self): - m1 = matchmod.match(b'/repo', b'', include=[b'path:dir/subdir/x']) - m2 = matchmod.match(b'/repo', b'', include=[b'path:dir/subdir/z']) + m1 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:dir/subdir/x'] + ) + m2 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:dir/subdir/z'] + ) im = matchmod.intersectmatchers(m1, m2) # OPT: these next three could probably be False as well. self.assertEqual(im.visitdir(b''), True) @@ -529,8 +597,12 @@ self.assertFalse(im.visitdir(b'dir/subdir/x')) def testVisitchildrensetIncludeInclude4(self): - m1 = matchmod.match(b'/repo', b'', include=[b'path:dir/subdir/x']) - m2 = matchmod.match(b'/repo', b'', include=[b'path:dir/subdir/z']) + m1 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:dir/subdir/x'] + ) + m2 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:dir/subdir/z'] + ) im = matchmod.intersectmatchers(m1, m2) # OPT: these next two could probably be set() as well. self.assertEqual(im.visitchildrenset(b''), {b'dir'}) @@ -623,7 +695,9 @@ def testVisitdirM2SubdirPrefix(self): m1 = matchmod.alwaysmatcher() - m2 = matchmod.match(b'/repo', b'', patterns=[b'path:dir/subdir']) + m2 = matchmod.match( + util.localpath(b'/repo'), b'', patterns=[b'path:dir/subdir'] + ) um = matchmod.unionmatcher([m1, m2]) self.assertEqual(um.visitdir(b''), b'all') self.assertEqual(um.visitdir(b'dir'), b'all') @@ -635,7 +709,9 @@ def testVisitchildrensetM2SubdirPrefix(self): m1 = matchmod.alwaysmatcher() - m2 = matchmod.match(b'/repo', b'', include=[b'path:dir/subdir']) + m2 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] + ) um = matchmod.unionmatcher([m1, m2]) self.assertEqual(um.visitchildrenset(b''), b'all') self.assertEqual(um.visitchildrenset(b'dir'), b'all') @@ -648,8 +724,12 @@ # We're using includematcher instead of patterns because it behaves slightly # better (giving narrower results) than patternmatcher. def testVisitdirIncludeInclude(self): - m1 = matchmod.match(b'/repo', b'', include=[b'path:dir/subdir']) - m2 = matchmod.match(b'/repo', b'', include=[b'rootfilesin:dir']) + m1 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] + ) + m2 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'rootfilesin:dir'] + ) um = matchmod.unionmatcher([m1, m2]) self.assertEqual(um.visitdir(b''), True) self.assertEqual(um.visitdir(b'dir'), True) @@ -661,8 +741,12 @@ self.assertEqual(um.visitdir(b'dir/subdir/x'), True) def testVisitchildrensetIncludeInclude(self): - m1 = matchmod.match(b'/repo', b'', include=[b'path:dir/subdir']) - m2 = matchmod.match(b'/repo', b'', include=[b'rootfilesin:dir']) + m1 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] + ) + m2 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'rootfilesin:dir'] + ) um = matchmod.unionmatcher([m1, m2]) self.assertEqual(um.visitchildrenset(b''), {b'dir'}) self.assertEqual(um.visitchildrenset(b'dir'), b'this') @@ -676,8 +760,12 @@ # We're using includematcher instead of patterns because it behaves slightly # better (giving narrower results) than patternmatcher. def testVisitdirIncludeInclude2(self): - m1 = matchmod.match(b'/repo', b'', include=[b'path:dir/subdir']) - m2 = matchmod.match(b'/repo', b'', include=[b'path:folder']) + m1 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] + ) + m2 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:folder'] + ) um = matchmod.unionmatcher([m1, m2]) self.assertEqual(um.visitdir(b''), True) self.assertEqual(um.visitdir(b'dir'), True) @@ -689,8 +777,12 @@ self.assertEqual(um.visitdir(b'dir/subdir/x'), True) def testVisitchildrensetIncludeInclude2(self): - m1 = matchmod.match(b'/repo', b'', include=[b'path:dir/subdir']) - m2 = matchmod.match(b'/repo', b'', include=[b'path:folder']) + m1 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] + ) + m2 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:folder'] + ) um = matchmod.unionmatcher([m1, m2]) self.assertEqual(um.visitchildrenset(b''), {b'folder', b'dir'}) self.assertEqual(um.visitchildrenset(b'dir'), {b'subdir'}) @@ -704,8 +796,12 @@ # We're using includematcher instead of patterns because it behaves slightly # better (giving narrower results) than patternmatcher. def testVisitdirIncludeInclude3(self): - m1 = matchmod.match(b'/repo', b'', include=[b'path:dir/subdir/x']) - m2 = matchmod.match(b'/repo', b'', include=[b'path:dir/subdir']) + m1 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:dir/subdir/x'] + ) + m2 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] + ) um = matchmod.unionmatcher([m1, m2]) self.assertEqual(um.visitdir(b''), True) self.assertEqual(um.visitdir(b'dir'), True) @@ -717,8 +813,12 @@ self.assertEqual(um.visitdir(b'dir/subdir/z'), True) def testVisitchildrensetIncludeInclude3(self): - m1 = matchmod.match(b'/repo', b'', include=[b'path:dir/subdir/x']) - m2 = matchmod.match(b'/repo', b'', include=[b'path:dir/subdir']) + m1 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:dir/subdir/x'] + ) + m2 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] + ) um = matchmod.unionmatcher([m1, m2]) self.assertEqual(um.visitchildrenset(b''), {b'dir'}) self.assertEqual(um.visitchildrenset(b'dir'), {b'subdir'}) @@ -732,8 +832,12 @@ # We're using includematcher instead of patterns because it behaves slightly # better (giving narrower results) than patternmatcher. def testVisitdirIncludeInclude4(self): - m1 = matchmod.match(b'/repo', b'', include=[b'path:dir/subdir/x']) - m2 = matchmod.match(b'/repo', b'', include=[b'path:dir/subdir/z']) + m1 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:dir/subdir/x'] + ) + m2 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:dir/subdir/z'] + ) um = matchmod.unionmatcher([m1, m2]) # OPT: these next three could probably be False as well. self.assertEqual(um.visitdir(b''), True) @@ -745,8 +849,12 @@ self.assertEqual(um.visitdir(b'dir/subdir/x'), b'all') def testVisitchildrensetIncludeInclude4(self): - m1 = matchmod.match(b'/repo', b'', include=[b'path:dir/subdir/x']) - m2 = matchmod.match(b'/repo', b'', include=[b'path:dir/subdir/z']) + m1 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:dir/subdir/x'] + ) + m2 = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:dir/subdir/z'] + ) um = matchmod.unionmatcher([m1, m2]) self.assertEqual(um.visitchildrenset(b''), {b'dir'}) self.assertEqual(um.visitchildrenset(b'dir'), {b'subdir'}) @@ -759,7 +867,9 @@ class SubdirMatcherTests(unittest.TestCase): def testVisitdir(self): - m = matchmod.match(b'/repo', b'', include=[b'path:dir/subdir']) + m = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] + ) sm = matchmod.subdirmatcher(b'dir', m) self.assertEqual(sm.visitdir(b''), True) @@ -770,7 +880,9 @@ self.assertFalse(sm.visitdir(b'foo')) def testVisitchildrenset(self): - m = matchmod.match(b'/repo', b'', include=[b'path:dir/subdir']) + m = matchmod.match( + util.localpath(b'/repo'), b'', include=[b'path:dir/subdir'] + ) sm = matchmod.subdirmatcher(b'dir', m) self.assertEqual(sm.visitchildrenset(b''), {b'subdir'})