Patchwork [2,of,6,v6,lazy-manifest] manifest: do parsing inside manifestdict contstructor

login
register
mail settings
Submitter Augie Fackler
Date March 7, 2015, 5:16 p.m.
Message ID <2524c117ce836e18402c.1425748577@imladris.local>
Download mbox | patch
Permalink /patch/7926/
State Accepted
Headers show

Comments

Augie Fackler - March 7, 2015, 5:16 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1425746592 18000
#      Sat Mar 07 11:43:12 2015 -0500
# Node ID 2524c117ce836e18402cac792361f0e44cac42c5
# Parent  a6865eef42791a2cc6ecba8f31e81c0555642ffc
manifest: do parsing inside manifestdict contstructor

This shape to the code will make using a C implementation of the
manifest storage easier.
Martin von Zweigbergk - March 9, 2015, 5:56 p.m.
On Sat, Mar 7, 2015 at 9:20 AM Augie Fackler <raf@durin42.com> wrote:

> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1425746592 18000
> #      Sat Mar 07 11:43:12 2015 -0500
> # Node ID 2524c117ce836e18402cac792361f0e44cac42c5
> # Parent  a6865eef42791a2cc6ecba8f31e81c0555642ffc
> manifest: do parsing inside manifestdict contstructor
>
> This shape to the code will make using a C implementation of the
> manifest storage easier.
>
> diff --git a/mercurial/manifest.py b/mercurial/manifest.py
> --- a/mercurial/manifest.py
> +++ b/mercurial/manifest.py
> @@ -20,17 +20,18 @@ def _parsemanifest(mfdict, fdict, lines)
>          else:
>              mfdict[f] = bin(n)
>
> -def _parse(lines):
> -    mfdict = manifestdict()
> +def _parse(lines, mfdict, flags):
>      try:
> -        parsers.parse_manifest(mfdict, mfdict._flags, lines)
> +        parsers.parse_manifest(mfdict, flags, lines)
>      except AttributeError:
> -        _parsemanifest(mfdict, mfdict._flags, lines)
> +        _parsemanifest(mfdict, flags, lines)
>      return mfdict
>

Just FYI, the return value is no longer used. I will probably make _parse a
method on the instance instead for my work tree manifests, so I can take
care of it then.


>
>  class manifestdict(dict):
> -    def __init__(self):
> +    def __init__(self, data=''):
>          self._flags = {}
> +        _parse(data, self, self._flags)
> +
>      def __setitem__(self, k, v):
>          assert v is not None
>          dict.__setitem__(self, k, v)
> @@ -250,7 +251,8 @@ class manifest(revlog.revlog):
>
>      def readdelta(self, node):
>          r = self.rev(node)
> -        return _parse(mdiff.patchtext(self.revdiff(self.deltaparent(r),
> r)))
> +        d = mdiff.patchtext(self.revdiff(self.deltaparent(r), r))
> +        return manifestdict(d)
>
>      def readfast(self, node):
>          '''use the faster of readdelta or read'''
> @@ -267,7 +269,7 @@ class manifest(revlog.revlog):
>              return self._mancache[node][0]
>          text = self.revision(node)
>          arraytext = array.array('c', text)
> -        m = _parse(text)
> +        m = manifestdict(text)
>          self._mancache[node] = (m, arraytext)
>          return m
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>

Patch

diff --git a/mercurial/manifest.py b/mercurial/manifest.py
--- a/mercurial/manifest.py
+++ b/mercurial/manifest.py
@@ -20,17 +20,18 @@  def _parsemanifest(mfdict, fdict, lines)
         else:
             mfdict[f] = bin(n)
 
-def _parse(lines):
-    mfdict = manifestdict()
+def _parse(lines, mfdict, flags):
     try:
-        parsers.parse_manifest(mfdict, mfdict._flags, lines)
+        parsers.parse_manifest(mfdict, flags, lines)
     except AttributeError:
-        _parsemanifest(mfdict, mfdict._flags, lines)
+        _parsemanifest(mfdict, flags, lines)
     return mfdict
 
 class manifestdict(dict):
-    def __init__(self):
+    def __init__(self, data=''):
         self._flags = {}
+        _parse(data, self, self._flags)
+
     def __setitem__(self, k, v):
         assert v is not None
         dict.__setitem__(self, k, v)
@@ -250,7 +251,8 @@  class manifest(revlog.revlog):
 
     def readdelta(self, node):
         r = self.rev(node)
-        return _parse(mdiff.patchtext(self.revdiff(self.deltaparent(r), r)))
+        d = mdiff.patchtext(self.revdiff(self.deltaparent(r), r))
+        return manifestdict(d)
 
     def readfast(self, node):
         '''use the faster of readdelta or read'''
@@ -267,7 +269,7 @@  class manifest(revlog.revlog):
             return self._mancache[node][0]
         text = self.revision(node)
         arraytext = array.array('c', text)
-        m = _parse(text)
+        m = manifestdict(text)
         self._mancache[node] = (m, arraytext)
         return m