# HG changeset patch # User Benoit Boissinot # Date 1252054075 -7200 # Node ID d0db168136dc0612cc63f877ced0201cf1053357 # Parent 3516a4e877c101f4dbe0f10f4d11412214711dff manifest/revlog: do not let the revlog cache mutable objects If a buffer of an mutable object is passed to revlog.addrevision(), the revlog will happily store it in its cache. Later when the revlog reuses the cached entry, if the manifest modified the object in-between, all kind of bugs appears. We fix it by: - passing immutable objects to addrevision() if they are already available - only storing the text in the cache if it's of str type Then we can remove the conversion of the cache entry to str() during retrieval. That was probably just there hiding the bug for the common cases but not really fixing it. diff -r 3516a4e877c1 -r d0db168136dc mercurial/manifest.py --- a/mercurial/manifest.py Thu Sep 03 21:40:45 2009 +0200 +++ b/mercurial/manifest.py Fri Sep 04 10:47:55 2009 +0200 @@ -132,9 +132,9 @@ # if this is changed to support newlines in filenames, # be sure to check the templates/ dir again (especially *-raw.tmpl) hex, flags = revlog.hex, map.flags - text = ["%s\000%s%s\n" % (f, hex(map[f]), flags(f)) - for f in files] - arraytext = array.array('c', "".join(text)) + text = ''.join("%s\000%s%s\n" % (f, hex(map[f]), flags(f)) + for f in files) + arraytext = array.array('c', text) cachedelta = None else: added, removed = changed @@ -190,9 +190,9 @@ if p1 != self.tip(): cachedelta = None arraytext = addlist + text = buffer(arraytext) - n = self.addrevision(buffer(arraytext), transaction, link, - p1, p2, cachedelta) + n = self.addrevision(text, transaction, link, p1, p2, cachedelta) self._mancache = (n, map, arraytext) return n diff -r 3516a4e877c1 -r d0db168136dc mercurial/revlog.py --- a/mercurial/revlog.py Thu Sep 03 21:40:45 2009 +0200 +++ b/mercurial/revlog.py Fri Sep 04 10:47:55 2009 +0200 @@ -973,7 +973,7 @@ if node == nullid: return "" if self._cache and self._cache[0] == node: - return str(self._cache[2]) + return self._cache[2] # look up what we need to read text = None @@ -988,7 +988,7 @@ # do we have useful data cached? if self._cache and self._cache[1] >= base and self._cache[1] < rev: base = self._cache[1] - text = str(self._cache[2]) + text = self._cache[2] self._loadindex(base, rev + 1) self._chunkraw(base, rev) @@ -1111,7 +1111,8 @@ ifh.write(data[1]) self.checkinlinesize(transaction, ifh) - self._cache = (node, curr, text) + if type(text) == str: # only accept immutable objects + self._cache = (node, curr, text) return node def ancestor(self, a, b):