grep: reuse getrenamedfn() from scmutil
authorMartin von Zweigbergk <martinvonz@google.com>
Fri, 18 Jan 2019 11:07:46 -0800
changeset 41782 cecdf7418cf1
parent 41781 e9b9ee9af4a9
child 41783 7b04b1154c15
grep: reuse getrenamedfn() from scmutil My motivation is to reduce uses of filectx.renamed(). Reusing scmutil.getrenamedfn() also means that we get some caching of copy information per file and revision. I don't think that matters for `hg grep` (I doubt it speeds up significantly, and I doubt it wastes significant memory), but I'm not sure. Differential Revision: https://phab.mercurial-scm.org/D6022
mercurial/commands.py
--- a/mercurial/commands.py	Thu Feb 21 10:54:29 2019 -0800
+++ b/mercurial/commands.py	Fri Jan 18 11:07:46 2019 -0800
@@ -2940,6 +2940,7 @@
     found = False
     follow = opts.get('follow')
 
+    getrenamed = scmutil.getrenamedfn(repo)
     def prep(ctx, fns):
         rev = ctx.rev()
         pctx = ctx.p1()
@@ -2953,13 +2954,10 @@
                 fnode = ctx.filenode(fn)
             except error.LookupError:
                 continue
+
             copy = None
             if follow:
-                try:
-                    copied = flog.renamed(fnode)
-                except error.WdirUnsupported:
-                    copied = ctx[fn].renamed()
-                copy = copied and copied[0]
+                copy = getrenamed(fn, rev)
                 if copy:
                     copies.setdefault(rev, {})[fn] = copy
                     if fn in skip: