Patchwork [7,of,9,V4] manifest: add shallow option to treemanifestctx.readdelta and readfast

login
register
mail settings
Submitter Durham Goode
Date Sept. 20, 2016, 11:47 p.m.
Message ID <561681e7a16fa33aa8a4.1474415274@dev111.prn1.facebook.com>
Download mbox | patch
Permalink /patch/16704/
State Accepted
Headers show

Comments

Durham Goode - Sept. 20, 2016, 11:47 p.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1474399441 25200
#      Tue Sep 20 12:24:01 2016 -0700
# Node ID 561681e7a16fa33aa8a40e4c9a31ff395a115e4c
# Parent  69b91c12d904f329eff6618ac43f5cfef631e8dc
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 - Sept. 21, 2016, 8:32 p.m.
On Tue, Sep 20, 2016 at 4:47 PM, Durham Goode <durham@fb.com> wrote:
> # HG changeset patch
> # User Durham Goode <durham@fb.com>
> # Date 1474399441 25200
> #      Tue Sep 20 12:24:01 2016 -0700
> # Node ID 561681e7a16fa33aa8a40e4c9a31ff395a115e4c
> # Parent  69b91c12d904f329eff6618ac43f5cfef631e8dc
> 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
> @@ -1109,7 +1109,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)
> @@ -1117,7 +1117,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
> @@ -1176,27 +1176,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:

Looks like this cannot happen because the condition above checks that
it's false.

> +                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):
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Durham Goode - Oct. 25, 2016, 8:17 p.m.
On 9/21/16 1:32 PM, Martin von Zweigbergk wrote:
> On Tue, Sep 20, 2016 at 4:47 PM, Durham Goode <durham@fb.com> wrote:
>> # HG changeset patch
>> # User Durham Goode <durham@fb.com>
>> # Date 1474399441 25200
>> #      Tue Sep 20 12:24:01 2016 -0700
>> # Node ID 561681e7a16fa33aa8a40e4c9a31ff395a115e4c
>> # Parent  69b91c12d904f329eff6618ac43f5cfef631e8dc
>> 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
>> @@ -1109,7 +1109,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)
>> @@ -1117,7 +1117,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
>> @@ -1176,27 +1176,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:
> Looks like this cannot happen because the condition above checks that
> it's false.
True. Will fix
>
>> +                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):
>> _______________________________________________
>> Mercurial-devel mailing list
>> Mercurial-devel@mercurial-scm.org
>> https://urldefense.proofpoint.com/v2/url?u=https-3A__www.mercurial-2Dscm.org_mailman_listinfo_mercurial-2Ddevel&d=DQIBaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=nuarHzhP1wi1T9iURRCj1A&m=0loc3QxbV83HAhNXcOapFTjP_X7sVB5naGs61y32iO0&s=1cqzH8WNI5JzlNBsQtDTvCxgzKza4y1Cn1sFmfZvsvo&e=

Patch

diff --git a/mercurial/manifest.py b/mercurial/manifest.py
--- a/mercurial/manifest.py
+++ b/mercurial/manifest.py
@@ -1109,7 +1109,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)
@@ -1117,7 +1117,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
@@ -1176,27 +1176,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):