changeset 39272:73cf21b2e8a6

manifest: add getstorage() to manifestlog and use it globally It is a common pattern to obtain a directory manifest storage instance (a manifestrevlog) by going through manifestlog._revlog.dirlog(). Why access to storage and caching of other manifests is done through manifestrevlog instead of manifestlog, I don't know. This commit establishes a getstorage(tree) API on manifestlog and imanifestlog that provides a public API for accessing manifest storage. All consumers previously using private attributes have been updated to use this new method. .. api:: manifestlog now has a getstorage(tree) method It should be used for obtaining an object representing the manifest's storage implementation. Accessing manifestlog._revlog should be avoided. Differential Revision: https://phab.mercurial-scm.org/D4277
author Gregory Szorc <gregory.szorc@gmail.com>
date Fri, 10 Aug 2018 15:01:06 -0700
parents 0d97530eb535
children 071f97d03acb
files hgext/convert/hg.py mercurial/changegroup.py mercurial/cmdutil.py mercurial/debugcommands.py mercurial/manifest.py mercurial/repair.py mercurial/repository.py mercurial/verify.py
diffstat 8 files changed, 26 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/hg.py	Fri Aug 10 14:44:50 2018 -0700
+++ b/hgext/convert/hg.py	Fri Aug 10 15:01:06 2018 -0700
@@ -358,7 +358,7 @@
             p2 = node
 
         if self.filemapmode and nparents == 1:
-            man = self.repo.manifestlog._revlog
+            man = self.repo.manifestlog.getstorage(b'')
             mnode = self.repo.changelog.read(nodemod.bin(p2))[0]
             closed = 'close' in commit.extra
             if not closed and not man.cmp(m1node, man.revision(mnode)):
--- a/mercurial/changegroup.py	Fri Aug 10 14:44:50 2018 -0700
+++ b/mercurial/changegroup.py	Fri Aug 10 15:01:06 2018 -0700
@@ -253,8 +253,7 @@
         # be empty during the pull
         self.manifestheader()
         deltas = self.deltaiter()
-        # TODO this violates storage abstraction.
-        repo.manifestlog._revlog.addgroup(deltas, revmap, trp)
+        repo.manifestlog.getstorage(b'').addgroup(deltas, revmap, trp)
         prog.complete()
         self.callback = None
 
@@ -485,9 +484,8 @@
             # If we get here, there are directory manifests in the changegroup
             d = chunkdata["filename"]
             repo.ui.debug("adding %s revisions\n" % d)
-            dirlog = repo.manifestlog._revlog.dirlog(d)
             deltas = self.deltaiter()
-            if not dirlog.addgroup(deltas, revmap, trp):
+            if not repo.manifestlog.getstorage(d).addgroup(deltas, revmap, trp):
                 raise error.Abort(_("received dir revlog group is empty"))
 
 class headerlessfixup(object):
