Patchwork D8544: grep: stop computing information for --diff when unnecessary

login
register
mail settings
Submitter phabricator
Date May 17, 2020, 5:50 p.m.
Message ID <differential-rev-PHID-DREV-p54m5nk66hw3cid6566f-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/46332/
State Superseded
Headers show

Comments

phabricator - May 17, 2020, 5:50 p.m.
valentin.gatienbaron created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This is one reason why `hg grep pattern` essentially does `hg cat -r
  . 'set:**'` inside. There is no speed improvement in this commit,
  because the rest of the code still greps data from filelog instead of
  working copy when possible.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/commands.py

CHANGE DETAILS




To: valentin.gatienbaron, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -3594,9 +3594,10 @@ 
     def prep(ctx, fns):
         rev = ctx.rev()
         pctx = ctx.p1()
-        parent = pctx.rev()
         matches.setdefault(rev, {})
-        matches.setdefault(parent, {})
+        if diff:
+            parent = pctx.rev()
+            matches.setdefault(parent, {})
         files = revfiles.setdefault(rev, [])
         for fn in fns:
             flog = getfile(fn)
@@ -3620,14 +3621,17 @@ 
                 content = get_file_content(fn, flog, fnode, ctx, rev)
                 grepbody(fn, rev, content)
 
-            pfn = copy or fn
-            if pfn not in matches[parent]:
-                try:
-                    pfnode = pctx.filenode(pfn)
-                    pcontent = get_file_content(pfn, flog, pfnode, pctx, parent)
-                    grepbody(pfn, parent, pcontent)
-                except error.LookupError:
-                    pass
+            if diff:
+                pfn = copy or fn
+                if pfn not in matches[parent]:
+                    try:
+                        pfnode = pctx.filenode(pfn)
+                        pcontent = get_file_content(
+                            pfn, flog, pfnode, pctx, parent
+                        )
+                        grepbody(pfn, parent, pcontent)
+                    except error.LookupError:
+                        pass
 
     ui.pager(b'grep')
     fm = ui.formatter(b'grep', opts)