comparison mercurial/bundle2.py @ 21598:1b0dbb91de5b

bundle2: add a ``newpart`` method to ``bundle20`` Creating new parts is the most common operation people do when exposed to a bundler. We create a dedicated method on the bundler object for it. This will simplify the code and also avoid having to import the ``mercurial.bundle2`` module in multiple places. One part creators have been updated for testing purpose.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Fri, 23 May 2014 15:45:46 -0700
parents 1daad9dcdba2
children 57cd844d7a5b
comparison
equal deleted inserted replaced
21597:1daad9dcdba2 21598:1b0dbb91de5b
405 405
406 Parts contains the actual applicative payload.""" 406 Parts contains the actual applicative payload."""
407 assert part.id is None 407 assert part.id is None
408 part.id = len(self._parts) # very cheap counter 408 part.id = len(self._parts) # very cheap counter
409 self._parts.append(part) 409 self._parts.append(part)
410
411 def newpart(self, typeid, *args, **kwargs):
412 """create a new part for the containers"""
413 part = bundlepart(typeid, *args, **kwargs)
414 return part
410 415
411 # methods used to generate the bundle2 stream 416 # methods used to generate the bundle2 stream
412 def getchunks(self): 417 def getchunks(self):
413 self.ui.debug('start emission of %s stream\n' % _magicstring) 418 self.ui.debug('start emission of %s stream\n' % _magicstring)
414 yield _magicstring 419 yield _magicstring
705 ret = changegroup.addchangegroup(op.repo, cg, 'bundle2', 'bundle2') 710 ret = changegroup.addchangegroup(op.repo, cg, 'bundle2', 'bundle2')
706 op.records.add('changegroup', {'return': ret}) 711 op.records.add('changegroup', {'return': ret})
707 if op.reply is not None: 712 if op.reply is not None:
708 # This is definitly not the final form of this 713 # This is definitly not the final form of this
709 # return. But one need to start somewhere. 714 # return. But one need to start somewhere.
710 part = bundlepart('b2x:reply:changegroup', (), 715 part = op.reply.newpart('b2x:reply:changegroup', (),
711 [('in-reply-to', str(inpart.id)), 716 [('in-reply-to', str(inpart.id)),
712 ('return', '%i' % ret)]) 717 ('return', '%i' % ret)])
713 op.reply.addpart(part) 718 op.reply.addpart(part)
714 assert not inpart.read() 719 assert not inpart.read()
715 720
716 @parthandler('b2x:reply:changegroup') 721 @parthandler('b2x:reply:changegroup')
717 def handlechangegroup(op, inpart): 722 def handlechangegroup(op, inpart):