Mercurial > hg
changeset 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 |
files | mercurial/bundle2.py |
diffstat | 1 files changed, 8 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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()