# HG changeset patch # User Durham Goode # Date 2016-09-13 23:25:21 # Node ID a059b17352ef12f8cca3329f769a35311e91227f # Parent 2c302c6544511b37abe61ee2cc5278e4f61d5e71 manifest: add manifestctx.readdelta() This adds an implementation of readdelta to the new manifestctx class and adds a couple consumers of it. This currently appears to have some duplicate code, but future patches cause this function to diverge when things like "shallow" are introduced. diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py --- a/mercurial/changegroup.py +++ b/mercurial/changegroup.py @@ -332,7 +332,7 @@ class cg1unpacker(object): for cset in xrange(clstart, clend): mfnode = repo.changelog.read( repo.changelog.node(cset))[0] - mfest = repo.manifest.readdelta(mfnode) + mfest = repo.manifestlog[mfnode].readdelta() # store file nodes we must see for f, n in mfest.iteritems(): needfiles.setdefault(f, set()).add(n) diff --git a/mercurial/context.py b/mercurial/context.py --- a/mercurial/context.py +++ b/mercurial/context.py @@ -532,7 +532,8 @@ class changectx(basectx): @propertycache def _manifestdelta(self): - return self._repo.manifest.readdelta(self._changeset.manifest) + mfnode = self._changeset.manifest + return self._repo.manifestlog[mfnode].readdelta() @propertycache def _parents(self): diff --git a/mercurial/manifest.py b/mercurial/manifest.py --- a/mercurial/manifest.py +++ b/mercurial/manifest.py @@ -993,6 +993,25 @@ class manifestctx(object): self._data = manifestdict(text) return self._data + def readdelta(self): + revlog = self._revlog + if revlog._usemanifestv2: + # Need to perform a slow delta + r0 = revlog.deltaparent(revlog.rev(self._node)) + m0 = manifestctx(revlog, revlog.node(r0)).read() + m1 = self.read() + md = manifestdict() + for f, ((n0, fl0), (n1, fl1)) in m0.diff(m1).iteritems(): + if n1: + md[f] = n1 + if fl1: + md.setflag(f, fl1) + return md + + r = revlog.rev(self._node) + d = mdiff.patchtext(revlog.revdiff(revlog.deltaparent(r), r)) + return manifestdict(d) + class treemanifestctx(object): def __init__(self, revlog, dir, node): revlog = revlog.dirlog(dir) @@ -1033,6 +1052,20 @@ class treemanifestctx(object): def node(self): return self._node + def readdelta(self): + # Need to perform a slow delta + revlog = self._revlog + r0 = revlog.deltaparent(revlog.rev(self._node)) + m0 = treemanifestctx(revlog, revlog.node(r0), dir=self._dir).read() + m1 = self.read() + md = treemanifest(dir=self._dir) + for f, ((n0, fl0), (n1, fl1)) in m0.diff(m1).iteritems(): + if n1: + md[f] = n1 + if fl1: + md.setflag(f, fl1) + return md + class manifest(manifestrevlog): def __init__(self, opener, dir='', dirlogcache=None): '''The 'dir' and 'dirlogcache' arguments are for internal use by