Patchwork [6,of,8] manifest: add shallow option to treemanifestctx.readdelta and readfast

login
register
mail settings
Submitter Durham Goode
Date Sept. 14, 2016, 11:04 p.m.
Message ID <de2b633b8448ee3fccc8.1473894276@dev111.prn1.facebook.com>
Download mbox | patch
Permalink /patch/16631/
State Superseded
Headers show

Comments

Durham Goode - Sept. 14, 2016, 11:04 p.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1473893509 25200
#      Wed Sep 14 15:51:49 2016 -0700
# Node ID de2b633b8448ee3fccc8bc277ae308476945b7dc
# Parent  33a7df42b989c555972280f6b84e2fac38babf7b
manifest: add shallow option to treemanifestctx.readdelta and readfast

The old manifest had different functions for performing shallow reads, shallow
readdeltas, and shallow readfasts. Since a lot of the code is duplicate (and
since those functions don't make sense on a normal manifestctx), let's unify
them into flags on the existing readdelta and readfast functions.

A future diff will change consumers of these functions to use the manifestctx
versions and will delete the old apis.

Patch

diff --git a/mercurial/manifest.py b/mercurial/manifest.py
--- a/mercurial/manifest.py
+++ b/mercurial/manifest.py
@@ -1104,7 +1104,7 @@  class manifestctx(object):
                 self._data = manifestdict(text)
         return self._data
 
-    def readfast(self):
+    def readfast(self, shallow=False):
         rl = self._revlog
         r = rl.rev(self._node)
         deltaparent = rl.deltaparent(r)
@@ -1112,7 +1112,7 @@  class manifestctx(object):
             return self.readdelta()
         return self.read()
 
-    def readdelta(self):
+    def readdelta(self, shallow=False):
         revlog = self._revlog
         if revlog._usemanifestv2:
             # Need to perform a slow delta
@@ -1171,27 +1171,40 @@  class treemanifestctx(object):
     def node(self):
         return self._node
 
-    def readdelta(self):
-        # Need to perform a slow delta
+    def readdelta(self, shallow=False):
         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
+        if shallow and revlog._treeondisk and not revlog._usemanifestv2:
+            if revlog._usemanifestv2:
+                raise error.Abort(
+                    _("shallow readdelta() not implemented for manifestv2"))
+            r = revlog.rev(self._node)
+            d = mdiff.patchtext(revlog.revdiff(revlog.deltaparent(r), r))
+            return manifestdict(d)
+        else:
+            # Need to perform a slow delta
+            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
 
-    def readfast(self):
+    def readfast(self, shallow=False):
         rl = self._revlog
         r = rl.rev(self._node)
         deltaparent = rl.deltaparent(r)
-        if deltaparent != revlog.nullrev and deltaparent in rl.parentrevs(r):
-            return self.readdelta()
-        return self.read()
+        if (deltaparent != revlog.nullrev and
+            deltaparent in rl.parentrevs(r)):
+            return self.readdelta(shallow=shallow)
+
+        if shallow:
+            return manifestdict(rl.revision(self._node))
+        else:
+            return self.read()
 
 class manifest(manifestrevlog):
     def __init__(self, opener, dir='', dirlogcache=None):