changeset 30293:78f3c7166f0d

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.
author Durham Goode <durham@fb.com>
date Wed, 02 Nov 2016 17:10:47 -0700
parents d4b340bf68c5
children bce79dfcf5e4
files mercurial/manifest.py
diffstat 1 files changed, 28 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/manifest.py	Wed Nov 02 17:10:47 2016 -0700
+++ b/mercurial/manifest.py	Wed Nov 02 17:10:47 2016 -0700
@@ -1350,7 +1350,7 @@
                 self._data = manifestdict(text)
         return self._data
 
-    def readfast(self):
+    def readfast(self, shallow=False):
         rl = self._repo.manifestlog._revlog
         r = rl.rev(self._node)
         deltaparent = rl.deltaparent(r)
@@ -1358,7 +1358,7 @@
             return self.readdelta()
         return self.read()
 
-    def readdelta(self):
+    def readdelta(self, shallow=False):
         revlog = self._repo.manifestlog._revlog
         if revlog._usemanifestv2:
             # Need to perform a slow delta
@@ -1420,27 +1420,37 @@
     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(self._repo, 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():
-            if n1:
-                md[f] = n1
-                if fl1:
-                    md.setflag(f, fl1)
-        return md
+        if shallow and not revlog._usemanifestv2:
+            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(self._repo, 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():
+                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):