Make patch.diff filelog cache LRU of 20 files. Fixes issue1738.
authorBrendan Cully <brendan@kublai.com>
Tue, 14 Jul 2009 16:50:37 -0700
changeset 9123 360f61c2919f
parent 9122 a9eae2f3241c
child 9124 632df73485ae
child 9125 8b58f53b9c35
child 9139 6d1f9238824e
Make patch.diff filelog cache LRU of 20 files. Fixes issue1738. 20 files is as fast as 200 for hg diff -r 28015:30103 of mozilla-central. Ideally we'd use util.lrucachefunc, but the interface doesn't quite work.
mercurial/patch.py
--- a/mercurial/patch.py	Tue Jul 14 17:12:12 2009 -0300
+++ b/mercurial/patch.py	Tue Jul 14 16:50:37 2009 -0700
@@ -1246,12 +1246,21 @@
     if not node1:
         node1 = repo.dirstate.parents()[0]
 
-    flcache = {}
-    def getfilectx(f, ctx):
-        flctx = ctx.filectx(f, filelog=flcache.get(f))
-        if f not in flcache:
-            flcache[f] = flctx._filelog
-        return flctx
+    def lrugetfilectx():
+        cache = {}
+        order = []
+        def getfilectx(f, ctx):
+            fctx = ctx.filectx(f, filelog=cache.get(f))
+            if f not in cache:
+                if len(cache) > 20:
+                    del cache[order.pop(0)]
+                cache[f] = fctx._filelog
+            else:
+                order.remove(f)
+            order.append(f)
+            return fctx
+        return getfilectx
+    getfilectx = lrugetfilectx()
 
     ctx1 = repo[node1]
     ctx2 = repo[node2]