@@ -1019,7 +1017,6 @@
         """
         repo = self._repo
         mfl = repo.manifestlog
-        dirlog = mfl._revlog.dirlog
         tmfnodes = {'': manifests}
 
         # Callback for the manifest, used to collect linkrevs for filelog
@@ -1066,7 +1063,7 @@
 
         while tmfnodes:
             tree, nodes = tmfnodes.popitem()
-            store = dirlog(tree)
+            store = mfl.getstorage(tree)
 
             if not self._filematcher.visitdir(store._tree[:-1] or '.'):
                 prunednodes = []
--- a/mercurial/cmdutil.py	Fri Aug 10 14:44:50 2018 -0700
+++ b/mercurial/cmdutil.py	Fri Aug 10 15:01:06 2018 -0700
@@ -1083,11 +1083,11 @@
                                    "treemanifest enabled"))
             if not dir.endswith('/'):
                 dir = dir + '/'
-            dirlog = repo.manifestlog._revlog.dirlog(dir)
+            dirlog = repo.manifestlog.getstorage(dir)
             if len(dirlog):
                 r = dirlog
         elif mf:
-            r = repo.manifestlog._revlog
+            r = repo.manifestlog.getstorage(b'')
         elif file_:
             filelog = repo.file(file_)
             if len(filelog):
--- a/mercurial/debugcommands.py	Fri Aug 10 14:44:50 2018 -0700
+++ b/mercurial/debugcommands.py	Fri Aug 10 15:01:06 2018 -0700
@@ -1486,7 +1486,7 @@
 def debugmanifestfulltextcache(ui, repo, add=None, **opts):
     """show, clear or amend the contents of the manifest fulltext cache"""
     with repo.lock():
-        r = repo.manifestlog._revlog
+        r = repo.manifestlog.getstorage(b'')
         try:
             cache = r._fulltextcache
         except AttributeError:
--- a/mercurial/manifest.py	Fri Aug 10 14:44:50 2018 -0700
+++ b/mercurial/manifest.py	Fri Aug 10 15:01:06 2018 -0700
@@ -1452,7 +1452,7 @@
         if tree:
             if self._revlog._treeondisk:
                 if verify:
-                    dirlog = self._revlog.dirlog(tree)
+                    dirlog = self.getstorage(tree)
                     if node not in dirlog.nodemap:
                         raise LookupError(node, dirlog.indexfile,
                                           _('no node'))
@@ -1479,6 +1479,9 @@
             mancache[node] = m
         return m
 
+    def getstorage(self, tree):
+        return self._revlog.dirlog(tree)
+
     def clearcaches(self, clear_persisted_data=False):
         self._dirmancache.clear()
         self._revlog.clearcaches(clear_persisted_data=clear_persisted_data)
@@ -1638,7 +1641,7 @@
         if not narrowmatch.always():
             if not narrowmatch.visitdir(self._dir[:-1] or '.'):
                 return excludedmanifestrevlog(self._dir)
-        return self._manifestlog._revlog.dirlog(self._dir)
+        return self._manifestlog.getstorage(self._dir)
 
     def read(self):
         if self._data is None:
--- a/mercurial/repair.py	Fri Aug 10 14:44:50 2018 -0700
+++ b/mercurial/repair.py	Fri Aug 10 15:01:06 2018 -0700
@@ -81,7 +81,7 @@
     return [revlog.linkrev(r) for r in brokenset]
 
 def _collectmanifest(repo, striprev):
-    return _collectrevlog(repo.manifestlog._revlog, striprev)
+    return _collectrevlog(repo.manifestlog.getstorage(b''), striprev)
 
 def _collectbrokencsets(repo, files, striprev):
     """return the changesets which will be broken by the truncation"""
@@ -322,7 +322,7 @@
     callback.addnodes(nodelist)
 
 def stripmanifest(repo, striprev, tr, files):
-    revlog = repo.manifestlog._revlog
+    revlog = repo.manifestlog.getstorage(b'')
     revlog.strip(striprev, tr)
     striptrees(repo, tr, striprev, files)
 
@@ -333,7 +333,7 @@
             if (unencoded.startswith('meta/') and
                 unencoded.endswith('00manifest.i')):
                 dir = unencoded[5:-12]
-                repo.manifestlog._revlog.dirlog(dir).strip(striprev, tr)
+                repo.manifestlog.getstorage(dir).strip(striprev, tr)
 
 def rebuildfncache(ui, repo):
     """Rebuilds the fncache file from repo history.
--- a/mercurial/repository.py	Fri Aug 10 14:44:50 2018 -0700
+++ b/mercurial/repository.py	Fri Aug 10 15:01:06 2018 -0700
@@ -1023,6 +1023,15 @@
         interface.
         """
 
+    def getstorage(tree):
+        """Retrieve an interface to storage for a particular tree.
+
+        If ``tree`` is the empty bytestring, storage for the root manifest will
+        be returned. Otherwise storage for a tree manifest is returned.
+
+        TODO formalize interface for returned object.
+        """
+
     def clearcaches():
         """Clear caches associated with this collection."""
 
--- a/mercurial/verify.py	Fri Aug 10 14:44:50 2018 -0700
+++ b/mercurial/verify.py	Fri Aug 10 15:01:06 2018 -0700
@@ -45,7 +45,7 @@
         self.errors = 0
         self.warnings = 0
         self.havecl = len(repo.changelog) > 0
-        self.havemf = len(repo.manifestlog._revlog) > 0
+        self.havemf = len(repo.manifestlog.getstorage(b'')) > 0
         self.revlogv1 = repo.changelog.version != revlog.REVLOGV0
         self.lrugetctx = util.lrucachefunc(repo.__getitem__)
         self.refersmf = False
@@ -205,7 +205,7 @@
         ui = self.ui
         match = self.match
         mfl = self.repo.manifestlog
-        mf = mfl._revlog.dirlog(dir)
+        mf = mfl.getstorage(dir)
 
         if not dir:
             self.ui.status(_("checking manifests\n"))