manifest: remove manifest.add and add memmfctx.write
This removes one more dependency on the manifest class by moving the write
functionality onto the memmanifestctx classes and changing the one consumer to
use the new API.
By moving the write path to a manifestctx, we now give the individual manifests
control over how they're read and serialized. This will be useful in developing
new manifest formats and storage systems.
--- a/mercurial/localrepo.py Tue Nov 08 08:03:43 2016 -0800
+++ b/mercurial/localrepo.py Tue Nov 08 08:03:43 2016 -0800
@@ -1700,9 +1700,13 @@
trp = weakref.proxy(tr)
if ctx.files():
- m1 = p1.manifest()
- m2 = p2.manifest()
- m = m1.copy()
+ m1ctx = p1.manifestctx()
+ m2ctx = p2.manifestctx()
+ mctx = m1ctx.copy()
+
+ m = mctx.read()
+ m1 = m1ctx.read()
+ m2 = m2ctx.read()
# check in files
added = []
@@ -1736,9 +1740,9 @@
drop = [f for f in removed if f in m]
for f in drop:
del m[f]
- mn = self.manifestlog.add(m, trp, linkrev,
- p1.manifestnode(), p2.manifestnode(),
- added, drop)
+ mn = mctx.write(trp, linkrev,
+ p1.manifestnode(), p2.manifestnode(),
+ added, drop)
files = changed + removed
else:
mn = p1.manifestnode()
--- a/mercurial/manifest.py Tue Nov 08 08:03:43 2016 -0800
+++ b/mercurial/manifest.py Tue Nov 08 08:03:43 2016 -0800
@@ -1320,14 +1320,14 @@
mancache[node] = m
return m
- def add(self, m, transaction, link, p1, p2, added, removed):
- return self._revlog.add(m, transaction, link, p1, p2, added, removed)
-
class memmanifestctx(object):
def __init__(self, repo):
self._repo = repo
self._manifestdict = manifestdict()
+ def _revlog(self):
+ return self._repo.manifestlog._revlog
+
def new(self):
return memmanifestctx(self._repo)
@@ -1339,6 +1339,10 @@
def read(self):
return self._manifestdict
+ def write(self, transaction, link, p1, p2, added, removed):
+ return self._revlog().add(self._manifestdict, transaction, link, p1, p2,
+ added, removed)
+
class manifestctx(object):
"""A class representing a single revision of a manifest, including its
contents, its parent revs, and its linkrev.
@@ -1430,6 +1434,9 @@
self._dir = dir
self._treemanifest = treemanifest()
+ def _revlog(self):
+ return self._repo.manifestlog._revlog
+
def new(self, dir=''):
return memtreemanifestctx(self._repo, dir=dir)
@@ -1441,6 +1448,10 @@
def read(self):
return self._treemanifest
+ def write(self, transaction, link, p1, p2, added, removed):
+ return self._revlog().add(self._treemanifest, transaction, link, p1, p2,
+ added, removed)
+
class treemanifestctx(object):
def __init__(self, repo, dir, node):
self._repo = repo