bundle2: update all ``addpart`` callers to ``newpart``
The new method is what we want in all current cases.
--- a/mercurial/bundle2.py Fri May 23 15:54:18 2014 -0700
+++ b/mercurial/bundle2.py Fri May 23 15:59:19 2014 -0700
@@ -321,11 +321,10 @@
if output is not None:
output = op.ui.popbuffer()
if output:
- outpart = bundlepart('b2x:output',
- advisoryparams=[('in-reply-to',
- str(part.id))],
- data=output)
- op.reply.addpart(outpart)
+ op.reply.newpart('b2x:output',
+ advisoryparams=[('in-reply-to',
+ str(part.id))],
+ data=output)
part.read()
except Exception, exc:
if part is not None:
@@ -409,7 +408,7 @@
self._parts.append(part)
def newpart(self, typeid, *args, **kwargs):
- """create a new part for the containers"""
+ """create a new part and add it to the containers"""
part = bundlepart(typeid, *args, **kwargs)
self.addpart(part)
return part
--- a/mercurial/exchange.py Fri May 23 15:54:18 2014 -0700
+++ b/mercurial/exchange.py Fri May 23 15:59:19 2014 -0700
@@ -214,16 +214,13 @@
bundler = bundle2.bundle20(pushop.ui, caps)
# create reply capability
capsblob = bundle2.encodecaps(pushop.repo.bundle2caps)
- bundler.addpart(bundle2.bundlepart('b2x:replycaps', data=capsblob))
+ bundler.newpart('b2x:replycaps', data=capsblob)
if not pushop.force:
- part = bundle2.bundlepart('B2X:CHECK:HEADS',
- data=iter(pushop.remoteheads))
- bundler.addpart(part)
+ bundler.newpart('B2X:CHECK:HEADS', data=iter(pushop.remoteheads))
extrainfo = _pushbundle2extraparts(pushop, bundler)
# add the changegroup bundle
cg = changegroup.getlocalbundle(pushop.repo, 'push', pushop.outgoing)
- cgpart = bundle2.bundlepart('B2X:CHANGEGROUP', data=cg.getchunks())
- bundler.addpart(cgpart)
+ cgpart = bundler.newpart('B2X:CHANGEGROUP', data=cg.getchunks())
stream = util.chunkbuffer(bundler.getchunks())
try:
reply = pushop.remote.unbundle(stream, ['force'], 'push')
@@ -670,8 +667,7 @@
b2caps.update(bundle2.decodecaps(blob))
bundler = bundle2.bundle20(repo.ui, b2caps)
if cg:
- part = bundle2.bundlepart('b2x:changegroup', data=cg.getchunks())
- bundler.addpart(part)
+ bundler.newpart('b2x:changegroup', data=cg.getchunks())
_getbundleextrapart(bundler, repo, source, heads=heads, common=common,
bundlecaps=bundlecaps, **kwargs)
return util.chunkbuffer(bundler.getchunks())
--- a/mercurial/wireproto.py Fri May 23 15:54:18 2014 -0700
+++ b/mercurial/wireproto.py Fri May 23 15:59:19 2014 -0700
@@ -805,9 +805,7 @@
os.unlink(tempname)
except bundle2.UnknownPartError, exc:
bundler = bundle2.bundle20(repo.ui)
- part = bundle2.bundlepart('B2X:ERROR:UNKNOWNPART',
- [('parttype', str(exc))])
- bundler.addpart(part)
+ bundler.newpart('B2X:ERROR:UNKNOWNPART', [('parttype', str(exc))])
return streamres(bundler.getchunks())
except util.Abort, inst:
# The old code we moved used sys.stderr directly.
@@ -829,9 +827,7 @@
except error.PushRaced, exc:
if getattr(exc, 'duringunbundle2', False):
bundler = bundle2.bundle20(repo.ui)
- part = bundle2.bundlepart('B2X:ERROR:PUSHRACED',
- [('message', str(exc))])
- bundler.addpart(part)
+ bundler.newpart('B2X:ERROR:PUSHRACED', [('message', str(exc))])
return streamres(bundler.getchunks())
else:
return pusherr(str(exc))
--- a/tests/test-bundle2.t Fri May 23 15:54:18 2014 -0700
+++ b/tests/test-bundle2.t Fri May 23 15:59:19 2014 -0700
@@ -47,9 +47,7 @@
> op.ui.write('received ping request (id %i)\n' % part.id)
> if op.reply is not None and 'ping-pong' in op.reply.capabilities:
> op.ui.write_err('replying to ping request (id %i)\n' % part.id)
- > rpart = bundle2.bundlepart('test:pong',
- > [('in-reply-to', str(part.id))])
- > op.reply.addpart(rpart)
+ > op.reply.newpart('test:pong', [('in-reply-to', str(part.id))])
>
> @bundle2.parthandler('test:debugreply')
> def debugreply(op, part):
@@ -83,11 +81,11 @@
>
> if opts['reply']:
> capsstring = 'ping-pong\nelephants=babar,celeste\ncity%3D%21=celeste%2Cville'
- > bundler.addpart(bundle2.bundlepart('b2x:replycaps', data=capsstring))
+ > bundler.newpart('b2x:replycaps', data=capsstring)
>
> if opts['pushrace']:
> dummynode = '01234567890123456789'
- > bundler.addpart(bundle2.bundlepart('b2x:check:heads', data=dummynode))
+ > bundler.newpart('b2x:check:heads', data=dummynode)
>
> revs = opts['rev']
> if 'rev' in opts:
@@ -99,31 +97,22 @@
> headcommon = [c.node() for c in repo.set('parents(%ld) - %ld', revs, revs)]
> outgoing = discovery.outgoing(repo.changelog, headcommon, headmissing)
> cg = changegroup.getlocalbundle(repo, 'test:bundle2', outgoing, None)
- > part = bundle2.bundlepart('b2x:changegroup', data=cg.getchunks())
- > bundler.addpart(part)
+ > bundler.newpart('b2x:changegroup', data=cg.getchunks())
>
> if opts['parts']:
- > part = bundle2.bundlepart('test:empty')
- > bundler.addpart(part)
+ > bundler.newpart('test:empty')
> # add a second one to make sure we handle multiple parts
- > part = bundle2.bundlepart('test:empty')
- > bundler.addpart(part)
- > part = bundle2.bundlepart('test:song', data=ELEPHANTSSONG)
- > bundler.addpart(part)
- > part = bundle2.bundlepart('test:debugreply')
- > bundler.addpart(part)
- > part = bundle2.bundlepart('test:math',
+ > bundler.newpart('test:empty')
+ > bundler.newpart('test:song', data=ELEPHANTSSONG)
+ > bundler.newpart('test:debugreply')
+ > bundler.newpart('test:math',
> [('pi', '3.14'), ('e', '2.72')],
> [('cooking', 'raw')],
> '42')
- > bundler.addpart(part)
> if opts['unknown']:
- > part = bundle2.bundlepart('test:UNKNOWN',
- > data='some random content')
- > bundler.addpart(part)
+ > bundler.newpart('test:UNKNOWN', data='some random content')
> if opts['parts']:
- > part = bundle2.bundlepart('test:ping')
- > bundler.addpart(part)
+ > bundler.newpart('test:ping')
>
> if path is None:
> file = sys.stdout
@@ -938,14 +927,12 @@
> reason = pushop.ui.config('failpush', 'reason', None)
> part = None
> if reason == 'abort':
- > part = bundle2.bundlepart('test:abort')
+ > bundler.newpart('test:abort')
> if reason == 'unknown':
- > part = bundle2.bundlepart('TEST:UNKNOWN')
+ > bundler.newpart('TEST:UNKNOWN')
> if reason == 'race':
> # 20 Bytes of crap
- > part = bundle2.bundlepart('b2x:check:heads', data='01234567890123456789')
- > if part is not None:
- > bundler.addpart(part)
+ > bundler.newpart('b2x:check:heads', data='01234567890123456789')
> return extradata
>
> @bundle2.parthandler("test:abort")