bundle2: have ``newpart`` automatically add the part to the bundle
authorPierre-Yves David <pierre-yves.david@fb.com>
Fri, 23 May 2014 15:54:18 -0700
changeset 21599 57cd844d7a5b
parent 21598 1b0dbb91de5b
child 21600 5e08f3b65510
bundle2: have ``newpart`` automatically add the part to the bundle The created part is automatically added to the bundle as this is most certainly the intent of the user code.
mercurial/bundle2.py
--- a/mercurial/bundle2.py	Fri May 23 15:45:46 2014 -0700
+++ b/mercurial/bundle2.py	Fri May 23 15:54:18 2014 -0700
@@ -381,7 +381,7 @@
 class bundle20(object):
     """represent an outgoing bundle2 container
 
-    Use the `addparam` method to add stream level parameter. and `addpart` to
+    Use the `addparam` method to add stream level parameter. and `newpart` to
     populate it. Then call `getchunks` to retrieve all the binary chunks of
     data that compose the bundle2 container."""
 
@@ -411,6 +411,7 @@
     def newpart(self, typeid, *args, **kwargs):
         """create a new part for the containers"""
         part = bundlepart(typeid, *args, **kwargs)
+        self.addpart(part)
         return part
 
     # methods used to generate the bundle2 stream
@@ -712,10 +713,9 @@
     if op.reply is not None:
         # This is definitly not the final form of this
         # return. But one need to start somewhere.
-        part = op.reply.newpart('b2x:reply:changegroup', (),
-                                [('in-reply-to', str(inpart.id)),
-                                ('return', '%i' % ret)])
-        op.reply.addpart(part)
+        op.reply.newpart('b2x:reply:changegroup', (),
+                         [('in-reply-to', str(inpart.id)),
+                          ('return', '%i' % ret)])
     assert not inpart.read()
 
 @parthandler('b2x:reply:changegroup')