grep: make cache LRU rather than unlimited
authorMatt Mackall <mpm@selenic.com>
Thu, 14 May 2009 13:20:40 -0500
changeset 8408 72538f1909ec
parent 8407 223000a687b0
child 8409 e84a8482c6f2
grep: make cache LRU rather than unlimited grep could cache an unbounded number of revlogs, limit to 20 with an LRU cache.
mercurial/commands.py
--- 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):