changeset 42807:90f5dfc9c42a

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.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 19 Aug 2019 16:29:43 +0200
parents 616aa62e5027
children e91411fcc697
files mercurial/revlog.py
diffstat 1 files changed, 6 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revlog.py	Wed Aug 07 23:55:01 2019 +0200
+++ b/mercurial/revlog.py	Mon Aug 19 16:29:43 2019 +0200
@@ -1633,11 +1633,14 @@
         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 if we have 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 @@
 
             rawtext = mdiff.patches(basetext, bins)
             del basetext # let us have a chance to free memory early
-            self._revisioncache = (node, rev, rawtext)
 
         if flags is None:
             if rev is None:
@@ -1691,6 +1693,9 @@
         if validatehash:
             self.checkhash(text, node, rev=rev)
 
+        if needcaching:
+            self._revisioncache = (node, rev, rawtext)
+
         return text
 
     def rawdata(self, nodeorrev, _df=None):