[PATCH 6 of 7] revlog: avoid caching raw text too early in _revisiondata

Pierre-Yves David pierre-yves.david at ens-lyon.org
Tue Aug 20 12:37:31 EDT 2019


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at octobus.net>
# Date 1566224983 -7200
#      Mon Aug 19 16:29:43 2019 +0200
# Node ID 5b8bcfd5ef2cb077fe3c8bd2c4f62f693ebcf2fc
# Parent  b8286cf6ab132b2d132e1565bc7bc100b4c69596
# EXP-Topic revisiondata
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 5b8bcfd5ef2c
revlog: avoid caching raw text too early in _revisiondata

Without this change, we could cache the rawtext without considering for it
validating the cache or not. If the exception raised by the invalid hash were to
be caught and the same revision accessed again, the invalid rawtext would be
returned.

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -1633,11 +1633,14 @@ class revlog(object):
         rawtext = None
         # An intermediate text to apply deltas to
         basetext = None
+        # Do we need to update the rawtext cache once it is validated ?
+        needcaching = True
 
         # Check is we are the entry in cache
         # The cache entry looks like (node, rev, rawtext)
         if self._revisioncache:
             if self._revisioncache[0] == node:
+                needcaching = False
                 # _cache only stores rawtext
                 # rawtext is reusable. but we might need to run flag processors
                 rawtext = self._revisioncache[2]
@@ -1680,7 +1683,6 @@ class revlog(object):
 
             rawtext = mdiff.patches(basetext, bins)
             del basetext # let us have a change to free memory early
-            self._revisioncache = (node, rev, rawtext)
 
         if flags is None:
             if rev is None:
@@ -1691,6 +1693,9 @@ class revlog(object):
         if validatehash:
             self.checkhash(text, node, rev=rev)
 
+        if needcaching:
+            self._revisioncache = (node, rev, rawtext)
+
         return text
 
     def rawdata(self, nodeorrev, _df=None):


More information about the Mercurial-devel mailing list