mercurial/bundle2.py
changeset 24642 54e5c239c2d9
parent 24641 60fecc5b14a4
child 24648 5cac3accdaa1
equal deleted inserted replaced
24641:60fecc5b14a4 24642:54e5c239c2d9
   521         if util.safehasattr(self._fp, 'close'):
   521         if util.safehasattr(self._fp, 'close'):
   522             return self._fp.close()
   522             return self._fp.close()
   523 
   523 
   524 def getunbundler(ui, fp, header=None):
   524 def getunbundler(ui, fp, header=None):
   525     """return a valid unbundler object for a given header"""
   525     """return a valid unbundler object for a given header"""
   526     return unbundle20(ui, fp, header)
   526     if header is None:
       
   527         header = changegroup.readexactly(fp, 4)
       
   528         magic, version = header[0:2], header[2:4]
       
   529         if magic != 'HG':
       
   530             raise util.Abort(_('not a Mercurial bundle'))
       
   531         if version != '2Y':
       
   532             raise util.Abort(_('unknown bundle version %s') % version)
       
   533     unbundler = unbundle20(ui, fp)
       
   534     ui.debug('start processing of %s stream\n' % header)
       
   535     return unbundler
   527 
   536 
   528 class unbundle20(unpackermixin):
   537 class unbundle20(unpackermixin):
   529     """interpret a bundle2 stream
   538     """interpret a bundle2 stream
   530 
   539 
   531     This class is fed with a binary stream and yields parts through its
   540     This class is fed with a binary stream and yields parts through its
   532     `iterparts` methods."""
   541     `iterparts` methods."""
   533 
   542 
   534     def __init__(self, ui, fp, header=None):
   543     def __init__(self, ui, fp):
   535         """If header is specified, we do not read it out of the stream."""
   544         """If header is specified, we do not read it out of the stream."""
   536         self.ui = ui
   545         self.ui = ui
   537         super(unbundle20, self).__init__(fp)
   546         super(unbundle20, self).__init__(fp)
   538         if header is None:
       
   539             header = self._readexact(4)
       
   540             magic, version = header[0:2], header[2:4]
       
   541             if magic != 'HG':
       
   542                 raise util.Abort(_('not a Mercurial bundle'))
       
   543             if version != '2Y':
       
   544                 raise util.Abort(_('unknown bundle version %s') % version)
       
   545         self.ui.debug('start processing of %s stream\n' % header)
       
   546 
   547 
   547     @util.propertycache
   548     @util.propertycache
   548     def params(self):
   549     def params(self):
   549         """dictionary of stream level parameters"""
   550         """dictionary of stream level parameters"""
   550         self.ui.debug('reading bundle2 stream parameters\n')
   551         self.ui.debug('reading bundle2 stream parameters\n')