# HG changeset patch # User Gregory Szorc # Date 2018-09-18 22:15:24 # Node ID 5ccd791344f3d890521426baeee7c3646cf54704 # Parent edaa40dc5fe56d8c900798076d800f536ac93676 localrepo: pass root manifest into manifestlog.__init__ Today, localrepository has a method that can be overloaded which returns an instance of the root manifest storage object. When a manifestlog is created, it calls this private method and stores the root manifest object on it. This "hook" on localrepository isn't part of the documented interface. It isn't compatible with our desire to make repo storage determined before the repo object is constructed. This commit changes manifestlog.__init__ to accept the root storage object instead of calling into the repo to construct it. By doing things this way, the repo instance is responsible for constructing the manifest storage object directly. This does mean that other derived repo types need to overload manifestlog(). But they should have been doing this already, as manifestlog() is typically decorated in a storage-specific way. e.g. localrepository.manifestlog() is decorated as @storecache('00manifest.i'). And this assumes that a 00manifest.i file exists in the store vfs. This condition may not hold for repository types using non-revlog storage. So it is important for special repo types to override manifestlog() to remove this file association. The code changed in perf is wrong because it isn't compatible with older Mercurial versions. But I'm pretty sure the code was broken on older versions before this commit. It only affects `hg perftags`. I don't care enough to fix that at this time. .. api:: ``manifest.manifestlog.__init__()`` now receives the root manifest storage instance instead of calling into a private method on the repo object to obtain it. Differential Revision: https://phab.mercurial-scm.org/D4641 diff --git a/contrib/perf.py b/contrib/perf.py --- a/contrib/perf.py +++ b/contrib/perf.py @@ -495,7 +495,9 @@ def perftags(ui, repo, **opts): repocleartagscache = repocleartagscachefunc(repo) def t(): repo.changelog = mercurial.changelog.changelog(svfs) - repo.manifestlog = mercurial.manifest.manifestlog(svfs, repo) + rootmanifest = mercurial.manifest.manifestrevlog(svfs) + repo.manifestlog = mercurial.manifest.manifestlog(svfs, repo, + rootmanifest) repocleartagscache() return len(repo.tags()) timer(t) diff --git a/mercurial/bundlerepo.py b/mercurial/bundlerepo.py --- a/mercurial/bundlerepo.py +++ b/mercurial/bundlerepo.py @@ -364,14 +364,16 @@ class bundlerepository(object): self.manstart = self._cgunpacker.tell() return c - def _constructmanifest(self): + @localrepo.unfilteredpropertycache + def manifestlog(self): self._cgunpacker.seek(self.manstart) # consume the header if it exists self._cgunpacker.manifestheader() linkmapper = self.unfiltered().changelog.rev - m = bundlemanifest(self.svfs, self._cgunpacker, linkmapper) + rootstore = bundlemanifest(self.svfs, self._cgunpacker, linkmapper) self.filestart = self._cgunpacker.tell() - return m + + return manifest.manifestlog(self.svfs, self, rootstore) def _consumemanifest(self): """Consumes the manifest portion of the bundle, setting filestart so the diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -994,15 +994,10 @@ class localrepository(object): return changelog.changelog(self.svfs, trypending=txnutil.mayhavepending(self.root)) - def _constructmanifest(self): - # This is a temporary function while we migrate from manifest to - # manifestlog. It allows bundlerepo and unionrepo to intercept the - # manifest creation. - return manifest.manifestrevlog(self.svfs) - @storecache('00manifest.i') def manifestlog(self): - return manifest.manifestlog(self.svfs, self) + rootstore = manifest.manifestrevlog(self.svfs) + return manifest.manifestlog(self.svfs, self, rootstore) @repofilecache('dirstate') def dirstate(self): diff --git a/mercurial/manifest.py b/mercurial/manifest.py --- a/mercurial/manifest.py +++ b/mercurial/manifest.py @@ -1609,7 +1609,7 @@ class manifestlog(object): of the list of files in the given commit. Consumers of the output of this class do not care about the implementation details of the actual manifests they receive (i.e. tree or flat or lazily loaded, etc).""" - def __init__(self, opener, repo): + def __init__(self, opener, repo, rootstore): usetreemanifest = False cachesize = 4 @@ -1620,7 +1620,7 @@ class manifestlog(object): self._treemanifests = usetreemanifest - self._rootstore = repo._constructmanifest() + self._rootstore = rootstore self._rootstore._setupmanifestcachehooks(repo) self._narrowmatch = repo.narrowmatch() diff --git a/mercurial/statichttprepo.py b/mercurial/statichttprepo.py --- a/mercurial/statichttprepo.py +++ b/mercurial/statichttprepo.py @@ -185,7 +185,8 @@ class statichttprepository(localrepo.loc self._filecache = {} self.requirements = requirements - self.manifestlog = manifest.manifestlog(self.svfs, self) + rootmanifest = manifest.manifestrevlog(self.svfs) + self.manifestlog = manifest.manifestlog(self.svfs, self, rootmanifest) self.changelog = changelog.changelog(self.svfs) self._tags = None self.nodetagscache = None diff --git a/mercurial/unionrepo.py b/mercurial/unionrepo.py --- a/mercurial/unionrepo.py +++ b/mercurial/unionrepo.py @@ -208,6 +208,12 @@ class unionrepository(object): def changelog(self): return unionchangelog(self.svfs, self.repo2.svfs) + @localrepo.unfilteredpropertycache + def manifestlog(self): + rootstore = unionmanifest(self.svfs, self.repo2.svfs, + self.unfiltered()._clrev) + return manifest.manifestlog(self.svfs, self, rootstore) + def _clrev(self, rev2): """map from repo2 changelog rev to temporary rev in self.changelog""" node = self.repo2.changelog.node(rev2) diff --git a/tests/test-check-interfaces.py b/tests/test-check-interfaces.py --- a/tests/test-check-interfaces.py +++ b/tests/test-check-interfaces.py @@ -184,7 +184,7 @@ def main(): checkzobject(fl, allowextra=True) # Conforms to imanifestlog. - ml = manifest.manifestlog(vfs, repo) + ml = manifest.manifestlog(vfs, repo, manifest.manifestrevlog(repo.svfs)) checkzobject(ml) checkzobject(repo.manifestlog)