Show More
@@ -1155,6 +1155,22 b' class treemanifest(object):' | |||||
1155 | subp1, subp2 = subp2, subp1 |
|
1155 | subp1, subp2 = subp2, subp1 | |
1156 | writesubtree(subm, subp1, subp2) |
|
1156 | writesubtree(subm, subp1, subp2) | |
1157 |
|
1157 | |||
|
1158 | def walksubtrees(self, matcher=None): | |||
|
1159 | """Returns an iterator of the subtrees of this manifest, including this | |||
|
1160 | manifest itself. | |||
|
1161 | ||||
|
1162 | If `matcher` is provided, it only returns subtrees that match. | |||
|
1163 | """ | |||
|
1164 | if matcher and not matcher.visitdir(self._dir[:-1] or '.'): | |||
|
1165 | return | |||
|
1166 | if not matcher or matcher(self._dir[:-1]): | |||
|
1167 | yield self | |||
|
1168 | ||||
|
1169 | self._load() | |||
|
1170 | for d, subm in self._dirs.iteritems(): | |||
|
1171 | for subtree in subm.walksubtrees(matcher=matcher): | |||
|
1172 | yield subtree | |||
|
1173 | ||||
1158 | class manifestrevlog(revlog.revlog): |
|
1174 | class manifestrevlog(revlog.revlog): | |
1159 | '''A revlog that stores manifest texts. This is responsible for caching the |
|
1175 | '''A revlog that stores manifest texts. This is responsible for caching the | |
1160 | full-text manifest contents. |
|
1176 | full-text manifest contents. |
@@ -467,5 +467,21 b' class testtreemanifest(unittest.TestCase' | |||||
467 | def parsemanifest(self, text): |
|
467 | def parsemanifest(self, text): | |
468 | return manifestmod.treemanifest('', text) |
|
468 | return manifestmod.treemanifest('', text) | |
469 |
|
469 | |||
|
470 | def testWalkSubtrees(self): | |||
|
471 | m = self.parsemanifest(A_DEEPER_MANIFEST) | |||
|
472 | ||||
|
473 | dirs = [s._dir for s in m.walksubtrees()] | |||
|
474 | self.assertEqual( | |||
|
475 | sorted(['', 'a/', 'a/c/', 'a/d/', 'a/b/', 'a/b/c/', 'a/b/d/']), | |||
|
476 | sorted(dirs) | |||
|
477 | ) | |||
|
478 | ||||
|
479 | match = matchmod.match('/', '', ['path:a/b/']) | |||
|
480 | dirs = [s._dir for s in m.walksubtrees(matcher=match)] | |||
|
481 | self.assertEqual( | |||
|
482 | sorted(['a/b/', 'a/b/c/', 'a/b/d/']), | |||
|
483 | sorted(dirs) | |||
|
484 | ) | |||
|
485 | ||||
470 | if __name__ == '__main__': |
|
486 | if __name__ == '__main__': | |
471 | silenttestrunner.main(__name__) |
|
487 | silenttestrunner.main(__name__) |
General Comments 0
You need to be logged in to leave comments.
Login now