Patchwork [5,of,9,V4] manifest: add manifestlog.get to obtain subdirectory instances

login
register
mail settings
Submitter Durham Goode
Date Sept. 20, 2016, 11:47 p.m.
Message ID <52a206d772021194ab43.1474415272@dev111.prn1.facebook.com>
Download mbox | patch
Permalink /patch/16702/
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 52a206d772021194ab4356aeba2c73650851a624
# Parent  8cf5f24c100e58ece712703d0e4bb0746bc3087e
manifest: add manifestlog.get to obtain subdirectory instances

Previously manifestlog only allowed obtaining root level manifests. Future
patches will need direct access to subdirectory manifests as part of changegroup
creation, so let's add a get() function that knows how to deal with
subdirectories.
via Mercurial-devel - Sept. 21, 2016, 6:56 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 52a206d772021194ab4356aeba2c73650851a624
> # Parent  8cf5f24c100e58ece712703d0e4bb0746bc3087e
> manifest: add manifestlog.get to obtain subdirectory instances
>
> Previously manifestlog only allowed obtaining root level manifests. Future
> patches will need direct access to subdirectory manifests as part of changegroup
> creation, so let's add a get() function that knows how to deal with
> subdirectories.
>
> diff --git a/mercurial/manifest.py b/mercurial/manifest.py
> --- a/mercurial/manifest.py
> +++ b/mercurial/manifest.py
> @@ -1033,20 +1033,34 @@ class manifestlog(object):
>          """Retrieves the manifest instance for the given node. Throws a KeyError
>          if not found.
>          """
> -        if node in self._mancache:
> -            cachemf = self._mancache[node]
> -            # The old manifest may put non-ctx manifests in the cache, so skip
> -            # those since they don't implement the full api.
> -            if (isinstance(cachemf, manifestctx) or
> -                isinstance(cachemf, treemanifestctx)):
> -                return cachemf
> +        return self.get('', node)
>
> -        if self._treeinmem:
> -            m = treemanifestctx(self._revlog, '', node)
> +    def get(self, dir, node):
> +        """Retrieves the manifest instance for the given node. Throws a KeyError
> +        if not found.

nit: Does it really throw KeyError? __getitem__ also doesn't seem to.

> +        """
> +        if dir:
> +            if self._revlog._treeondisk:
> +                m = treemanifestctx(self._revlog.dirlog(dir), dir, node)
> +            else:
> +                raise error.Abort(
> +                        _("cannot ask for manifest directory '%s' in a flat "
> +                          "manifest") % dir)
>          else:
> -            m = manifestctx(self._revlog, node)
> -        if node != revlog.nullid:
> -            self._mancache[node] = m
> +            if node in self._mancache:
> +                cachemf = self._mancache[node]
> +                # The old manifest may put non-ctx manifests in the cache, so
> +                # skip those since they don't implement the full api.
> +                if (isinstance(cachemf, manifestctx) or
> +                    isinstance(cachemf, treemanifestctx)):
> +                    return cachemf
> +
> +            if self._treeinmem:
> +                m = treemanifestctx(self._revlog, '', node)
> +            else:
> +                m = manifestctx(self._revlog, node)
> +            if node != revlog.nullid:
> +                self._mancache[node] = m
>          return m
>
>      def add(self, m, transaction, link, p1, p2, added, removed):
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Durham Goode - Sept. 21, 2016, 7:06 p.m.
On 9/21/16 11:56 AM, 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 52a206d772021194ab4356aeba2c73650851a624
>> # Parent  8cf5f24c100e58ece712703d0e4bb0746bc3087e
>> manifest: add manifestlog.get to obtain subdirectory instances
>>
>> Previously manifestlog only allowed obtaining root level manifests. Future
>> patches will need direct access to subdirectory manifests as part of changegroup
>> creation, so let's add a get() function that knows how to deal with
>> subdirectories.
>>
>> diff --git a/mercurial/manifest.py b/mercurial/manifest.py
>> --- a/mercurial/manifest.py
>> +++ b/mercurial/manifest.py
>> @@ -1033,20 +1033,34 @@ class manifestlog(object):
>>           """Retrieves the manifest instance for the given node. Throws a KeyError
>>           if not found.
>>           """
>> -        if node in self._mancache:
>> -            cachemf = self._mancache[node]
>> -            # The old manifest may put non-ctx manifests in the cache, so skip
>> -            # those since they don't implement the full api.
>> -            if (isinstance(cachemf, manifestctx) or
>> -                isinstance(cachemf, treemanifestctx)):
>> -                return cachemf
>> +        return self.get('', node)
>>
>> -        if self._treeinmem:
>> -            m = treemanifestctx(self._revlog, '', node)
>> +    def get(self, dir, node):
>> +        """Retrieves the manifest instance for the given node. Throws a KeyError
>> +        if not found.
> nit: Does it really throw KeyError? __getitem__ also doesn't seem to.
Interesting point.  It used to, when manifestctx would read from the 
revlog during the constructor, but since we moved that out, it probably 
doesn't now (but probably should).  I'll make the manifestctx and 
treemanifestctx constructors at least check that the node exists in the 
revlog before returning, and throw KeyError if they don't.

Patch

diff --git a/mercurial/manifest.py b/mercurial/manifest.py
--- a/mercurial/manifest.py
+++ b/mercurial/manifest.py
@@ -1033,20 +1033,34 @@  class manifestlog(object):
         """Retrieves the manifest instance for the given node. Throws a KeyError
         if not found.
         """
-        if node in self._mancache:
-            cachemf = self._mancache[node]
-            # The old manifest may put non-ctx manifests in the cache, so skip
-            # those since they don't implement the full api.
-            if (isinstance(cachemf, manifestctx) or
-                isinstance(cachemf, treemanifestctx)):
-                return cachemf
+        return self.get('', node)
 
-        if self._treeinmem:
-            m = treemanifestctx(self._revlog, '', node)
+    def get(self, dir, node):
+        """Retrieves the manifest instance for the given node. Throws a KeyError
+        if not found.
+        """
+        if dir:
+            if self._revlog._treeondisk:
+                m = treemanifestctx(self._revlog.dirlog(dir), dir, node)
+            else:
+                raise error.Abort(
+                        _("cannot ask for manifest directory '%s' in a flat "
+                          "manifest") % dir)
         else:
-            m = manifestctx(self._revlog, node)
-        if node != revlog.nullid:
-            self._mancache[node] = m
+            if node in self._mancache:
+                cachemf = self._mancache[node]
+                # The old manifest may put non-ctx manifests in the cache, so
+                # skip those since they don't implement the full api.
+                if (isinstance(cachemf, manifestctx) or
+                    isinstance(cachemf, treemanifestctx)):
+                    return cachemf
+
+            if self._treeinmem:
+                m = treemanifestctx(self._revlog, '', node)
+            else:
+                m = manifestctx(self._revlog, node)
+            if node != revlog.nullid:
+                self._mancache[node] = m
         return m
 
     def add(self, m, transaction, link, p1, p2, added, removed):