# HG changeset patch # User Pierre-Yves David # Date 2014-04-15 17:54:54 # Node ID 5ecfe76d0d963e8200930a0aefdc92442c606508 # Parent f9a9a6d63e89b9ed6b9c33cfd71ada6761eeb48e bundle2: make header reading optional The `readbundle` function will consume the 4 first bytes to dispatch between various unbundler. We introduce a way to inform `unbundle20` that the header has been read and it can be trusted. diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py --- a/mercurial/bundle2.py +++ b/mercurial/bundle2.py @@ -399,15 +399,17 @@ class unbundle20(unpackermixin): (this will eventually yield parts)""" - def __init__(self, ui, fp): + def __init__(self, ui, fp, header=None): + """If header is specified, we do not read it out of the stream.""" 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) + if header is None: + 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