Patchwork [4,of,6,RFC] manifest: replace manifestlog repo arg with manifestaccessor

login
register
mail settings
Submitter Durham Goode
Date Nov. 3, 2016, 10:27 p.m.
Message ID <28c62d7ed65d98732218.1478212060@dev111.prn1.facebook.com>
Download mbox | patch
Permalink /patch/17327/
State Changes Requested
Headers show

Comments

Durham Goode - Nov. 3, 2016, 10:27 p.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1478211628 25200
#      Thu Nov 03 15:20:28 2016 -0700
# Branch stable
# Node ID 28c62d7ed65d98732218794380629a64db7d6cf1
# Parent  04c8f9fb517ef1755988fbae3db72df722bcd622
manifest: replace manifestlog repo arg with manifestaccessor

This replaces the manifestlog and manifestctx constructor repo argument with a
manifestaccessor instance. This breaks the circular dependency between localrepo
and manifestlog, and means that manifestctxs no longer need to hold on to the
repository object either.

Patch

diff --git a/contrib/perf.py b/contrib/perf.py
--- a/contrib/perf.py
+++ b/contrib/perf.py
@@ -407,7 +407,8 @@  def perftags(ui, repo, **opts):
     repocleartagscache = repocleartagscachefunc(repo)
     def t():
         repo.changelog = mercurial.changelog.changelog(svfs)
-        repo.manifestlog = mercurial.manifest.manifestlog(svfs, repo)
+        repo.manifestlog = mercurial.manifest.manifestlog(svfs,
+                                                          repo.manifestaccessor)
         repocleartagscache()
         return len(repo.tags())
     timer(t)
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -519,7 +519,7 @@  class localrepository(object):
 
     @storecache('00manifest.i')
     def manifestlog(self):
-        return manifest.manifestlog(self.svfs, self)
+        return manifest.manifestlog(self.svfs, self.manifestaccessor)
 
     @repofilecache('dirstate')
     def dirstate(self):
diff --git a/mercurial/manifest.py b/mercurial/manifest.py
--- a/mercurial/manifest.py
+++ b/mercurial/manifest.py
@@ -1244,8 +1244,8 @@  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):
-        self._repo = repo
+    def __init__(self, opener, mfaccessor):
+        self._mfaccessor = mfaccessor
 
         usetreemanifest = False
 
@@ -1254,12 +1254,13 @@  class manifestlog(object):
             usetreemanifest = opts.get('treemanifest', usetreemanifest)
         self._treeinmem = usetreemanifest
 
-        self._oldmanifest = repo.manifestaccessor.revlog
-        self._revlog = self._oldmanifest
-
         # We'll separate this into it's own cache once oldmanifest is no longer
         # used
-        self._mancache = self._oldmanifest._mancache
+        self._mancache = self._revlog._mancache
+
+    @property
+    def _revlog(self):
+        return self._mfaccessor.revlog
 
     def __getitem__(self, node):
         """Retrieves the manifest instance for the given node. Throws a KeyError
@@ -1274,9 +1275,9 @@  class manifestlog(object):
                 return cachemf
 
         if self._treeinmem:
-            m = treemanifestctx(self._repo, '', node)
+            m = treemanifestctx(self._mfaccessor, '', node)
         else:
-            m = manifestctx(self._repo, node)
+            m = manifestctx(self._mfaccessor, node)
         if node != revlog.nullid:
             self._mancache[node] = m
         return m
@@ -1288,8 +1289,8 @@  class manifestctx(object):
     """A class representing a single revision of a manifest, including its
     contents, its parent revs, and its linkrev.
     """
-    def __init__(self, repo, node):
-        self._repo = repo
+    def __init__(self, mfaccessor, node):
+        self._mfaccessor = mfaccessor
         self._data = None
 
         self._node = node
@@ -1309,7 +1310,7 @@  class manifestctx(object):
             if self._node == revlog.nullid:
                 self._data = manifestdict()
             else:
-                rl = self._repo.manifestlog._revlog
+                rl = self._mfaccessor.revlog
                 text = rl.revision(self._node)
                 arraytext = array.array('c', text)
                 rl._fulltextcache[self._node] = arraytext
@@ -1317,7 +1318,7 @@  class manifestctx(object):
         return self._data
 
     def readfast(self):
-        rl = self._repo.manifestlog._revlog
+        rl = self._mfaccessor.revlog
         r = rl.rev(self._node)
         deltaparent = rl.deltaparent(r)
         if deltaparent != revlog.nullrev and deltaparent in rl.parentrevs(r):
@@ -1325,11 +1326,11 @@  class manifestctx(object):
         return self.read()
 
     def readdelta(self):
-        revlog = self._repo.manifestlog._revlog
+        revlog = self._mfaccessor.revlog
         if revlog._usemanifestv2:
             # Need to perform a slow delta
             r0 = revlog.deltaparent(revlog.rev(self._node))
-            m0 = manifestctx(self._repo, revlog.node(r0)).read()
+            m0 = manifestctx(self._mfaccessor, revlog.node(r0)).read()
             m1 = self.read()
             md = manifestdict()
             for f, ((n0, fl0), (n1, fl1)) in m0.diff(m1).iteritems():
@@ -1344,8 +1345,8 @@  class manifestctx(object):
         return manifestdict(d)
 
 class treemanifestctx(object):
-    def __init__(self, repo, dir, node):
-        self._repo = repo
+    def __init__(self, mfaccessor, dir, node):
+        self._mfaccessor = mfaccessor
         self._dir = dir
         self._data = None
 
@@ -1359,7 +1360,7 @@  class treemanifestctx(object):
         #self.linkrev = revlog.linkrev(rev)
 
     def _revlog(self):
-        return self._repo.manifestlog._revlog.dirlog(self._dir)
+        return self._mfaccessor.revlog.dirlog(self._dir)
 
     def read(self):
         if not self._data:
@@ -1371,7 +1372,7 @@  class treemanifestctx(object):
                 def gettext():
                     return rl.revision(self._node)
                 def readsubtree(dir, subm):
-                    return treemanifestctx(self._repo, dir, subm).read()
+                    return treemanifestctx(self._mfaccessor, dir, subm).read()
                 m.read(gettext, readsubtree)
                 m.setnode(self._node)
                 self._data = m
@@ -1390,7 +1391,8 @@  class treemanifestctx(object):
         # Need to perform a slow delta
         revlog = self._revlog()
         r0 = revlog.deltaparent(revlog.rev(self._node))
-        m0 = treemanifestctx(self._repo, self._dir, revlog.node(r0)).read()
+        m0 = treemanifestctx(self._mfaccessor, self._dir,
+                             revlog.node(r0)).read()
         m1 = self.read()
         md = treemanifest(dir=self._dir)
         for f, ((n0, fl0), (n1, fl1)) in m0.diff(m1).iteritems():
diff --git a/mercurial/statichttprepo.py b/mercurial/statichttprepo.py
--- a/mercurial/statichttprepo.py
+++ b/mercurial/statichttprepo.py
@@ -155,7 +155,8 @@  class statichttprepository(localrepo.loc
         self._filecache = {}
         self.requirements = requirements
 
-        self.manifestlog = manifest.manifestlog(self.svfs, self)
+        self.manifestlog = manifest.manifestlog(self.svfs,
+                                                self.manifestaccessor)
         self.changelog = changelog.changelog(self.svfs)
         self._tags = None
         self.nodetagscache = None