# HG changeset patch # User Durham Goode <dur...@fb.com> # Date 1473893509 25200 # Wed Sep 14 15:51:49 2016 -0700 # Node ID 33a7df42b989c555972280f6b84e2fac38babf7b # Parent d41da1522f8efb5bf5aa75a51f0093b1129b6b5a 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. diff --git a/mercurial/manifest.py b/mercurial/manifest.py --- a/mercurial/manifest.py +++ b/mercurial/manifest.py @@ -1040,20 +1040,34 @@ class manifestlog(object): """Retrieves the manifest instance for the given node. Throws a KeyError 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 self._treeinmem: - m = treemanifestctx(self._revlog, '', node) + def get(self, dir, node): + """Retrieves the manifest instance for the given node. Throws a KeyError + if not found. + """ + if dir: + if self._treeinmem: + m = treemanifestctx(self._revlog.dirlog(dir), dir, node) + else: + raise error.Abort( + _("cannot ask for manifest directory '%s' in a flat " + "manifest") % dir) else: - m = manifestctx(self._revlog, 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 self._treeinmem: + m = treemanifestctx(self._revlog, '', node) + else: + m = manifestctx(self._revlog, node) + if node != revlog.nullid: + self._mancache[node] = m return m def add(self, m, transaction, link, p1, p2, added, removed): _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel