context: extend efficient manifest filtering to when all paths are files
authorSiddharth Agarwal <sid0@fb.com>
Wed, 16 Jul 2014 14:53:03 -0700
changeset 21895 5809d62e7106
parent 21894 1000348b3aea
child 21896 2b41ee1b5ea1
context: extend efficient manifest filtering to when all paths are files On a repository with over 250,000 files and 700,000 commits, this improves cases like hg status --rev <rev> -- <file> # rev is not . from 2.1 seconds to 1.4 seconds. There is further scope for improvement here: for a single file or a small set of files, it is probably more efficient to use filelog linkrevs when possible. However there will always be cases where that will fail (multiple commits pointing to the same file revision, removed files...), so this is independently useful.
mercurial/context.py
--- a/mercurial/context.py	Sat Jul 12 00:37:08 2014 -0700
+++ b/mercurial/context.py	Wed Jul 16 14:53:03 2014 -0700
@@ -74,8 +74,10 @@
         if match.always():
             return self.manifest().copy()
 
-        if match.matchfn == match.exact:
-            return self.manifest().intersectfiles(match.files())
+        files = match.files()
+        if (match.matchfn == match.exact or
+            (not match.anypats() and util.all(fn in self for fn in files))):
+            return self.manifest().intersectfiles(files)
 
         mf = self.manifest().copy()
         for fn in mf.keys():