##// END OF EJS Templates
match: fix the "visitdir" method on "rootfilesin" matchers...
Arseniy Alekseyev -
r52462:b32c3146 stable
parent child Browse files
Show More
@@ -638,7 +638,10 b' class patternmatcher(basematcher):'
638 super(patternmatcher, self).__init__(badfn)
638 super(patternmatcher, self).__init__(badfn)
639 kindpats.sort()
639 kindpats.sort()
640
640
641 roots, dirs, parents = _rootsdirsandparents(kindpats)
641 self._files = _explicitfiles(kindpats)
642 self._files = _explicitfiles(kindpats)
643 self._dirs_explicit = set(dirs)
644 self._dirs = parents
642 self._prefix = _prefix(kindpats)
645 self._prefix = _prefix(kindpats)
643 self._pats, self._matchfn = _buildmatch(kindpats, b'$', root)
646 self._pats, self._matchfn = _buildmatch(kindpats, b'$', root)
644
647
@@ -647,14 +650,14 b' class patternmatcher(basematcher):'
647 return True
650 return True
648 return self._matchfn(fn)
651 return self._matchfn(fn)
649
652
650 @propertycache
651 def _dirs(self):
652 return set(pathutil.dirs(self._fileset))
653
654 def visitdir(self, dir):
653 def visitdir(self, dir):
655 if self._prefix and dir in self._fileset:
654 if self._prefix and dir in self._fileset:
656 return b'all'
655 return b'all'
657 return dir in self._dirs or path_or_parents_in_set(dir, self._fileset)
656 return (
657 dir in self._dirs
658 or path_or_parents_in_set(dir, self._fileset)
659 or path_or_parents_in_set(dir, self._dirs_explicit)
660 )
658
661
659 def visitchildrenset(self, dir):
662 def visitchildrenset(self, dir):
660 ret = self.visitdir(dir)
663 ret = self.visitdir(dir)
@@ -1461,7 +1464,7 b' def _buildregexmatch(kindpats, globsuffi'
1461 allgroups = []
1464 allgroups = []
1462 regexps = []
1465 regexps = []
1463 exact = set()
1466 exact = set()
1464 for (kind, pattern, _source) in kindpats:
1467 for kind, pattern, _source in kindpats:
1465 if kind == b'filepath':
1468 if kind == b'filepath':
1466 exact.add(pattern)
1469 exact.add(pattern)
1467 continue
1470 continue
@@ -94,12 +94,14 b' class PatternMatcherTests(unittest.TestC'
94 patterns=[b'rootfilesin:dir/subdir'],
94 patterns=[b'rootfilesin:dir/subdir'],
95 )
95 )
96 assert isinstance(m, matchmod.patternmatcher)
96 assert isinstance(m, matchmod.patternmatcher)
97 self.assertFalse(m.visitdir(b'dir/subdir/x'))
97 # OPT: we shouldn't visit [x] as a directory,
98 # but we should still visit it as a file.
99 # Unfortunately, `visitdir` is used for both.
100 self.assertTrue(m.visitdir(b'dir/subdir/x'))
98 self.assertFalse(m.visitdir(b'folder'))
101 self.assertFalse(m.visitdir(b'folder'))
99 # FIXME: These should probably be True.
102 self.assertTrue(m.visitdir(b''))
100 self.assertFalse(m.visitdir(b''))
103 self.assertTrue(m.visitdir(b'dir'))
101 self.assertFalse(m.visitdir(b'dir'))
104 self.assertTrue(m.visitdir(b'dir/subdir'))
102 self.assertFalse(m.visitdir(b'dir/subdir'))
103
105
104 def testVisitchildrensetRootfilesin(self):
106 def testVisitchildrensetRootfilesin(self):
105 m = matchmod.match(
107 m = matchmod.match(
@@ -108,13 +110,13 b' class PatternMatcherTests(unittest.TestC'
108 patterns=[b'rootfilesin:dir/subdir'],
110 patterns=[b'rootfilesin:dir/subdir'],
109 )
111 )
110 assert isinstance(m, matchmod.patternmatcher)
112 assert isinstance(m, matchmod.patternmatcher)
111 self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), set())
113 self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), b'this')
112 self.assertEqual(m.visitchildrenset(b'folder'), set())
114 self.assertEqual(m.visitchildrenset(b'folder'), set())
113 # FIXME: These should probably be {'dir'}, {'subdir'} and 'this',
115 # OPT: These should probably be {'dir'}, {'subdir'} and 'this',
114 # respectively, or at least 'this' for all three.
116 # respectively
115 self.assertEqual(m.visitchildrenset(b''), set())
117 self.assertEqual(m.visitchildrenset(b''), b'this')
116 self.assertEqual(m.visitchildrenset(b'dir'), set())
118 self.assertEqual(m.visitchildrenset(b'dir'), b'this')
117 self.assertEqual(m.visitchildrenset(b'dir/subdir'), set())
119 self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'this')
118
120
119 def testVisitdirGlob(self):
121 def testVisitdirGlob(self):
120 m = matchmod.match(
122 m = matchmod.match(
@@ -863,6 +863,7 b" in rhg it's empty, in Python it's missin"
863 M subdir/modified (no-rhg !)
863 M subdir/modified (no-rhg !)
864 R subdir/removed (no-rhg !)
864 R subdir/removed (no-rhg !)
865 ! subdir/deleted (no-rhg !)
865 ! subdir/deleted (no-rhg !)
866 ? subdir/unknown (no-rhg !)
866
867
867 Note: `hg status some-name` creates a patternmatcher which is not supported
868 Note: `hg status some-name` creates a patternmatcher which is not supported
868 yet by the Rust implementation of status, but includematcher is supported.
869 yet by the Rust implementation of status, but includematcher is supported.
General Comments 0
You need to be logged in to leave comments. Login now