Patchwork [STABLE] bundle2: only use callable return as reply handler

login
register
mail settings
Submitter Pierre-Yves David
Date July 25, 2014, 2:50 p.m.
Message ID <6f9815d0ce10d8bdd1a8.1406299835@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/5200/
State Accepted
Commit dab31290c7ebdaafadfdb574d37c3285fdc7795f
Headers show

Comments

Pierre-Yves David - July 25, 2014, 2:50 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1404310428 -7200
#      Wed Jul 02 16:13:48 2014 +0200
# Branch stable
# Node ID 6f9815d0ce10d8bdd1a892b81d2933669fd04909
# Parent  54ff2789d75e0662a536b3da61ca25c07436966b
bundle2: only use callable return as reply handler

When a bundle2 parts generator returns a non callable value, it should not be
used as a reply handler. The changegroup part generator is already having this
case of behavior when there is no changegroup to push. This changeset prevent a
crash for user of the experimentable bundle2 feature.
Matt Mackall - July 25, 2014, 4:10 p.m.
On Fri, 2014-07-25 at 16:50 +0200, pierre-yves.david@ens-lyon.org wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@fb.com>
> # Date 1404310428 -7200
> #      Wed Jul 02 16:13:48 2014 +0200
> # Branch stable
> # Node ID 6f9815d0ce10d8bdd1a892b81d2933669fd04909
> # Parent  54ff2789d75e0662a536b3da61ca25c07436966b
> bundle2: only use callable return as reply handler

Queued for stable, thanks.

Patch

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -240,11 +240,12 @@  def _pushbundle2(pushop):
     capsblob = bundle2.encodecaps(pushop.repo.bundle2caps)
     bundler.newpart('b2x:replycaps', data=capsblob)
     replyhandlers = []
     for partgen in bundle2partsgenerators:
         ret = partgen(pushop, bundler)
-        replyhandlers.append(ret)
+        if callable(ret):
+            replyhandlers.append(ret)
     # do not push if nothing to push
     if bundler.nbparts <= 1:
         return
     stream = util.chunkbuffer(bundler.getchunks())
     try:
diff --git a/tests/test-bundle2.t b/tests/test-bundle2.t
--- a/tests/test-bundle2.t
+++ b/tests/test-bundle2.t
@@ -955,11 +955,10 @@  Setting up
   >     if reason == 'unknown':
   >         bundler.newpart('TEST:UNKNOWN')
   >     if reason == 'race':
   >         # 20 Bytes of crap
   >         bundler.newpart('b2x:check:heads', data='01234567890123456789')
-  >     return lambda op: None
   > 
   > @bundle2.parthandler("test:abort")
   > def handleabort(op, part):
   >     raise util.Abort('Abandon ship!', hint="don't panic")
   >