# HG changeset patch # User Sune Foldager # Date 1305200837 -7200 # Node ID 62e25c63fb3a9044e6041ce480a3bb0c3e8a3c57 # Parent bb7e3b3e6e1109249cb9e185da69e517ff3996dc revlog: fix bug in chainbase cache The bug didn't cause corruption, and thus wasn't caught in hg verify or in tests. It could lead to delta chains longer than normally allowed, by affecting the code that decides when to add a full revision. This could, in turn, lead to performance regression. diff -r bb7e3b3e6e11 -r 62e25c63fb3a mercurial/revlog.py --- a/mercurial/revlog.py Mon May 09 15:16:56 2011 -0400 +++ b/mercurial/revlog.py Thu May 12 13:47:17 2011 +0200 @@ -218,7 +218,7 @@ self.datafile = indexfile[:-2] + ".d" self.opener = opener self._cache = None - self._basecache = None + self._basecache = (0, 0) self._chunkcache = (0, '') self.index = [] self._pcache = {} @@ -1010,8 +1010,7 @@ delta = mdiff.textdiff(ptext, t) data = compress(delta) l = len(data[1]) + len(data[0]) - basecache = self._basecache - if basecache and basecache[0] == rev: + if basecache[0] == rev: chainbase = basecache[1] else: chainbase = self.chainbase(rev) @@ -1020,14 +1019,15 @@ base = rev else: base = chainbase - return dist, l, data, base + return dist, l, data, base, chainbase curr = len(self) prev = curr - 1 - base = curr + base = chainbase = curr offset = self.end(prev) flags = 0 d = None + basecache = self._basecache p1r, p2r = self.rev(p1), self.rev(p2) # should we try to build a delta? @@ -1036,7 +1036,7 @@ d = builddelta(p1r) else: d = builddelta(prev) - dist, l, data, base = d + dist, l, data, base, chainbase = d # full versions are inserted when the needed deltas # become comparable to the uncompressed text @@ -1049,7 +1049,7 @@ text = buildtext() data = compress(text) l = len(data[1]) + len(data[0]) - base = curr + base = chainbase = curr e = (offset_type(offset, flags), l, textlen, base, link, p1r, p2r, node) @@ -1075,7 +1075,7 @@ if type(text) == str: # only accept immutable objects self._cache = (node, curr, text) - self._basecache = (curr, base) + self._basecache = (curr, chainbase) return node def group(self, nodelist, bundler):