Submitter | Pierre-Yves David |
---|---|
Date | April 12, 2014, 10:08 p.m. |
Message ID | <24f7528f409dff53d137.1397340520@marginatus.alto.octopoid.net> |
Download | mbox | patch |
Permalink | /patch/4303/ |
State | Accepted |
Headers | show |
Comments
On Sun, Apr 13, 2014 at 12:08 AM, <pierre-yves.david@ens-lyon.org> wrote: > # HG changeset patch > # User Pierre-Yves David <pierre-yves.david@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@selenic.com > http://selenic.com/mailman/listinfo/mercurial-devel >
On 04/12/2014 06:14 PM, Olle wrote: > > > > On Sun, Apr 13, 2014 at 12:08 AM, <pierre-yves.david@ens-lyon.org > <mailto:pierre-yves.david@ens-lyon.org>> wrote: > > # HG changeset patch > # User Pierre-Yves David <pierre-yves.david@fb.com > <mailto:pierre-yves.david@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 facepalm
Patch
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): + """A mixing to extract bytes and struct data from a stream""" - (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): + """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 = {}