# HG changeset patch # User Pierre-Yves David # Date 1400885146 25200 # Node ID 1b0dbb91de5b435976822a4200d28941a2e70ab6 # Parent 1daad9dcdba28253b801e8b3952a19a4f58e66b3 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. diff -r 1daad9dcdba2 -r 1b0dbb91de5b mercurial/bundle2.py --- a/mercurial/bundle2.py Thu May 22 10:48:37 2014 -0700 +++ b/mercurial/bundle2.py Fri May 23 15:45:46 2014 -0700 @@ -408,6 +408,11 @@ part.id = len(self._parts) # very cheap counter self._parts.append(part) + def newpart(self, typeid, *args, **kwargs): + """create a new part for the containers""" + part = bundlepart(typeid, *args, **kwargs) + return part + # methods used to generate the bundle2 stream def getchunks(self): self.ui.debug('start emission of %s stream\n' % _magicstring) @@ -707,9 +712,9 @@ if op.reply is not None: # This is definitly not the final form of this # return. But one need to start somewhere. - part = bundlepart('b2x:reply:changegroup', (), - [('in-reply-to', str(inpart.id)), - ('return', '%i' % ret)]) + part = op.reply.newpart('b2x:reply:changegroup', (), + [('in-reply-to', str(inpart.id)), + ('return', '%i' % ret)]) op.reply.addpart(part) assert not inpart.read()