Patchwork [4,of,4] manifest: move dirlog up to manifestrevlog

login
register
mail settings
Submitter Durham Goode
Date Sept. 13, 2016, 11:30 p.m.
Message ID <e141fd3c3455ce88ebcc.1473809447@dev111.prn1.facebook.com>
Download mbox | patch
Permalink /patch/16613/
State Accepted
Headers show

Comments

Durham Goode - Sept. 13, 2016, 11:30 p.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1473807641 25200
#      Tue Sep 13 16:00:41 2016 -0700
# Node ID e141fd3c3455ce88ebcca85f166c8d42b682bc2d
# Parent  460e9339cd89add743326b16463f04737a0b4db0
manifest: move dirlog up to manifestrevlog

This removes dirlog and it's associated cache from manifest and puts it in
manifestrevlog. The notion of there being sub-logs is specific to the revlog
implementation, and therefore belongs on the revlog class.

This patch will enable future patches to move the serialization logic for
manifests onto manifestrevlog, which will allow us to move manifest.add onto
manifestlog in a way that it just calls out to manifestrevlog for the
serialization.
via Mercurial-devel - Sept. 14, 2016, 4:56 p.m.
Looks good. Pushed to committed, thanks.

On Tue, Sep 13, 2016 at 4:30 PM, Durham Goode <durham@fb.com> wrote:
> # HG changeset patch
> # User Durham Goode <durham@fb.com>
> # Date 1473807641 25200
> #      Tue Sep 13 16:00:41 2016 -0700
> # Node ID e141fd3c3455ce88ebcca85f166c8d42b682bc2d
> # Parent  460e9339cd89add743326b16463f04737a0b4db0
> manifest: move dirlog up to manifestrevlog
>
> This removes dirlog and it's associated cache from manifest and puts it in
> manifestrevlog. The notion of there being sub-logs is specific to the revlog
> implementation, and therefore belongs on the revlog class.
>
> This patch will enable future patches to move the serialization logic for
> manifests onto manifestrevlog, which will allow us to move manifest.add onto
> manifestlog in a way that it just calls out to manifestrevlog for the
> serialization.
>
> diff --git a/mercurial/manifest.py b/mercurial/manifest.py
> --- a/mercurial/manifest.py
> +++ b/mercurial/manifest.py
> @@ -896,7 +896,7 @@ class manifestrevlog(revlog.revlog):
>      '''A revlog that stores manifest texts. This is responsible for caching the
>      full-text manifest contents.
>      '''
> -    def __init__(self, opener, dir=''):
> +    def __init__(self, opener, dir='', dirlogcache=None):
>          # During normal operations, we expect to deal with not more than four
>          # revs at a time (such as during commit --amend). When rebasing large
>          # stacks of commits, the number can go up, hence the config knob below.
> @@ -921,6 +921,11 @@ class manifestrevlog(revlog.revlog):
>                  dir = dir + '/'
>              indexfile = "meta/" + dir + "00manifest.i"
>          self._dir = dir
> +        # The dirlogcache is kept on the root manifest log
> +        if dir:
> +            self._dirlogcache = dirlogcache
> +        else:
> +            self._dirlogcache = {'': self}
>
>          super(manifestrevlog, self).__init__(opener, indexfile)
>
> @@ -931,6 +936,15 @@ class manifestrevlog(revlog.revlog):
>      def clearcaches(self):
>          super(manifestrevlog, self).clearcaches()
>          self._fulltextcache.clear()
> +        self._dirlogcache = {'': self}
> +
> +    def dirlog(self, dir):
> +        if dir:
> +            assert self._treeondisk
> +        if dir not in self._dirlogcache:
> +            self._dirlogcache[dir] = manifestrevlog(self.opener, dir,
> +                                                    self._dirlogcache)
> +        return self._dirlogcache[dir]
>
>  class manifestlog(object):
>      """A collection class representing the collection of manifest snapshots
> @@ -1115,12 +1129,7 @@ class manifest(manifestrevlog):
>              usetreemanifest = opts.get('treemanifest', usetreemanifest)
>          self._mancache = util.lrucachedict(cachesize)
>          self._treeinmem = usetreemanifest
> -        super(manifest, self).__init__(opener, dir=dir)
> -        # The dirlogcache is kept on the root manifest log
> -        if dir:
> -            self._dirlogcache = dirlogcache
> -        else:
> -            self._dirlogcache = {'': self}
> +        super(manifest, self).__init__(opener, dir=dir, dirlogcache=dirlogcache)
>
>      def _newmanifest(self, data=''):
>          if self._treeinmem:
> @@ -1128,6 +1137,9 @@ class manifest(manifestrevlog):
>          return manifestdict(data)
>
>      def dirlog(self, dir):
> +        """This overrides the base revlog implementation to allow construction
> +        'manifest' types instead of manifestrevlog types. This is only needed
> +        until we migrate off the 'manifest' type."""
>          if dir:
>              assert self._treeondisk
>          if dir not in self._dirlogcache:
> @@ -1282,4 +1294,3 @@ class manifest(manifestrevlog):
>      def clearcaches(self):
>          super(manifest, self).clearcaches()
>          self._mancache.clear()
> -        self._dirlogcache = {'': self}
> _______________________________________________
> 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
@@ -896,7 +896,7 @@  class manifestrevlog(revlog.revlog):
     '''A revlog that stores manifest texts. This is responsible for caching the
     full-text manifest contents.
     '''
-    def __init__(self, opener, dir=''):
+    def __init__(self, opener, dir='', dirlogcache=None):
         # During normal operations, we expect to deal with not more than four
         # revs at a time (such as during commit --amend). When rebasing large
         # stacks of commits, the number can go up, hence the config knob below.
@@ -921,6 +921,11 @@  class manifestrevlog(revlog.revlog):
                 dir = dir + '/'
             indexfile = "meta/" + dir + "00manifest.i"
         self._dir = dir
+        # The dirlogcache is kept on the root manifest log
+        if dir:
+            self._dirlogcache = dirlogcache
+        else:
+            self._dirlogcache = {'': self}
 
         super(manifestrevlog, self).__init__(opener, indexfile)
 
@@ -931,6 +936,15 @@  class manifestrevlog(revlog.revlog):
     def clearcaches(self):
         super(manifestrevlog, self).clearcaches()
         self._fulltextcache.clear()
+        self._dirlogcache = {'': self}
+
+    def dirlog(self, dir):
+        if dir:
+            assert self._treeondisk
+        if dir not in self._dirlogcache:
+            self._dirlogcache[dir] = manifestrevlog(self.opener, dir,
+                                                    self._dirlogcache)
+        return self._dirlogcache[dir]
 
 class manifestlog(object):
     """A collection class representing the collection of manifest snapshots
@@ -1115,12 +1129,7 @@  class manifest(manifestrevlog):
             usetreemanifest = opts.get('treemanifest', usetreemanifest)
         self._mancache = util.lrucachedict(cachesize)
         self._treeinmem = usetreemanifest
-        super(manifest, self).__init__(opener, dir=dir)
-        # The dirlogcache is kept on the root manifest log
-        if dir:
-            self._dirlogcache = dirlogcache
-        else:
-            self._dirlogcache = {'': self}
+        super(manifest, self).__init__(opener, dir=dir, dirlogcache=dirlogcache)
 
     def _newmanifest(self, data=''):
         if self._treeinmem:
@@ -1128,6 +1137,9 @@  class manifest(manifestrevlog):
         return manifestdict(data)
 
     def dirlog(self, dir):
+        """This overrides the base revlog implementation to allow construction
+        'manifest' types instead of manifestrevlog types. This is only needed
+        until we migrate off the 'manifest' type."""
         if dir:
             assert self._treeondisk
         if dir not in self._dirlogcache:
@@ -1282,4 +1294,3 @@  class manifest(manifestrevlog):
     def clearcaches(self):
         super(manifest, self).clearcaches()
         self._mancache.clear()
-        self._dirlogcache = {'': self}