manifest: throw LookupError if node not in revlog

When accessing a manifest via manifestlog[node], let's verify that the node
actually exists and throw a LookupError if it doesn't. This matches the old read
behavior, so we don't accidentally return invalid manifestctxs.

We do this in manifestlog instead of in the manifestctx/treemanifestctx
constructors because the treemanifest code currently relies on the fact that
certain code paths can produce treemanifests without touching the revlogs (and
it has tests that verify things work if certain revlogs are missing entirely, so
they break if we add validation that tries to read them).
This commit is contained in:
Durham Goode 2016-11-02 17:33:31 -07:00
parent 83ab000007
commit c70bd2fb82

View File

@ -1262,8 +1262,8 @@ class manifestlog(object):
self._mancache = self._oldmanifest._mancache
def __getitem__(self, node):
"""Retrieves the manifest instance for the given node. Throws a KeyError
if not found.
"""Retrieves the manifest instance for the given node. Throws a
LookupError if not found.
"""
if node in self._mancache:
cachemf = self._mancache[node]
@ -1273,6 +1273,9 @@ class manifestlog(object):
isinstance(cachemf, treemanifestctx)):
return cachemf
if node not in self._revlog.nodemap:
raise LookupError(node, self._revlog.indexfile,
_('no node'))
if self._treeinmem:
m = treemanifestctx(self._repo, '', node)
else: