Patchwork [2,of,6,V5] manifest: add manifestlog.get to obtain subdirectory instances

login
register
mail settings
Submitter Durham Goode
Date Nov. 3, 2016, 1:29 a.m.
Message ID <03f320268065807ad4fd.1478136597@dev111.prn1.facebook.com>
Download mbox | patch
Permalink /patch/17305/
State Accepted
Headers show

Comments

Durham Goode - Nov. 3, 2016, 1:29 a.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1478132646 25200
#      Wed Nov 02 17:24:06 2016 -0700
# Branch stable
# Node ID 03f320268065807ad4fd90dbfb9b05d5493c250c
# Parent  ac8875e9c49e6d66393aa412e52262640bdcf134
manifest: add manifestlog.get to obtain subdirectory instances

Previously manifestlog only allowed obtaining root level manifests. Future
patches will need direct access to subdirectory manifests as part of changegroup
creation, so let's add a get() function that knows how to deal with
subdirectories.

Patch

diff --git a/mercurial/manifest.py b/mercurial/manifest.py
--- a/mercurial/manifest.py
+++ b/mercurial/manifest.py
@@ -1265,23 +1265,41 @@  class manifestlog(object):
         """Retrieves the manifest instance for the given node. Throws a
         LookupError if not found.
         """
-        if node in self._mancache:
-            cachemf = self._mancache[node]
-            # The old manifest may put non-ctx manifests in the cache, so skip
-            # those since they don't implement the full api.
-            if (isinstance(cachemf, manifestctx) or
-                isinstance(cachemf, treemanifestctx)):
-                return cachemf
+        return self.get('', node)
 
-        if node not in self._revlog.nodemap:
-            raise LookupError(node, self._revlog.indexfile,
-                              _('no node'))
-        if self._treeinmem:
-            m = treemanifestctx(self._repo, '', node)
+    def get(self, dir, node):
+        """Retrieves the manifest instance for the given node. Throws a
+        LookupError if not found.
+        """
+        if dir:
+            if self._revlog._treeondisk:
+                dirlog = self._revlog.dirlog(dir)
+                if node not in dirlog.nodemap:
+                    raise LookupError(node, dirlog.indexfile,
+                                      _('no node'))
+                m = treemanifestctx(self._repo, dir, node)
+            else:
+                raise error.Abort(
+                        _("cannot ask for manifest directory '%s' in a flat "
+                          "manifest") % dir)
         else:
-            m = manifestctx(self._repo, node)
-        if node != revlog.nullid:
-            self._mancache[node] = m
+            if node in self._mancache:
+                cachemf = self._mancache[node]
+                # The old manifest may put non-ctx manifests in the cache, so
+                # skip those since they don't implement the full api.
+                if (isinstance(cachemf, manifestctx) or
+                    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:
+                m = manifestctx(self._repo, node)
+            if node != revlog.nullid:
+                self._mancache[node] = m
         return m
 
     def add(self, m, transaction, link, p1, p2, added, removed):