treemanifest: refactor treemanifest.walk()
authorDrew Gottlieb <drgott@google.com>
Tue, 07 Apr 2015 15:18:52 -0700
changeset 24647 fb446c57f8f9
parent 24646 5693c834bcb4
child 24648 5cac3accdaa1
treemanifest: refactor treemanifest.walk() This refactor is a preparation for an optimization in the next commit. This introduces a recursive element that recurses each submanifest. By using a recursive function, the next commit can avoid walking over some subdirectories altogether.
mercurial/manifest.py
--- a/mercurial/manifest.py	Tue Apr 07 15:18:52 2015 -0700
+++ b/mercurial/manifest.py	Tue Apr 07 15:18:52 2015 -0700
@@ -623,12 +623,11 @@
                     yield fn
                 raise StopIteration
 
-        for fn in self:
+        for fn in self._walk(match):
             if fn in fset:
                 # specified pattern is the exact name
                 fset.remove(fn)
-            if match(fn):
-                yield fn
+            yield fn
 
         # for dirstate.walk, files=['.'] means "walk the whole tree".
         # follow that here, too
@@ -638,6 +637,19 @@
             if not self.hasdir(fn):
                 match.bad(fn, None)
 
+    def _walk(self, match):
+        '''Recursively generates matching file names for walk().'''
+
+        # yield this dir's files and walk its submanifests
+        for p in sorted(self._dirs.keys() + self._files.keys()):
+            if p in self._files:
+                fullp = self._subpath(p)
+                if match(fullp):
+                    yield fullp
+            else:
+                for f in self._dirs[p]._walk(match):
+                    yield f
+
     def matches(self, match):
         '''generate a new manifest filtered by the match argument'''
         if match.always():