Mercurial > public > mercurial-scm > hg
comparison mercurial/commands.py @ 41782:cecdf7418cf1
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
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Fri, 18 Jan 2019 11:07:46 -0800 |
parents | e9b9ee9af4a9 |
children | 2a3c0106ded9 |
comparison
equal
deleted
inserted
replaced
41781:e9b9ee9af4a9 | 41782:cecdf7418cf1 |
---|---|
2938 revfiles = {} | 2938 revfiles = {} |
2939 match = scmutil.match(repo[None], pats, opts) | 2939 match = scmutil.match(repo[None], pats, opts) |
2940 found = False | 2940 found = False |
2941 follow = opts.get('follow') | 2941 follow = opts.get('follow') |
2942 | 2942 |
2943 getrenamed = scmutil.getrenamedfn(repo) | |
2943 def prep(ctx, fns): | 2944 def prep(ctx, fns): |
2944 rev = ctx.rev() | 2945 rev = ctx.rev() |
2945 pctx = ctx.p1() | 2946 pctx = ctx.p1() |
2946 parent = pctx.rev() | 2947 parent = pctx.rev() |
2947 matches.setdefault(rev, {}) | 2948 matches.setdefault(rev, {}) |
2951 flog = getfile(fn) | 2952 flog = getfile(fn) |
2952 try: | 2953 try: |
2953 fnode = ctx.filenode(fn) | 2954 fnode = ctx.filenode(fn) |
2954 except error.LookupError: | 2955 except error.LookupError: |
2955 continue | 2956 continue |
2957 | |
2956 copy = None | 2958 copy = None |
2957 if follow: | 2959 if follow: |
2958 try: | 2960 copy = getrenamed(fn, rev) |
2959 copied = flog.renamed(fnode) | |
2960 except error.WdirUnsupported: | |
2961 copied = ctx[fn].renamed() | |
2962 copy = copied and copied[0] | |
2963 if copy: | 2961 if copy: |
2964 copies.setdefault(rev, {})[fn] = copy | 2962 copies.setdefault(rev, {})[fn] = copy |
2965 if fn in skip: | 2963 if fn in skip: |
2966 skip.add(copy) | 2964 skip.add(copy) |
2967 if fn in skip: | 2965 if fn in skip: |