Mercurial > public > mercurial-scm > hg
comparison mercurial/bundle2.py @ 21131:b7435117d951
bundle2: capture remote stdout while unbundling
When a reply is built, the bundle processing will capture the output of each
handler and sends it to the client in a dedicated part.
As a side effect, this add a "remote: " prefix to destination output on local
push. This is considered okay for now as:
1. bundle2 is still experimental,
2. Matt said he could be okay to change output for bundle2,
3. This keeps the implementation simple.
This changeset does it for stdout only. stderr will be done in a future changeset.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Wed, 16 Apr 2014 14:22:24 -0400 |
parents | 1ff06386217f |
children | bef4a2adc532 |
comparison
equal
deleted
inserted
replaced
21130:1ff06386217f | 21131:b7435117d951 |
---|---|
305 | 305 |
306 # handler is called outside the above try block so that we don't | 306 # handler is called outside the above try block so that we don't |
307 # risk catching KeyErrors from anything other than the | 307 # risk catching KeyErrors from anything other than the |
308 # parthandlermapping lookup (any KeyError raised by handler() | 308 # parthandlermapping lookup (any KeyError raised by handler() |
309 # itself represents a defect of a different variety). | 309 # itself represents a defect of a different variety). |
310 handler(op, part) | 310 output = None |
311 if op.reply is not None: | |
312 op.ui.pushbuffer() | |
313 output = '' | |
314 try: | |
315 handler(op, part) | |
316 finally: | |
317 if output is not None: | |
318 output = op.ui.popbuffer() | |
319 if output: | |
320 outpart = bundlepart('output', | |
321 advisoryparams=[('in-reply-to', | |
322 str(part.id))], | |
323 data=output) | |
324 op.reply.addpart(outpart) | |
311 part.read() | 325 part.read() |
312 except Exception: | 326 except Exception: |
313 if part is not None: | 327 if part is not None: |
314 # consume the bundle content | 328 # consume the bundle content |
315 part.read() | 329 part.read() |
670 h = inpart.read(20) | 684 h = inpart.read(20) |
671 assert not h | 685 assert not h |
672 if heads != op.repo.heads(): | 686 if heads != op.repo.heads(): |
673 raise exchange.PushRaced() | 687 raise exchange.PushRaced() |
674 | 688 |
689 @parthandler('output') | |
690 def handleoutput(op, inpart): | |
691 """forward output captured on the server to the client""" | |
692 for line in inpart.read().splitlines(): | |
693 op.ui.write(('remote: %s\n' % line)) | |
694 | |
675 @parthandler('replycaps') | 695 @parthandler('replycaps') |
676 def handlereplycaps(op, inpart): | 696 def handlereplycaps(op, inpart): |
677 """Notify that a reply bundle should be created | 697 """Notify that a reply bundle should be created |
678 | 698 |
679 Will convey bundle capability at some point too.""" | 699 Will convey bundle capability at some point too.""" |
680 if op.reply is None: | 700 if op.reply is None: |
681 op.reply = bundle20(op.ui) | 701 op.reply = bundle20(op.ui) |
702 |