# HG changeset patch # User Alexis S. L. Carvalho # Date 1203459610 10800 # Node ID e3dd35d3603bf9aaabb8cd80707e5592b3544069 # Parent 154f8be6272ba077153d728319775fc179be1fd2 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. diff -r 154f8be6272b -r e3dd35d3603b mercurial/commands.py --- a/mercurial/commands.py Tue Feb 19 19:20:10 2008 -0300 +++ b/mercurial/commands.py Tue Feb 19 19:20:10 2008 -0300 @@ -1072,19 +1072,19 @@ if st == 'window': matches.clear() elif st == 'add': - mf = repo.changectx(rev).manifest() + ctx = repo.changectx(rev) matches[rev] = {} for fn in fns: if fn in skip: continue try: - grepbody(fn, rev, getfile(fn).read(mf[fn])) + grepbody(fn, rev, getfile(fn).read(ctx.filenode(fn))) fstate.setdefault(fn, []) if follow: - copied = getfile(fn).renamed(mf[fn]) + copied = getfile(fn).renamed(ctx.filenode(fn)) if copied: copies.setdefault(rev, {})[fn] = copied[0] - except KeyError: + except revlog.LookupError: pass elif st == 'iter': states = matches[rev].items()