bundle2: support for capabilities with values
The capabilities attributes of `bundle20` is now a dictionary and the reply caps
can encode capabilities with values.
--- a/mercurial/bundle2.py Thu Apr 17 11:32:30 2014 -0400
+++ b/mercurial/bundle2.py Thu Apr 17 11:44:49 2014 -0400
@@ -344,7 +344,7 @@
self.ui = ui
self._params = []
self._parts = []
- self.capabilities = set(capabilities)
+ self.capabilities = dict(capabilities)
def addparam(self, name, value=None):
"""add a stream level parameter"""
@@ -697,8 +697,22 @@
def handlereplycaps(op, inpart):
"""Notify that a reply bundle should be created
- the part payload is a list of capabilities (one per line)"""
- caps = [c for c in inpart.read().splitlines() if c]
+ The part payload is a list of capabilities (one per line)
+ Capabilities may have values using a line of form::
+
+ capability=value1,value2,value3
+
+ The value are alway a list."""
+ caps = {}
+ for line in inpart.read().splitlines():
+ if not line:
+ continue
+ if '=' not in line:
+ key, vals = line, ()
+ else:
+ key, vals = line.split('=', 1)
+ vals = vals.split(',')
+ caps[key] = vals
if op.reply is None:
op.reply = bundle20(op.ui, caps)
--- a/tests/test-bundle2.t Thu Apr 17 11:32:30 2014 -0400
+++ b/tests/test-bundle2.t Thu Apr 17 11:44:49 2014 -0400
@@ -51,6 +51,9 @@
> op.ui.write('debugreply: capabilities:\n')
> for cap in sorted(op.reply.capabilities):
> op.ui.write('debugreply: %r\n' % cap)
+ > for val in op.reply.capabilities[cap]:
+ > op.ui.write('debugreply: %r\n' % val)
+ >
> @command('bundle2',
> [('', 'param', [], 'stream level parameter'),
> ('', 'unknown', False, 'include an unknown mandatory part in the bundle'),
@@ -69,7 +72,7 @@
> raise util.Abort('%s' % exc)
>
> if opts['reply']:
- > capsstring = 'ping-pong\nelephants'
+ > capsstring = 'ping-pong\nelephants=babar,celeste\ncity=celesteville'
> bundler.addpart(bundle2.bundlepart('replycaps', data=capsstring))
>
> revs = opts['rev']
@@ -544,8 +547,12 @@
Patali Dirapata, Cromda Cromda Ripalo, Pata Pata, Ko Ko Ko
Bokoro Dipoulito, Rondi Rondi Pepino, Pata Pata, Ko Ko Ko
Emana Karassoli, Loucra Loucra Ponponto, Pata Pata, Ko Ko Ko.
- \x00\x00\x00\x00\x00\x1b\x06output\x00\x00\x00\x01\x00\x01\x0b\x01in-reply-to4\x00\x00\x00Rdebugreply: capabilities: (esc)
+ \x00\x00\x00\x00\x00\x1b\x06output\x00\x00\x00\x01\x00\x01\x0b\x01in-reply-to4\x00\x00\x00\xc6debugreply: capabilities: (esc)
+ debugreply: 'city'
+ debugreply: 'celesteville'
debugreply: 'elephants'
+ debugreply: 'babar'
+ debugreply: 'celeste'
debugreply: 'ping-pong'
\x00\x00\x00\x00\x00\x1e test:pong\x00\x00\x00\x02\x01\x00\x0b\x01in-reply-to6\x00\x00\x00\x00\x00\x1b\x06output\x00\x00\x00\x03\x00\x01\x0b\x01in-reply-to6\x00\x00\x00=received ping request (id 6) (esc)
replying to ping request (id 6)
@@ -562,7 +569,7 @@
:output:
mandatory: 0
advisory: 1
- payload: 82 bytes
+ payload: 198 bytes
:test:pong:
mandatory: 1
advisory: 0
@@ -581,7 +588,11 @@
remote: Bokoro Dipoulito, Rondi Rondi Pepino, Pata Pata, Ko Ko Ko
remote: Emana Karassoli, Loucra Loucra Ponponto, Pata Pata, Ko Ko Ko.
remote: debugreply: capabilities:
+ remote: debugreply: 'city'
+ remote: debugreply: 'celesteville'
remote: debugreply: 'elephants'
+ remote: debugreply: 'babar'
+ remote: debugreply: 'celeste'
remote: debugreply: 'ping-pong'
remote: received ping request (id 6)
remote: replying to ping request (id 6)