##// END OF EJS Templates
match: make exactmatcher.visitchildrenset return file children as well...
Kyle Lippincott -
r39297:c9a3f7f5 default
parent child Browse files
Show More
@@ -587,23 +587,24 b' class exactmatcher(basematcher):'
587 return dir in self._dirs
587 return dir in self._dirs
588
588
589 def visitchildrenset(self, dir):
589 def visitchildrenset(self, dir):
590 if dir in self._dirs:
590 if not self._fileset or dir not in self._dirs:
591 candidates = self._dirs - {'.'}
591 return set()
592 if dir != '.':
592
593 d = dir + '/'
593 candidates = self._fileset | self._dirs - {'.'}
594 candidates = set(c[len(d):] for c in candidates if
594 if dir != '.':
595 c.startswith(d))
595 d = dir + '/'
596 # self._dirs includes all of the directories, recursively, so if
596 candidates = set(c[len(d):] for c in candidates if
597 # we're attempting to match foo/bar/baz.txt, it'll have '.', 'foo',
597 c.startswith(d))
598 # 'foo/bar' in it. Thus we can safely ignore a candidate that has a
598 # self._dirs includes all of the directories, recursively, so if
599 # '/' in it, indicating a it's for a subdir-of-a-subdir; the
599 # we're attempting to match foo/bar/baz.txt, it'll have '.', 'foo',
600 # immediate subdir will be in there without a slash.
600 # 'foo/bar' in it. Thus we can safely ignore a candidate that has a
601 ret = set(c for c in candidates if '/' not in c)
601 # '/' in it, indicating a it's for a subdir-of-a-subdir; the
602 # We need to emit 'this' for foo/bar, not set(), not {'baz.txt'}.
602 # immediate subdir will be in there without a slash.
603 if not ret:
603 ret = {c for c in candidates if '/' not in c}
604 return 'this'
604 # We really do not expect ret to be empty, since that would imply that
605 return ret
605 # there's something in _dirs that didn't have a file in _fileset.
606 return set()
606 assert ret
607 return ret
607
608
608 def isexact(self):
609 def isexact(self):
609 return True
610 return True
@@ -202,11 +202,27 b' class ExactMatcherTests(unittest.TestCas'
202 assert isinstance(m, matchmod.exactmatcher)
202 assert isinstance(m, matchmod.exactmatcher)
203 self.assertEqual(m.visitchildrenset(b'.'), {b'dir'})
203 self.assertEqual(m.visitchildrenset(b'.'), {b'dir'})
204 self.assertEqual(m.visitchildrenset(b'dir'), {b'subdir'})
204 self.assertEqual(m.visitchildrenset(b'dir'), {b'subdir'})
205 self.assertEqual(m.visitchildrenset(b'dir/subdir'), b'this')
205 self.assertEqual(m.visitchildrenset(b'dir/subdir'), {b'foo.txt'})
206 self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), set())
206 self.assertEqual(m.visitchildrenset(b'dir/subdir/x'), set())
207 self.assertEqual(m.visitchildrenset(b'dir/subdir/foo.txt'), set())
207 self.assertEqual(m.visitchildrenset(b'dir/subdir/foo.txt'), set())
208 self.assertEqual(m.visitchildrenset(b'folder'), set())
208 self.assertEqual(m.visitchildrenset(b'folder'), set())
209
209
210 def testVisitchildrensetFilesAndDirs(self):
211 m = matchmod.match(b'x', b'', patterns=[b'rootfile.txt',
212 b'a/file1.txt',
213 b'a/b/file2.txt',
214 # no file in a/b/c
215 b'a/b/c/d/file4.txt'],
216 exact=True)
217 assert isinstance(m, matchmod.exactmatcher)
218 self.assertEqual(m.visitchildrenset(b'.'), {b'a', b'rootfile.txt'})
219 self.assertEqual(m.visitchildrenset(b'a'), {b'b', b'file1.txt'})
220 self.assertEqual(m.visitchildrenset(b'a/b'), {b'c', b'file2.txt'})
221 self.assertEqual(m.visitchildrenset(b'a/b/c'), {b'd'})
222 self.assertEqual(m.visitchildrenset(b'a/b/c/d'), {b'file4.txt'})
223 self.assertEqual(m.visitchildrenset(b'a/b/c/d/e'), set())
224 self.assertEqual(m.visitchildrenset(b'folder'), set())
225
210 class DifferenceMatcherTests(unittest.TestCase):
226 class DifferenceMatcherTests(unittest.TestCase):
211
227
212 def testVisitdirM2always(self):
228 def testVisitdirM2always(self):
General Comments 0
You need to be logged in to leave comments. Login now