[PATCH 4 of 6] revlog: move chunk cache preload from revision to _chunks

Siddharth Agarwal sid0 at fb.com
Sat Sep 7 15:40:38 CDT 2013


# HG changeset patch
# User Siddharth Agarwal <sid0 at fb.com>
# Date 1378533911 25200
#      Fri Sep 06 23:05:11 2013 -0700
# Node ID 59e9548119a2921c1c4c96dff96cd303eb19fd77
# Parent  8c9c2c14cdfb0dd708c5f2fdd793035b1f6c8466
revlog: move chunk cache preload from revision to _chunks

In case we don't have a cached text already, add the base rev to the list
passed to _chunks. In the cached case this also avoids unnecessarily preloading
the chunk for the cached rev.

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -859,6 +859,8 @@
         '''faster version of [self._chunk(rev) for rev in revs]
 
         Assumes that revs is in ascending order.'''
+        if not revs:
+            return []
         start = self.start
         length = self.length
         inline = self._inline
@@ -868,7 +870,8 @@
         l = []
         ladd = l.append
 
-        # XXX assume for now that chunkcache is preloaded
+        # preload the cache
+        self._chunkraw(revs[0], revs[-1])
         offset, data = self._chunkcache
 
         for rev in revs:
@@ -946,21 +949,22 @@
             else:
                 iterrev -= 1
             e = index[iterrev]
-        chain.reverse()
-        base = iterrev
 
         if iterrev == cachedrev:
             # cache hit
             text = self._cache[2]
+        else:
+            chain.append(iterrev)
+        chain.reverse()
 
         # drop cache to save memory
         self._cache = None
 
-        self._chunkraw(base, rev)
+        bins = self._chunks(chain)
         if text is None:
-            text = str(self._chunkbase(base))
+            text = str(bins[0])
+            bins = bins[1:]
 
-        bins = self._chunks(chain)
         text = mdiff.patches(text, bins)
 
         text = self._checkhash(text, node, rev)


More information about the Mercurial-devel mailing list