manifestdict: extract condition for _intersectfiles() and use for walk()
authorMartin von Zweigbergk <martinvonz@google.com>
Wed, 08 Apr 2015 09:38:09 -0700
changeset 24685 b3d78d82d84c
parent 24684 ff7badaf3158
child 24686 e0e28e910fa3
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).
mercurial/manifest.py
--- 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():