changeset 24685:b3d78d82d84c

manifestdict: extract condition for _intersectfiles() and use for walk() The condition on which manifestdict.matches() and manifestdict.walk() take the fast path of iterating over files instead of the manifest, is slightly different. Specifically, walk() does not take the fast path for exact matchers and it does not avoid taking the fast path when there are more than 100 files. Let's extract the condition so we don't have to maintain it in two places and so walk() can gain these two missing pieces of the condition (although there seems to be no current caller of walk() with an exact matcher).
author Martin von Zweigbergk <martinvonz@google.com>
date Wed, 08 Apr 2015 09:38:09 -0700
parents ff7badaf3158
children e0e28e910fa3
files mercurial/manifest.py
diffstat 1 files changed, 9 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/manifest.py	Tue Apr 07 22:40:25 2015 -0700
+++ b/mercurial/manifest.py	Wed Apr 08 09:38:09 2015 -0700
@@ -214,6 +214,13 @@
     def hasdir(self, dir):
         return dir in self._dirs
 
+    def _filesfastpath(self, match):
+        '''Checks whether we can correctly and quickly iterate over matcher
+        files instead of over manifest files.'''
+        files = match.files()
+        return (len(files) < 100 and (match.isexact() or
+            (not match.anypats() and util.all(fn in self for fn in files))))
+
     def walk(self, match):
         '''Generates matching file names.
 
@@ -230,7 +237,7 @@
         fset = set(match.files())
 
         # avoid the entire walk if we're only looking for specific files
-        if not match.anypats() and util.all(fn in self for fn in fset):
+        if self._filesfastpath(match):
             for fn in sorted(fset):
                 yield fn
             return
@@ -255,9 +262,7 @@
         if match.always():
             return self.copy()
 
-        files = match.files()
-        if (len(files) < 100 and (match.isexact() or
-            (not match.anypats() and util.all(fn in self for fn in files)))):
+        if self._filesfastpath(match):
             m = manifestdict()
             lm = self._lm
             for fn in match.files():