# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 2014-04-17 06:01:38
# Node ID 5bb5d4ba14e55c32a42f6e9151b3a364cd7d0acc
# Parent  15039ce3e4a39c85d30113b12dc44f5907d62450

bundle2: transmit capabilities to getbundle during pull

Bundle2 capabilities of the client are sent to the server in the bundlecaps
argument of `getbundle`.

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -546,6 +546,8 @@ def _pullbundle2(pullop):
 
     For now, the only supported data are changegroup."""
     kwargs = {'bundlecaps': set(['HG20'])}
+    capsblob = bundle2.encodecaps(pullop.repo.bundle2caps)
+    kwargs['bundlecaps'].add('bundle2=' + urllib.quote(capsblob))
     # pulling changegroup
     pullop.todosteps.remove('changegroup')
     if not pullop.fetch:
@@ -660,7 +662,12 @@ def getbundle(repo, source, heads=None, 
         return cg
     # very crude first implementation,
     # the bundle API will change and the generation will be done lazily.
-    bundler = bundle2.bundle20(repo.ui)
+    b2caps = {}
+    for bcaps in bundlecaps:
+        if bcaps.startswith('bundle2='):
+            blob = urllib.unquote(bcaps[len('bundle2='):])
+            b2caps.update(bundle2.decodecaps(blob))
+    bundler = bundle2.bundle20(repo.ui, b2caps)
     part = bundle2.bundlepart('changegroup', data=cg.getchunks())
     bundler.addpart(part)
     return util.chunkbuffer(bundler.getchunks())