Patchwork [2,of,2,narrowhg-ext] manifest: fix narrowmanifest to be narrowmanifestlog

login
register
mail settings
Submitter Durham Goode
Date Nov. 14, 2016, 11:30 p.m.
Message ID <331ce6adfeccf8f21bdd.1479166223@dev111.prn1.facebook.com>
Download mbox | patch
Permalink /patch/17567/
State Accepted
Headers show

Comments

Durham Goode - Nov. 14, 2016, 11:30 p.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1479166205 28800
#      Mon Nov 14 15:30:05 2016 -0800
# Node ID 331ce6adfeccf8f21bdda8ddfb28da8f4b410848
# Parent  33646477f95dcfd2b7d4eede4d190569ca142be6
manifest: fix narrowmanifest to be narrowmanifestlog

Upstream hg has completely refactored the manifest class, so we need to update
our internal narrowmanifest* logic. In some ways the new logic is simpler, since
we only need to wrap manifestlog.get() to cover all manifestctx creations
instead of having to wrap every manifest revlog to capture all creations. We
still need to wrap manifestrevlog creations to insert the narrowrevlog mixin,
but that is now completely separate logic from the tree oriented
excludeddirmanfiestctx logic.
via Mercurial-devel - Nov. 15, 2016, 5:26 p.m.
queued these with some minor changes (dropped unused import and
changed an "add" to "write"). Thanks!

