Mercurial > public > mercurial-scm > hg
comparison mercurial/commands.py @ 6146:e3dd35d3603b
Speed up hg grep by avoiding useless manifest parsing
In the kernel repo (tip = 2b89f7111b96), a "hg grep mpm MAINTAINERS" goes
from ~165s to 0.7s. This could get even a bit faster if we broke out of
the loop after the first match, but I'm not sure how that would interact
with the --follow code.
This is obviously an extreme example, but other cases should also benefit
from this patch.
author | Alexis S. L. Carvalho <alexis@cecm.usp.br> |
---|---|
date | Tue, 19 Feb 2008 19:20:10 -0300 |
parents | 989467e8e3a9 |
children | bc1ba9124799 |
comparison
equal
deleted
inserted
replaced
6145:154f8be6272b | 6146:e3dd35d3603b |
---|---|
1070 follow = opts.get('follow') | 1070 follow = opts.get('follow') |
1071 for st, rev, fns in changeiter: | 1071 for st, rev, fns in changeiter: |
1072 if st == 'window': | 1072 if st == 'window': |
1073 matches.clear() | 1073 matches.clear() |
1074 elif st == 'add': | 1074 elif st == 'add': |
1075 mf = repo.changectx(rev).manifest() | 1075 ctx = repo.changectx(rev) |
1076 matches[rev] = {} | 1076 matches[rev] = {} |
1077 for fn in fns: | 1077 for fn in fns: |
1078 if fn in skip: | 1078 if fn in skip: |
1079 continue | 1079 continue |
1080 try: | 1080 try: |
1081 grepbody(fn, rev, getfile(fn).read(mf[fn])) | 1081 grepbody(fn, rev, getfile(fn).read(ctx.filenode(fn))) |
1082 fstate.setdefault(fn, []) | 1082 fstate.setdefault(fn, []) |
1083 if follow: | 1083 if follow: |
1084 copied = getfile(fn).renamed(mf[fn]) | 1084 copied = getfile(fn).renamed(ctx.filenode(fn)) |
1085 if copied: | 1085 if copied: |
1086 copies.setdefault(rev, {})[fn] = copied[0] | 1086 copies.setdefault(rev, {})[fn] = copied[0] |
1087 except KeyError: | 1087 except revlog.LookupError: |
1088 pass | 1088 pass |
1089 elif st == 'iter': | 1089 elif st == 'iter': |
1090 states = matches[rev].items() | 1090 states = matches[rev].items() |
1091 states.sort() | 1091 states.sort() |
1092 for fn, m in states: | 1092 for fn, m in states: |