Mercurial > public > mercurial-scm > hg
comparison mercurial/commands.py @ 8408:72538f1909ec
grep: make cache LRU rather than unlimited
grep could cache an unbounded number of revlogs, limit to 20 with an
LRU cache.
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Thu, 14 May 2009 13:20:40 -0500 |
parents | 223000a687b0 |
children | 7af92e70bb25 |
comparison
equal
deleted
inserted
replaced
8407:223000a687b0 | 8408:72538f1909ec |
---|---|
1152 sep, eol = ':', '\n' | 1152 sep, eol = ':', '\n' |
1153 if opts.get('print0'): | 1153 if opts.get('print0'): |
1154 sep = eol = '\0' | 1154 sep = eol = '\0' |
1155 | 1155 |
1156 fcache = {} | 1156 fcache = {} |
1157 forder = [] | |
1157 def getfile(fn): | 1158 def getfile(fn): |
1158 if fn not in fcache: | 1159 if fn not in fcache: |
1160 if len(fcache) > 20: | |
1161 del fcache[forder.pop(0)] | |
1159 fcache[fn] = repo.file(fn) | 1162 fcache[fn] = repo.file(fn) |
1163 else: | |
1164 forder.remove(fn) | |
1165 | |
1166 forder.append(fn) | |
1160 return fcache[fn] | 1167 return fcache[fn] |
1161 | 1168 |
1162 def matchlines(body): | 1169 def matchlines(body): |
1163 begin = 0 | 1170 begin = 0 |
1164 linenum = 0 | 1171 linenum = 0 |