changeset 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 e84a8482c6f2
files mercurial/commands.py
diffstat 1 files changed, 7 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Thu May 14 13:20:40 2009 -0500
+++ b/mercurial/commands.py	Thu May 14 13:20:40 2009 -0500
@@ -1154,9 +1154,16 @@
         sep = eol = '\0'
 
     fcache = {}
+    forder = []
     def getfile(fn):
         if fn not in fcache:
+            if len(fcache) > 20:
+                del fcache[forder.pop(0)]
             fcache[fn] = repo.file(fn)
+        else:
+            forder.remove(fn)
+
+        forder.append(fn)
         return fcache[fn]
 
     def matchlines(body):