[PATCH 7 of 7] bundle2-localpeer: properly propagate the server output on error (issue4594)

Pierre-Yves David pierre-yves.david at ens-lyon.org
Thu Apr 16 04:25:49 CDT 2015


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1429171311 14400
#      Thu Apr 16 04:01:51 2015 -0400
# Node ID 1e4021549a5155bef6b41ceccbd1becedc029422
# Parent  14b4d54ac72d694498c899df4fd180d144fcac7f
bundle2-localpeer: properly propagate the server output on error (issue4594)

In case of errors, output parts salvaged from the reply bundle needs to be
processed for outputting their content. This concludes our quest for fixing
issue4594.

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -134,10 +134,25 @@ class localpeer(peer.peerrepository):
                     # API is finally improved.
                     stream = util.chunkbuffer(ret.getchunks())
                     ret = bundle2.getunbundler(self.ui, stream)
                 return ret
             except Exception, exc:
+                # If the exception contains output salvaged from a bundle2
+                # reply, we need to make sure it is printed before continuing
+                # to fails. So we build a bundle2 with such output and consume
+                # it directly.
+                #
+                # This is not very elegant but allows a "simple" solution for
+                # issue4594
+                output = getattr(exc, '_bundle2salvagedoutput', ())
+                if output:
+                    bundler = bundle2.bundle20(self._repo.ui)
+                    for out in output:
+                        bundler.addpart(out)
+                    stream = util.chunkbuffer(bundler.getchunks())
+                    b = bundle2.getunbundler(self.ui, stream)
+                    bundle2.processbundle(self._repo, b)
                 raise
         except error.PushRaced, exc:
             raise error.ResponseError(_('push failed:'), str(exc))
 
     def lock(self):
diff --git a/tests/test-bundle2-exchange.t b/tests/test-bundle2-exchange.t
--- a/tests/test-bundle2-exchange.t
+++ b/tests/test-bundle2-exchange.t
@@ -559,10 +559,14 @@ Doing the actual push: hook abort
   pushing to other
   searching for changes
   pre-close-tip:e7ec4e813ba6 draft 
   transaction abort!
   rollback completed
+  remote: adding changesets
+  remote: adding manifests
+  remote: adding file changes
+  remote: added 1 changesets with 1 changes to 1 files
   abort: pretxnclose.failpush hook exited with status 1
   [255]
 
   $ hg -R main push ssh://user@dummy/other -r e7ec4e813ba6
   pushing to ssh://user@dummy/other


More information about the Mercurial-devel mailing list