[PATCH] revset: use manifest.matches in _follow revset

Durham Goode durham at fb.com
Fri Feb 5 20:47:28 UTC 2016


# HG changeset patch
# User Durham Goode <durham at fb.com>
# Date 1454705079 28800
#      Fri Feb 05 12:44:39 2016 -0800
# Node ID 4bf06bc950fcbee8fc65cd3fd17d366a27603ad9
# Parent  01a5143cd25f285f8c745a92986cd7186bb32c90
revset: use manifest.matches in _follow revset

The old _follow revset iterated over every file in the commit and checked if it
matched. For repos with large manifests, this could take 500ms. By switching to
use manifest.matches() we can take advantage of the fastpaths built in to
manifest.py that allows iterating over only the files in the matcher when it's a
simple matcher. This brings the time spent down from 500ms to 0ms during simple
operations like 'hg log -f file.txt'.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -1086,13 +1086,14 @@ def _follow(repo, subset, x, name, follo
         matcher = matchmod.match(repo.root, repo.getcwd(), [x],
                                  ctx=repo[None], default='path')
 
+        files = c.manifest().matches(matcher)
+
         s = set()
-        for fname in c:
-            if matcher(fname):
-                fctx = c[fname]
-                s = s.union(set(c.rev() for c in fctx.ancestors(followfirst)))
-                # include the revision responsible for the most recent version
-                s.add(fctx.introrev())
+        for fname in files:
+            fctx = c[fname]
+            s = s.union(set(c.rev() for c in fctx.ancestors(followfirst)))
+            # include the revision responsible for the most recent version
+            s.add(fctx.introrev())
     else:
         s = _revancestors(repo, baseset([c.rev()]), followfirst)
 


More information about the Mercurial-devel mailing list