Patchwork [4,of,4] manifestdict: extract condition for _intersectfiles() and use for walk()

login
register
mail settings
Submitter Martin von Zweigbergk
Date April 9, 2015, 8:31 p.m.
Message ID <9dfc00bd3ee967ae2530.1428611515@martinvonz.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/8583/
State Accepted
Headers show

Comments

Martin von Zweigbergk - April 9, 2015, 8:31 p.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1428511089 25200
#      Wed Apr 08 09:38:09 2015 -0700
# Node ID 9dfc00bd3ee967ae25302f1b78654374aaeb3e77
# Parent  b2aa870b2de74190ba04146c91faebbf693969ca
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).
Matt Mackall - April 9, 2015, 8:51 p.m.
On Thu, 2015-04-09 at 13:31 -0700, Martin von Zweigbergk wrote:
> # HG changeset patch
> # User Martin von Zweigbergk <martinvonz@google.com>
> # Date 1428511089 25200
> #      Wed Apr 08 09:38:09 2015 -0700
> # Node ID 9dfc00bd3ee967ae25302f1b78654374aaeb3e77
> # Parent  b2aa870b2de74190ba04146c91faebbf693969ca
> manifestdict: extract condition for _intersectfiles() and use for walk()

These are queued for default, thanks.

Patch

diff -r b2aa870b2de7 -r 9dfc00bd3ee9 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():