Patchwork D7820: grep: speed up `hg grep --all-files some/path` by using ctx.matches(match)

login
register
mail settings
Submitter phabricator
Date Jan. 10, 2020, 6:42 p.m.
Message ID <differential-rev-PHID-DREV-vwlc5fw7pvedaqpihgzm-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/44246/
State Superseded
Headers show

Comments

phabricator - Jan. 10, 2020, 6:42 p.m.
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  ctx.matches(match) avoids walking unintersting parts of the tree when
  using tree manifests. That can make a very big difference when
  grepping in a small subset of the tree (2.0s -> 0.7s in my case, but
  can of course be made more extreme by picking a smaller subset of
  files).

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D7820

AFFECTED FILES
  mercurial/cmdutil.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2429,12 +2429,16 @@ 
 
                     def fns_generator():
                         if allfiles:
-                            fiter = iter(ctx)
+
+                            def bad(f, msg):
+                                pass
+
+                            for f in ctx.matches(matchmod.badmatch(match, bad)):
+                                yield f
                         else:
-                            fiter = ctx.files()
-                        for f in fiter:
-                            if match(f):
-                                yield f
+                            for f in ctx.files():
+                                if match(f):
+                                    yield f
 
                     fns = fns_generator()
                 prepare(ctx, fns)