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

login
register
mail settings
Submitter Durham Goode
Date Nov. 3, 2016, 1:29 a.m.
Message ID <488f0af8cb92461a67b4.1478136599@dev111.prn1.facebook.com>
Download mbox | patch
Permalink /patch/17310/
State Accepted
Headers show

Comments

Durham Goode - Nov. 3, 2016, 1:29 a.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1478131847 25200
#      Wed Nov 02 17:10:47 2016 -0700
# Branch stable
# Node ID 488f0af8cb92461a67b47bfe259e3378bb00769c
# Parent  9034cbde98311be9a93da0554a3ca9d399d64089
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.
via Mercurial-devel - Nov. 4, 2016, 10:49 p.m.
On Wed, Nov 2, 2016 at 6:29 PM, Durham Goode <durham@fb.com> wrote:
> # HG changeset patch
> # User Durham Goode <durham@fb.com>
> # Date 1478131847 25200
> #      Wed Nov 02 17:10:47 2016 -0700
> # Branch stable
> # Node ID 488f0af8cb92461a67b47bfe259e3378bb00769c
> # Parent  9034cbde98311be9a93da0554a3ca9d399d64089
> 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.
>
> diff --git a/mercurial/manifest.py b/mercurial/manifest.py
> --- a/mercurial/manifest.py
> +++ b/mercurial/manifest.py
> @@ -1350,7 +1350,7 @@ class manifestctx(object):
>                  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 @@ class manifestctx(object):
>              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 @@ 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(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 readdelta(self, shallow=False):
> +        revlog = self._revlog
> +        if shallow and revlog._treeondisk and not revlog._usemanifestv2:

I think "and revlog._treeondisk" can be removed here. If it's false
(which must mean treeinmem is True), we're using treemanifests in
memory but flat manifests on disk. It should be correct to return the
delta from the revlog in that case too.

> +            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):
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/manifest.py b/mercurial/manifest.py
--- a/mercurial/manifest.py
+++ b/mercurial/manifest.py
@@ -1350,7 +1350,7 @@  class manifestctx(object):
                 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 @@  class manifestctx(object):
             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 @@  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(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 readdelta(self, shallow=False):
+        revlog = self._revlog
+        if shallow and revlog._treeondisk 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):