changeset 21066:5ecfe76d0d96

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.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Tue, 15 Apr 2014 13:54:54 -0400
parents f9a9a6d63e89
children 7974aa88868e
files mercurial/bundle2.py
diffstat 1 files changed, 9 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/bundle2.py	Tue Apr 15 13:42:45 2014 -0400
+++ b/mercurial/bundle2.py	Tue Apr 15 13:54:54 2014 -0400
@@ -399,15 +399,17 @@
 
     (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