Patchwork [1,of,4] manifest: add manifestctx.readdelta()

login
register
mail settings
Submitter Durham Goode
Date Sept. 13, 2016, 11:30 p.m.
Message ID <f63c46ee248044f73f51.1473809444@dev111.prn1.facebook.com>
Download mbox | patch
Permalink /patch/16610/
State Accepted
Headers show

Comments

Durham Goode - Sept. 13, 2016, 11:30 p.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1473809121 25200
#      Tue Sep 13 16:25:21 2016 -0700
# Node ID f63c46ee248044f73f51a5edc9c7be419df8ff39
# Parent  be16091ac14d03f3cc038b2fb26efe46f785f8d7
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.

Patch

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