diff tests/test-manifest.py @ 31876:94c1d3c1aea2

treemanifest: add walksubtrees api Adds a new function to treemanifest that allows walking over the directories in the tree. Currently it only accepts a matcher to prune the walk, but in the future it will also accept a list of trees and will only walk over subtrees that differ from the versions in the list. This will be useful for identifying what parts of the tree are new to this revision, which is useful when deciding the minimal set of trees to send to a client given that they have a certain tree already. Since this is intended for an extension to use, the only current consumer is a test. In the future this function may be useful for implementing other algorithms like diff and changegroup generation.
author Durham Goode <durham@fb.com>
date Mon, 10 Apr 2017 13:07:47 -0700
parents 959ebff3505a
children 68c43a416585
line wrap: on
line diff
--- a/tests/test-manifest.py	Tue Apr 11 23:12:14 2017 +0900
+++ b/tests/test-manifest.py	Mon Apr 10 13:07:47 2017 -0700
@@ -467,5 +467,21 @@
     def parsemanifest(self, text):
         return manifestmod.treemanifest('', text)
 
+    def testWalkSubtrees(self):
+        m = self.parsemanifest(A_DEEPER_MANIFEST)
+
+        dirs = [s._dir for s in m.walksubtrees()]
+        self.assertEqual(
+            sorted(['', 'a/', 'a/c/', 'a/d/', 'a/b/', 'a/b/c/', 'a/b/d/']),
+            sorted(dirs)
+        )
+
+        match = matchmod.match('/', '', ['path:a/b/'])
+        dirs = [s._dir for s in m.walksubtrees(matcher=match)]
+        self.assertEqual(
+            sorted(['a/b/', 'a/b/c/', 'a/b/d/']),
+            sorted(dirs)
+        )
+
 if __name__ == '__main__':
     silenttestrunner.main(__name__)