# HG changeset patch # User Pierre-Yves David # Date 1566224983 -7200 # Node ID 90f5dfc9c42acfd4311aae152b5cf7888f41f3d7 # Parent 616aa62e5027f4ffdab3a743094aae9c55a254d6 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 -r 616aa62e5027 -r 90f5dfc9c42a mercurial/revlog.py --- 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):