On Mon, Nov 14, 2016 at 3:30 PM, Durham Goode <durham@fb.com> wrote:
> # HG changeset patch
> # User Durham Goode <durham@fb.com>
> # Date 1479166205 28800
> #      Mon Nov 14 15:30:05 2016 -0800
> # Node ID 331ce6adfeccf8f21bdda8ddfb28da8f4b410848
> # Parent  33646477f95dcfd2b7d4eede4d190569ca142be6
> manifest: fix narrowmanifest to be narrowmanifestlog
>
> Upstream hg has completely refactored the manifest class, so we need to update
> our internal narrowmanifest* logic. In some ways the new logic is simpler, since
> we only need to wrap manifestlog.get() to cover all manifestctx creations
> instead of having to wrap every manifest revlog to capture all creations. We
> still need to wrap manifestrevlog creations to insert the narrowrevlog mixin,
> but that is now completely separate logic from the tree oriented
> excludeddirmanfiestctx logic.
>
> diff --git a/src/narrowrepo.py b/src/narrowrepo.py
> --- a/src/narrowrepo.py
> +++ b/src/narrowrepo.py
> @@ -37,11 +37,16 @@ def wraprepo(repo):
>              narrowrevlog.makenarrowchangelog(cl)
>              return cl
>
> +        def _constructmanifest(self):
> +            manifest = super(narrowrepository, self)._constructmanifest()
> +            narrowrevlog.makenarrowmanifestrevlog(manifest)
> +            return manifest
> +
>          @cacheprop('00manifest.i')
> -        def manifest(self):
> -            mf = super(narrowrepository, self).manifest
> -            narrowrevlog.makenarrowmanifest(mf, self)
> -            return mf
> +        def manifestlog(self):
> +            mfl = super(narrowrepository, self).manifestlog
> +            narrowrevlog.makenarrowmanifestlog(mfl, self)
> +            return mfl
>
>          def file(self, f):
>              fl = super(narrowrepository, self).file(f)
> diff --git a/src/narrowrevlog.py b/src/narrowrevlog.py
> --- a/src/narrowrevlog.py
> +++ b/src/narrowrevlog.py
> @@ -17,15 +17,6 @@ assert (revlog.REVIDX_KNOWN_FLAGS & ELLI
>  revlog.REVIDX_KNOWN_FLAGS |= ELLIPSIS_NODE_FLAG
>
>
> -if util.safehasattr(manifest, 'treemanifestctx'):
> -    def inittreemanifestctx(orig, self, revlog, dir, node):
> -        orig(self, revlog, dir, node)
> -        if isinstance(self._revlog, excludeddirmanifestlog):
> -            self._data = excludeddir(dir, node)
> -
> -    extensions.wrapfunction(manifest.treemanifestctx, '__init__',
> -                            inittreemanifestctx)
> -
>  class narrowrevlogmixin(object):
>      """Mixin for revlog subclasses to make them support narrow clones."""
>
> @@ -77,15 +68,15 @@ class excludeddir(manifest.treemanifest)
>      def copy(self):
>          return self
>
> -class excludeddirmanifestlog(manifest.manifest):
> -    def __init__(self, dir):
> +class excludeddirmanifestctx(manifest.treemanifestctx):
> +    def __init__(self, dir, node):
>          self._dir = dir
> -        self._treeondisk = True
> +        self._node = node
>
> -    def read(self, node):
> -        return excludeddir(self._dir, node)
> +    def read(self):
> +        return excludeddir(self._dir, self._node)
>
> -    def add(self, *args):
> +    def write(self, *args):
>          # We should never write entries in dirlogs outside the narrow clone.
>          # However, the method still gets called from writesubtree() in
>          # _addtree(), so we need to handle it. We should possibly make that
> @@ -93,17 +84,23 @@ class excludeddirmanifestlog(manifest.ma
>          # in excludeddir instances).
>          pass
>
> -def makenarrowmanifest(mf, repo):
> -    if not isinstance(mf, narrowrevlogmixin):
> -        class narrowmanifest(narrowrevlogmixin, mf.__class__):
> +def makenarrowmanifestrevlog(mfrevlog):
> +    if not isinstance(mfrevlog, narrowrevlogmixin):
> +        class narrowmanifestrevlog(narrowrevlogmixin, mfrevlog.__class__):
>              def dirlog(self, dir):
> -                if not repo.narrowmatch().visitdir(dir[:-1] or '.'):
> -                    dirlog = excludeddirmanifestlog(dir)
> -                else:
> -                    dirlog = super(narrowmanifest, self).dirlog(dir)
> -                    makenarrowmanifest(dirlog, repo)
> -                return dirlog
> -        mf.__class__ = narrowmanifest
> +                result = super(narrowmanifestrevlog, self).dirlog(dir)
> +                makenarrowmanifestrevlog(result)
> +                return result
> +
> +        mfrevlog.__class__ = narrowmanifestrevlog
> +
> +def makenarrowmanifestlog(mfl, repo):
> +    class narrowmanifestlog(mfl.__class__):
> +        def get(self, dir, node, verify=True):
> +            if not repo.narrowmatch().visitdir(dir[:-1] or '.'):
> +                return excludeddirmanifestctx(dir, node)
> +            return super(narrowmanifestlog, self).get(dir, node, verify=verify)
> +    mfl.__class__ = narrowmanifestlog
>
>  def makenarrowfilelog(fl, narrowmatch):
>      if not isinstance(fl, narrowrevlogmixin):

Patch

diff --git a/src/narrowrepo.py b/src/narrowrepo.py
--- a/src/narrowrepo.py
+++ b/src/narrowrepo.py
@@ -37,11 +37,16 @@  def wraprepo(repo):
             narrowrevlog.makenarrowchangelog(cl)
             return cl
 
+        def _constructmanifest(self):
+            manifest = super(narrowrepository, self)._constructmanifest()
+            narrowrevlog.makenarrowmanifestrevlog(manifest)
+            return manifest
+
         @cacheprop('00manifest.i')
-        def manifest(self):
-            mf = super(narrowrepository, self).manifest
-            narrowrevlog.makenarrowmanifest(mf, self)
-            return mf
+        def manifestlog(self):
+            mfl = super(narrowrepository, self).manifestlog
+            narrowrevlog.makenarrowmanifestlog(mfl, self)
+            return mfl
 
         def file(self, f):
             fl = super(narrowrepository, self).file(f)
diff --git a/src/narrowrevlog.py b/src/narrowrevlog.py
--- a/src/narrowrevlog.py
+++ b/src/narrowrevlog.py
@@ -17,15 +17,6 @@  assert (revlog.REVIDX_KNOWN_FLAGS & ELLI
 revlog.REVIDX_KNOWN_FLAGS |= ELLIPSIS_NODE_FLAG
 
 
-if util.safehasattr(manifest, 'treemanifestctx'):
-    def inittreemanifestctx(orig, self, revlog, dir, node):
-        orig(self, revlog, dir, node)
-        if isinstance(self._revlog, excludeddirmanifestlog):
-            self._data = excludeddir(dir, node)
-
-    extensions.wrapfunction(manifest.treemanifestctx, '__init__',
-                            inittreemanifestctx)
-
 class narrowrevlogmixin(object):
     """Mixin for revlog subclasses to make them support narrow clones."""
 
@@ -77,15 +68,15 @@  class excludeddir(manifest.treemanifest)
     def copy(self):
         return self
 
-class excludeddirmanifestlog(manifest.manifest):
-    def __init__(self, dir):
+class excludeddirmanifestctx(manifest.treemanifestctx):
+    def __init__(self, dir, node):
         self._dir = dir
-        self._treeondisk = True
+        self._node = node
 
-    def read(self, node):
-        return excludeddir(self._dir, node)
+    def read(self):
+        return excludeddir(self._dir, self._node)
 
-    def add(self, *args):
+    def write(self, *args):
         # We should never write entries in dirlogs outside the narrow clone.
         # However, the method still gets called from writesubtree() in
         # _addtree(), so we need to handle it. We should possibly make that
@@ -93,17 +84,23 @@  class excludeddirmanifestlog(manifest.ma
         # in excludeddir instances).
         pass
 
-def makenarrowmanifest(mf, repo):
-    if not isinstance(mf, narrowrevlogmixin):
-        class narrowmanifest(narrowrevlogmixin, mf.__class__):
+def makenarrowmanifestrevlog(mfrevlog):
+    if not isinstance(mfrevlog, narrowrevlogmixin):
+        class narrowmanifestrevlog(narrowrevlogmixin, mfrevlog.__class__):
             def dirlog(self, dir):
-                if not repo.narrowmatch().visitdir(dir[:-1] or '.'):
-                    dirlog = excludeddirmanifestlog(dir)
-                else:
-                    dirlog = super(narrowmanifest, self).dirlog(dir)
-                    makenarrowmanifest(dirlog, repo)
-                return dirlog
-        mf.__class__ = narrowmanifest
+                result = super(narrowmanifestrevlog, self).dirlog(dir)
+                makenarrowmanifestrevlog(result)
+                return result
+
+        mfrevlog.__class__ = narrowmanifestrevlog
+
+def makenarrowmanifestlog(mfl, repo):
+    class narrowmanifestlog(mfl.__class__):
+        def get(self, dir, node, verify=True):
+            if not repo.narrowmatch().visitdir(dir[:-1] or '.'):
+                return excludeddirmanifestctx(dir, node)
+            return super(narrowmanifestlog, self).get(dir, node, verify=verify)
+    mfl.__class__ = narrowmanifestlog
 
 def makenarrowfilelog(fl, narrowmatch):
     if not isinstance(fl, narrowrevlogmixin):