manifest: throw LookupError if node not in revlog
authorDurham Goode <durham@fb.com>
Wed, 02 Nov 2016 17:33:31 -0700
changeset 30290 1a0c1ad57833
parent 30289 1f92056c4066
child 30291 dc21ea3323c4
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).
mercurial/manifest.py
--- a/mercurial/manifest.py	Sun Oct 23 10:40:33 2016 -0700
+++ b/mercurial/manifest.py	Wed Nov 02 17:33:31 2016 -0700
@@ -1262,8 +1262,8 @@
         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 @@
                 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: