diff -r c827a0028e6f -r a813caca89b3 mercurial/bundle2.py --- a/mercurial/bundle2.py Sun Apr 13 12:21:09 2014 -0400 +++ b/mercurial/bundle2.py Fri Apr 11 15:19:54 2014 -0400 @@ -373,21 +373,11 @@ blocks.append(par) return ' '.join(blocks) -class unbundle20(object): - """interpret a bundle2 stream +class unpackermixin(object): + """A mixin 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""" @@ -398,6 +388,23 @@ """read exactly bytes from the stream""" return changegroup.readexactly(self._fp, size) + +class unbundle20(unpackermixin): + """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"""