[PATCH 1 of 8] bundle2: extract stream//unpack logic in an unpackermixin

Olle olle.lundberg at gmail.com
Sat Apr 12 17:14:42 CDT 2014


On Sun, Apr 13, 2014 at 12:08 AM, <pierre-yves.david at ens-lyon.org> wrote:

> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david at fb.com>
> # Date 1397243994 14400
> #      Fri Apr 11 15:19:54 2014 -0400
> # Node ID 24f7528f409dff53d1372df5015e59d331983311
> # Parent  3d38ebb586fe5a3bb74c68c2464f948ede39e63d
> bundle2: extract stream//unpack logic in an unpackermixin
>
> The coming `unbundlepart` will need the same kind of method than
> `unbundle20`
> for unpacking data from the stream. We extract them into a mixin class
> before
> the creation of `unbundlepart`.
>
> diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
> --- a/mercurial/bundle2.py
> +++ b/mercurial/bundle2.py
> @@ -371,35 +371,42 @@ class bundle20(object):
>                  value = urllib.quote(value)
>                  par = '%s=%s' % (par, value)
>              blocks.append(par)
>          return ' '.join(blocks)
>
> -class unbundle20(object):
> -    """interpret a bundle2 stream
> +class unpackermixing(object):
>
I think you mean mixin here

> +    """A mixing to extract bytes and struct data from a stream"""
>
same here

>
> -    (this will eventually yield parts)"""
> -
> -    def __init__(self, ui, fp):
> -        self.ui = ui
> +    def __init__(self, fp):
>          self._fp = fp
> -        header = self._readexact(4)
> -        magic, version = header[0:2], header[2:4]
> -        if magic != 'HG':
> -            raise util.Abort(_('not a Mercurial bundle'))
> -        if version != '20':
> -            raise util.Abort(_('unknown bundle version %s') % version)
> -        self.ui.debug('start processing of %s stream\n' % header)
>
>      def _unpack(self, format):
>          """unpack this struct format from the stream"""
>          data = self._readexact(struct.calcsize(format))
>          return _unpack(format, data)
>
>      def _readexact(self, size):
>          """read exactly <size> bytes from the stream"""
>          return changegroup.readexactly(self._fp, size)
>
> +
> +class unbundle20(unpackermixing):
>
and here

> +    """interpret a bundle2 stream
> +
> +    (this will eventually yield parts)"""
> +
> +    def __init__(self, ui, fp):
> +        self.ui = ui
> +        super(unbundle20, self).__init__(fp)
> +        header = self._readexact(4)
> +        magic, version = header[0:2], header[2:4]
> +        if magic != 'HG':
> +            raise util.Abort(_('not a Mercurial bundle'))
> +        if version != '20':
> +            raise util.Abort(_('unknown bundle version %s') % version)
> +        self.ui.debug('start processing of %s stream\n' % header)
> +
>      @util.propertycache
>      def params(self):
>          """dictionnary of stream level parameters"""
>          self.ui.debug('reading bundle2 stream parameters\n')
>          params = {}
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>



-- 
Olle
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20140413/c81500d9/attachment.html>


More information about the Mercurial-devel mailing list