comparison mercurial/revlog.py @ 40055:801ccd8e67c0

revlog: clear revision cache on hash verification failure The revision cache is populated after raw revision fulltext is retrieved but before hash verification. If hash verification fails, the revision cache will be populated and subsequent operations to retrieve the invalid fulltext may return the cached fulltext instead of raising. This commit changes hash verification so it will invalidate the revision cache if the cached node fails hash verification. The side-effect is that subsequent operations to request the revision text - even the raw revision text - will always fail. The new behavior is consistent and is definitely less wrong. There is an open question of whether revision(raw=True) should validate hashes. But I'm going to punt on this problem. We can always change behavior later. And to be honest, I'm not sure we should expose raw=True on the storage interface at all. Another day... Differential Revision: https://phab.mercurial-scm.org/D4867
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 03 Oct 2018 10:57:35 -0700
parents 55db747a21ad
children 0a4625ffd6c0
comparison
equal deleted inserted replaced
40054:8c692a6b5ad1 40055:801ccd8e67c0
1657 """ 1657 """
1658 try: 1658 try:
1659 if p1 is None and p2 is None: 1659 if p1 is None and p2 is None:
1660 p1, p2 = self.parents(node) 1660 p1, p2 = self.parents(node)
1661 if node != self.hash(text, p1, p2): 1661 if node != self.hash(text, p1, p2):
1662 # Clear the revision cache on hash failure. The revision cache
1663 # only stores the raw revision and clearing the cache does have
1664 # the side-effect that we won't have a cache hit when the raw
1665 # revision data is accessed. But this case should be rare and
1666 # it is extra work to teach the cache about the hash
1667 # verification state.
1668 if self._revisioncache and self._revisioncache[0] == node:
1669 self._revisioncache = None
1670
1662 revornode = rev 1671 revornode = rev
1663 if revornode is None: 1672 if revornode is None:
1664 revornode = templatefilters.short(hex(node)) 1673 revornode = templatefilters.short(hex(node))
1665 raise error.RevlogError(_("integrity check failed on %s:%s") 1674 raise error.RevlogError(_("integrity check failed on %s:%s")
1666 % (self.indexfile, pycompat.bytestr(revornode))) 1675 % (self.indexfile, pycompat.bytestr(revornode)))