wireproto: provide accessors for client capabilities
authorJoerg Sonnenberger <joerg@bec.de>
Sat, 24 Mar 2018 17:57:22 +0100
changeset 45105 afcfdf53e4b5afa5db29c0eb98adb0258505aad9
parent 45104 a4f02a17420ddfbf99ff20e8fa0b2ff37d7823c9
child 45106 65705fbc9c37ab5d8b439adcd353569312eb9b4d
push id780
push usergszorc@mozilla.com
push dateSat, 07 Apr 2018 00:53:46 +0000
wireproto: provide accessors for client capabilities For HTTP, this refactors the existing logic, including the parsing of the compression engine capability. For SSH, this adds a ssh-only capability "protocaps" and a command for informing the server on what the client supports. Since SSH is stateful, keep track of the capabilities in the server instance. Differential Revision: https://phab.mercurial-scm.org/D1944
mercurial/help/internals/wireprotocol.txt
mercurial/sshpeer.py
mercurial/wireproto.py
mercurial/wireprotoserver.py
mercurial/wireprototypes.py
tests/test-debugcommands.t
tests/test-ssh-bundle1.t
tests/test-ssh-proto-unbundle.t
tests/test-ssh-proto.t
tests/test-ssh.t
--- a/mercurial/help/internals/wireprotocol.txt
+++ b/mercurial/help/internals/wireprotocol.txt
@@ -446,16 +446,20 @@ A generic error response type is also su
 message written to ``stderr`` followed by ``\n-\n``. In addition, ``\n`` is
 written to ``stdout``.
 
 If the server receives an unknown command, it will send an empty ``string``
 response.
 
 The server terminates if it receives an empty command (a ``\n`` character).
 
+If the server announces support for the ``protocaps`` capability, the client
+should issue a ``protocaps`` command after the initial handshake to annonunce
+its own capabilities. The client capabilities are persistent.
+
 SSH Version 2 Transport
 -----------------------
 
 **Experimental and under development**
 
 Version 2 of the SSH transport behaves identically to version 1 of the SSH
 transport with the exception of handshake semantics. See above for how
 version 2 of the SSH transport is negotiated.
@@ -1116,16 +1120,23 @@ lookup
 Whether the server supports the ``lookup`` command.
 
 This capability was introduced in Mercurial 0.9.2 (released December
 2006).
 
 This capability was introduced at the same time as the ``changegroupsubset``
 capability/command.
 
+protocaps
+---------
+
+Whether the server supports the ``protocaps`` command for SSH V1 transport.
+
+This capability was introduced in Mercurial 4.6.
+
 pushkey
 -------
 
 Whether the server supports the ``pushkey`` and ``listkeys`` commands.
 
 This capability was introduced in Mercurial 1.6 (released July 2010).
 
 standardbundle
@@ -1525,16 +1536,26 @@ The return type is ``string``.
 
 Returns a string consisting of ``0``s and ``1``s indicating whether nodes
 are known. If the Nth node specified in the ``nodes`` argument is known,
 a ``1`` will be returned at byte offset N. If the node isn't known, ``0``
 will be present at byte offset N.
 
 There is no trailing newline.
 
+protocaps
+---------
+
+Notify the server about the client capabilities in the SSH V1 transport
+protocol.
+
+The ``caps`` argument is a space-delimited list of capabilities.
+
+The server will reply with the string ``OK``.
+
 pushkey
 -------
 
 Set a value using the ``pushkey`` protocol.
 
 Accepts arguments ``namespace``, ``key``, ``old``, and ``new``, which
 correspond to the pushkey namespace to operate on, the key within that
 namespace to change, the old value (which may be empty), and the new value.
--- a/mercurial/sshpeer.py
+++ b/mercurial/sshpeer.py
@@ -158,16 +158,27 @@ def _makeconnection(ui, sshcmd, args, re
 
     # no buffer allow the use of 'select'
     # feel free to remove buffering and select usage when we ultimately
     # move to threading.
     stdin, stdout, stderr, proc = procutil.popen4(cmd, bufsize=0, env=sshenv)
 
     return proc, stdin, stdout, stderr
 
+def _clientcapabilities():
+    """Return list of capabilities of this client.
+
+    Returns a list of capabilities that are supported by this client.
+    """
+    protoparams = []
+    comps = [e.wireprotosupport().name for e in
+             util.compengines.supportedwireengines(util.CLIENTROLE)]
+    protoparams.append('comp=%s' % ','.join(comps))
+    return protoparams
+
 def _performhandshake(ui, stdin, stdout, stderr):
     def badresponse():
         # Flush any output on stderr.
         _forwardoutput(ui, stderr)
 
         msg = _('no suitable response from remote hg')
         hint = ui.config('ui', 'ssherrorhint')
         raise error.RepoError(msg, hint=hint)
@@ -604,9 +615,20 @@ def instance(ui, path, create):
         ui.debug('running %s\n' % cmd)
         res = ui.system(cmd, blockedtag='sshpeer', environ=sshenv)
         if res != 0:
             raise error.RepoError(_('could not create remote repo'))
 
     proc, stdin, stdout, stderr = _makeconnection(ui, sshcmd, args, remotecmd,
                                                   remotepath, sshenv)
 
-    return makepeer(ui, path, proc, stdin, stdout, stderr)
+    peer = makepeer(ui, path, proc, stdin, stdout, stderr)
+
+    # Finally, if supported by the server, notify it about our own
+    # capabilities.
+    if 'protocaps' in peer.capabilities():
+        try:
+            peer._call("protocaps", caps=' '.join(_clientcapabilities()))
+        except IOError:
+            peer._cleanup()
+            raise error.RepoError(_('capability exchange failed'))
+
+    return peer
--- a/mercurial/wireproto.py
+++ b/mercurial/wireproto.py
@@ -154,16 +154,28 @@ def encodebatchcmds(req):
         assert all(escapearg(k) == k for k in argsdict)
 
         args = ','.join('%s=%s' % (escapearg(k), escapearg(v))
                         for k, v in argsdict.iteritems())
         cmds.append('%s %s' % (op, args))
 
     return ';'.join(cmds)
 
+def clientcompressionsupport(proto):
+    """Returns a list of compression methods supported by the client.
+
+    Returns a list of the compression methods supported by the client
+    according to the protocol capabilities. If no such capability has
+    been announced, fallback to the default of zlib and uncompressed.
+    """
+    for cap in proto.getprotocaps():
+        if cap.startswith('comp='):
+            return cap[5:].split(',')
+    return ['zlib', 'none']
+
 # mapping of options accepted by getbundle and their types
 #
 # Meant to be extended by extensions. It is extensions responsibility to ensure
 # such options are properly processed in exchange.getbundle.
 #
 # supported types are:
 #
 # :nodes: list of binary nodes
@@ -1022,16 +1034,23 @@ def lookup(repo, proto, key):
         success = 0
     return wireprototypes.bytesresponse('%d %s\n' % (success, r))
 
 @wireprotocommand('known', 'nodes *', permission='pull')
 def known(repo, proto, nodes, others):
     v = ''.join(b and '1' or '0' for b in repo.known(decodelist(nodes)))
     return wireprototypes.bytesresponse(v)
 
+@wireprotocommand('protocaps', 'caps', permission='pull',
+                  transportpolicy=POLICY_V1_ONLY)
+def protocaps(repo, proto, caps):
+    if proto.name == wireprototypes.SSHV1:
+        proto._protocaps = set(caps.split(' '))
+    return wireprototypes.bytesresponse('OK')
+
 @wireprotocommand('pushkey', 'namespace key old new', permission='push')
 def pushkey(repo, proto, namespace, key, old, new):
     # compatibility with pre-1.8 clients which were accidentally
     # sending raw binary nodes rather than utf-8-encoded hex
     if len(new) == 20 and stringutil.escapestr(new) != new:
         # looks like it could be a binary node
         try:
             new.decode('utf-8')
--- a/mercurial/wireprotoserver.py
+++ b/mercurial/wireprotoserver.py
@@ -62,16 +62,17 @@ def decodevaluefromheaders(req, headerpr
     return ''.join(chunks)
 
 @zi.implementer(wireprototypes.baseprotocolhandler)
 class httpv1protocolhandler(object):
     def __init__(self, req, ui, checkperm):
         self._req = req
         self._ui = ui
         self._checkperm = checkperm
+        self._protocaps = None
 
     @property
     def name(self):
         return 'http-v1'
 
     def getargs(self, args):
         knownargs = self._args()
         data = {}
@@ -94,16 +95,22 @@ class httpv1protocolhandler(object):
             args.update(urlreq.parseqs(
                 self._req.bodyfh.read(postlen), keep_blank_values=True))
             return args
 
         argvalue = decodevaluefromheaders(self._req, b'X-HgArg')
         args.update(urlreq.parseqs(argvalue, keep_blank_values=True))
         return args
 
+    def getprotocaps(self):
+        if self._protocaps is None:
+            value = decodevaluefromheaders(self._req, r'X-HgProto')
+            self._protocaps = set(value.split(' '))
+        return self._protocaps
+
     def forwardpayload(self, fp):
         # Existing clients *always* send Content-Length.
         length = int(self._req.headers[b'Content-Length'])
 
         # If httppostargs is used, we need to read Content-Length
         # minus the amount that was consumed by args.
         length -= int(self._req.headers.get(b'X-HgArgs-Post', 0))
         for s in util.filechunkiter(self._req.bodyfh, limit=length):
@@ -594,54 +601,51 @@ class httpv2protocolhandler(object):
         for k in args.split():
             if k == '*':
                 raise NotImplementedError('do not support * args')
             else:
                 data[k] = self._args[k]
 
         return [data[k] for k in args.split()]
 
+    def getprotocaps(self):
+        # Protocol capabilities are currently not implemented for HTTP V2.
+        return set()
+
     def forwardpayload(self, fp):
         raise NotImplementedError
 
     @contextlib.contextmanager
     def mayberedirectstdio(self):
         raise NotImplementedError
 
     def client(self):
         raise NotImplementedError
 
     def addcapabilities(self, repo, caps):
         return caps
 
     def checkperm(self, perm):
         raise NotImplementedError
 
-def _httpresponsetype(ui, req, prefer_uncompressed):
+def _httpresponsetype(ui, proto, prefer_uncompressed):
     """Determine the appropriate response type and compression settings.
 
     Returns a tuple of (mediatype, compengine, engineopts).
     """
     # Determine the response media type and compression engine based
     # on the request parameters.
-    protocaps = decodevaluefromheaders(req, 'X-HgProto').split(' ')
 
-    if '0.2' in protocaps:
+    if '0.2' in proto.getprotocaps():
         # All clients are expected to support uncompressed data.
         if prefer_uncompressed:
             return HGTYPE2, util._noopengine(), {}
 
-        # Default as defined by wire protocol spec.
-        compformats = ['zlib', 'none']
-        for cap in protocaps:
-            if cap.startswith('comp='):
-                compformats = cap[5:].split(',')
-                break
-
         # Now find an agreed upon compression format.
+        compformats = wireproto.clientcompressionsupport(proto)
         for engine in wireproto.supportedcompengines(ui, util.SERVERROLE):
             if engine.wireprotosupport().name in compformats:
                 opts = {}
                 level = ui.configint('server', '%slevel' % engine.name())
                 if level is not None:
                     opts['level'] = level
 
                 return HGTYPE2, engine, opts
@@ -700,17 +704,17 @@ def _callhttp(repo, req, res, proto, cmd
     elif isinstance(rsp, wireprototypes.streamreslegacy):
         setresponse(HTTP_OK, HGTYPE, bodygen=rsp.gen)
     elif isinstance(rsp, wireprototypes.streamres):
         gen = rsp.gen
 
         # This code for compression should not be streamres specific. It
         # is here because we only compress streamres at the moment.
         mediatype, engine, engineopts = _httpresponsetype(
-            repo.ui, req, rsp.prefer_uncompressed)
+            repo.ui, proto, rsp.prefer_uncompressed)
         gen = engine.compressstream(gen, engineopts)
 
         if mediatype == HGTYPE2:
             gen = genversion2(gen, engine, engineopts)
 
         setresponse(HTTP_OK, mediatype, bodygen=gen)
     elif isinstance(rsp, wireprototypes.pushres):
         rsp = '%d\n%s' % (rsp.res, rsp.output)
@@ -744,16 +748,17 @@ def _sshv1respondooberror(fout, ferr, rs
 
 @zi.implementer(wireprototypes.baseprotocolhandler)
 class sshv1protocolhandler(object):
     """Handler for requests services via version 1 of SSH protocol."""
     def __init__(self, ui, fin, fout):
         self._ui = ui
         self._fin = fin
         self._fout = fout
+        self._protocaps = set()
 
     @property
     def name(self):
         return wireprototypes.SSHV1
 
     def getargs(self, args):
         data = {}
         keys = args.split()
@@ -770,16 +775,19 @@ class sshv1protocolhandler(object):
                     val = self._fin.read(int(l))
                     star[arg] = val
                 data['*'] = star
             else:
                 val = self._fin.read(int(l))
                 data[arg] = val
         return [data[k] for k in keys]
 
+    def getprotocaps(self):
+        return self._protocaps
+
     def forwardpayload(self, fpout):
         # We initially send an empty response. This tells the client it is
         # OK to start sending data. If a client sees any other response, it
         # interprets it as an error.
         _sshv1respondbytes(self._fout, b'')
 
         # The file is in the form:
         #
@@ -795,16 +803,18 @@ class sshv1protocolhandler(object):
     def mayberedirectstdio(self):
         yield None
 
     def client(self):
         client = encoding.environ.get('SSH_CLIENT', '').split(' ', 1)[0]
         return 'remote:ssh:' + client
 
     def addcapabilities(self, repo, caps):
+        if self.name == wireprototypes.SSHV1:
+            caps.append(b'protocaps')
         caps.append(b'batch')
         return caps
 
     def checkperm(self, perm):
         pass
 
 class sshv2protocolhandler(sshv1protocolhandler):
     """Protocol handler for version 2 of the SSH protocol."""
--- a/mercurial/wireprototypes.py
+++ b/mercurial/wireprototypes.py
@@ -112,16 +112,22 @@ class baseprotocolhandler(zi.Interface):
         Used for uniquely identifying the transport type.
         """)
 
     def getargs(args):
         """return the value for arguments in <args>
 
         returns a list of values (same order as <args>)"""
 
+    def getprotocaps():
+        """Returns the list of protocol-level capabilities of client
+
+        Returns a list of capabilities as declared by the client for
+        the current request (or connection for stateful protocol handlers)."""
+
     def forwardpayload(fp):
         """Read the raw payload and forward to a file.
 
         The payload is read in full before the function returns.
         """
 
     def mayberedirectstdio():
         """Context manager to possibly redirect stdio.
--- a/tests/test-debugcommands.t
+++ b/tests/test-debugcommands.t
@@ -402,14 +402,17 @@ Test debugpeer
   $ hg --config ui.ssh="\"$PYTHON\" \"$TESTDIR/dummyssh\"" --debug debugpeer ssh://user@dummy/debugrevlog
   running "*" "*/tests/dummyssh" 'user@dummy' 'hg -R debugrevlog serve --stdio' (glob) (no-windows !)
   running "*" "*\tests/dummyssh" "user@dummy" "hg -R debugrevlog serve --stdio" (glob) (windows !)
   devel-peer-request: hello
   sending hello command
   devel-peer-request: between
   devel-peer-request:   pairs: 81 bytes
   sending between command
-  remote: 403
-  remote: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  remote: 413
+  remote: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   remote: 1
+  devel-peer-request: protocaps
+  devel-peer-request:   caps: * bytes (glob)
+  sending protocaps command
   url: ssh://user@dummy/debugrevlog
   local: no
   pushable: yes
--- a/tests/test-ssh-bundle1.t
+++ b/tests/test-ssh-bundle1.t
@@ -475,20 +475,21 @@ stderr from remote commands should be pr
 debug output
 
   $ hg pull --debug ssh://user@dummy/remote
   pulling from ssh://user@dummy/remote
   running .* ".*/dummyssh" ['"]user@dummy['"] ('|")hg -R remote serve --stdio('|") (re)
   sending upgrade request: * proto=exp-ssh-v2-0001 (glob) (sshv2 !)
   sending hello command
   sending between command
-  remote: 403 (sshv1 !)
+  remote: 413 (sshv1 !)
   protocol upgraded to exp-ssh-v2-0001 (sshv2 !)
-  remote: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  remote: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   remote: 1 (sshv1 !)
+  sending protocaps command
   preparing listkeys for "bookmarks"
   sending listkeys command
   received listkey for "bookmarks": 45 bytes
   query 1; heads
   sending batch command
   searching for changes
   all remote heads known locally
   no changes found
--- a/tests/test-ssh-proto-unbundle.t
+++ b/tests/test-ssh-proto-unbundle.t
@@ -51,19 +51,19 @@ Test pushing bundle1 payload to a server
   creating ssh peer from handshake results
   i> write(104) -> 104:
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
   sending unbundle command
   i> write(9) -> 9:
   i>     unbundle\n
   i> write(9) -> 9:
@@ -105,18 +105,18 @@ Test pushing bundle1 payload to a server
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 62:
   o>     upgraded * exp-ssh-v2-0001\n (glob)
   o> readline() -> 4:
-  o>     402\n
-  o> read(402) -> 402: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  o>     412\n
+  o> read(412) -> 412: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   o> read(1) -> 1:
   o>     \n
   sending unbundle command
   i> write(9) -> 9:
   i>     unbundle\n
   i> write(9) -> 9:
   i>     heads 10\n
   i> write(10) -> 10: 666f726365
@@ -220,19 +220,19 @@ ui.write() in hook is redirected to stde
   creating ssh peer from handshake results
   i> write(104) -> 104:
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
   sending unbundle command
   i> write(9) -> 9:
   i>     unbundle\n
   i> write(9) -> 9:
@@ -280,18 +280,18 @@ ui.write() in hook is redirected to stde
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 62:
   o>     upgraded * exp-ssh-v2-0001\n (glob)
   o> readline() -> 4:
-  o>     402\n
-  o> read(402) -> 402: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  o>     412\n
+  o> read(412) -> 412: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   o> read(1) -> 1:
   o>     \n
   sending unbundle command
   i> write(9) -> 9:
   i>     unbundle\n
   i> write(9) -> 9:
   i>     heads 10\n
   i> write(10) -> 10: 666f726365
@@ -348,19 +348,19 @@ And a variation that writes multiple lin
   creating ssh peer from handshake results
   i> write(104) -> 104:
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
   sending unbundle command
   i> write(9) -> 9:
   i>     unbundle\n
   i> write(9) -> 9:
@@ -409,18 +409,18 @@ And a variation that writes multiple lin
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 62:
   o>     upgraded * exp-ssh-v2-0001\n (glob)
   o> readline() -> 4:
-  o>     402\n
-  o> read(402) -> 402: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  o>     412\n
+  o> read(412) -> 412: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   o> read(1) -> 1:
   o>     \n
   sending unbundle command
   i> write(9) -> 9:
   i>     unbundle\n
   i> write(9) -> 9:
   i>     heads 10\n
   i> write(10) -> 10: 666f726365
@@ -478,19 +478,19 @@ And a variation that does a ui.flush() a
   creating ssh peer from handshake results
   i> write(104) -> 104:
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
   sending unbundle command
   i> write(9) -> 9:
   i>     unbundle\n
   i> write(9) -> 9:
@@ -538,18 +538,18 @@ And a variation that does a ui.flush() a
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 62:
   o>     upgraded * exp-ssh-v2-0001\n (glob)
   o> readline() -> 4:
-  o>     402\n
-  o> read(402) -> 402: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  o>     412\n
+  o> read(412) -> 412: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   o> read(1) -> 1:
   o>     \n
   sending unbundle command
   i> write(9) -> 9:
   i>     unbundle\n
   i> write(9) -> 9:
   i>     heads 10\n
   i> write(10) -> 10: 666f726365
@@ -606,19 +606,19 @@ Multiple writes + flush
   creating ssh peer from handshake results
   i> write(104) -> 104:
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
   sending unbundle command
   i> write(9) -> 9:
   i>     unbundle\n
   i> write(9) -> 9:
@@ -667,18 +667,18 @@ Multiple writes + flush
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 62:
   o>     upgraded * exp-ssh-v2-0001\n (glob)
   o> readline() -> 4:
-  o>     402\n
-  o> read(402) -> 402: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  o>     412\n
+  o> read(412) -> 412: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   o> read(1) -> 1:
   o>     \n
   sending unbundle command
   i> write(9) -> 9:
   i>     unbundle\n
   i> write(9) -> 9:
   i>     heads 10\n
   i> write(10) -> 10: 666f726365
@@ -736,19 +736,19 @@ ui.write() + ui.write_err() output is ca
   creating ssh peer from handshake results
   i> write(104) -> 104:
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
   sending unbundle command
   i> write(9) -> 9:
   i>     unbundle\n
   i> write(9) -> 9:
@@ -799,18 +799,18 @@ ui.write() + ui.write_err() output is ca
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 62:
   o>     upgraded * exp-ssh-v2-0001\n (glob)
   o> readline() -> 4:
-  o>     402\n
-  o> read(402) -> 402: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  o>     412\n
+  o> read(412) -> 412: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   o> read(1) -> 1:
   o>     \n
   sending unbundle command
   i> write(9) -> 9:
   i>     unbundle\n
   i> write(9) -> 9:
   i>     heads 10\n
   i> write(10) -> 10: 666f726365
@@ -870,19 +870,19 @@ print() output is captured
   creating ssh peer from handshake results
   i> write(104) -> 104:
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
   sending unbundle command
   i> write(9) -> 9:
   i>     unbundle\n
   i> write(9) -> 9:
@@ -930,18 +930,18 @@ print() output is captured
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 62:
   o>     upgraded * exp-ssh-v2-0001\n (glob)
   o> readline() -> 4:
-  o>     402\n
-  o> read(402) -> 402: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  o>     412\n
+  o> read(412) -> 412: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   o> read(1) -> 1:
   o>     \n
   sending unbundle command
   i> write(9) -> 9:
   i>     unbundle\n
   i> write(9) -> 9:
   i>     heads 10\n
   i> write(10) -> 10: 666f726365
@@ -998,19 +998,19 @@ Mixed print() and ui.write() are both ca
   creating ssh peer from handshake results
   i> write(104) -> 104:
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
   sending unbundle command
   i> write(9) -> 9:
   i>     unbundle\n
   i> write(9) -> 9:
@@ -1061,18 +1061,18 @@ Mixed print() and ui.write() are both ca
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 62:
   o>     upgraded * exp-ssh-v2-0001\n (glob)
   o> readline() -> 4:
-  o>     402\n
-  o> read(402) -> 402: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  o>     412\n
+  o> read(412) -> 412: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   o> read(1) -> 1:
   o>     \n
   sending unbundle command
   i> write(9) -> 9:
   i>     unbundle\n
   i> write(9) -> 9:
   i>     heads 10\n
   i> write(10) -> 10: 666f726365
@@ -1132,19 +1132,19 @@ print() to stdout and stderr both get ca
   creating ssh peer from handshake results
   i> write(104) -> 104:
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
   sending unbundle command
   i> write(9) -> 9:
   i>     unbundle\n
   i> write(9) -> 9:
@@ -1195,18 +1195,18 @@ print() to stdout and stderr both get ca
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 62:
   o>     upgraded * exp-ssh-v2-0001\n (glob)
   o> readline() -> 4:
-  o>     402\n
-  o> read(402) -> 402: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  o>     412\n
+  o> read(412) -> 412: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   o> read(1) -> 1:
   o>     \n
   sending unbundle command
   i> write(9) -> 9:
   i>     unbundle\n
   i> write(9) -> 9:
   i>     heads 10\n
   i> write(10) -> 10: 666f726365
@@ -1272,19 +1272,19 @@ Shell hook writing to stdout has output 
   creating ssh peer from handshake results
   i> write(104) -> 104:
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
   sending unbundle command
   i> write(9) -> 9:
   i>     unbundle\n
   i> write(9) -> 9:
@@ -1333,18 +1333,18 @@ Shell hook writing to stdout has output 
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 62:
   o>     upgraded * exp-ssh-v2-0001\n (glob)
   o> readline() -> 4:
-  o>     402\n
-  o> read(402) -> 402: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  o>     412\n
+  o> read(412) -> 412: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   o> read(1) -> 1:
   o>     \n
   sending unbundle command
   i> write(9) -> 9:
   i>     unbundle\n
   i> write(9) -> 9:
   i>     heads 10\n
   i> write(10) -> 10: 666f726365
@@ -1403,19 +1403,19 @@ Shell hook writing to stderr has output 
   creating ssh peer from handshake results
   i> write(104) -> 104:
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
   sending unbundle command
   i> write(9) -> 9:
   i>     unbundle\n
   i> write(9) -> 9:
@@ -1464,18 +1464,18 @@ Shell hook writing to stderr has output 
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 62:
   o>     upgraded * exp-ssh-v2-0001\n (glob)
   o> readline() -> 4:
-  o>     402\n
-  o> read(402) -> 402: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  o>     412\n
+  o> read(412) -> 412: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   o> read(1) -> 1:
   o>     \n
   sending unbundle command
   i> write(9) -> 9:
   i>     unbundle\n
   i> write(9) -> 9:
   i>     heads 10\n
   i> write(10) -> 10: 666f726365
@@ -1536,19 +1536,19 @@ Shell hook writing to stdout and stderr 
   creating ssh peer from handshake results
   i> write(104) -> 104:
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
   sending unbundle command
   i> write(9) -> 9:
   i>     unbundle\n
   i> write(9) -> 9:
@@ -1599,18 +1599,18 @@ Shell hook writing to stdout and stderr 
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 62:
   o>     upgraded * exp-ssh-v2-0001\n (glob)
   o> readline() -> 4:
-  o>     402\n
-  o> read(402) -> 402: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  o>     412\n
+  o> read(412) -> 412: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   o> read(1) -> 1:
   o>     \n
   sending unbundle command
   i> write(9) -> 9:
   i>     unbundle\n
   i> write(9) -> 9:
   i>     heads 10\n
   i> write(10) -> 10: 666f726365
@@ -1679,19 +1679,19 @@ Shell and Python hooks writing to stdout
   creating ssh peer from handshake results
   i> write(104) -> 104:
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
   sending unbundle command
   i> write(9) -> 9:
   i>     unbundle\n
   i> write(9) -> 9:
@@ -1746,18 +1746,18 @@ Shell and Python hooks writing to stdout
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 62:
   o>     upgraded * exp-ssh-v2-0001\n (glob)
   o> readline() -> 4:
-  o>     402\n
-  o> read(402) -> 402: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  o>     412\n
+  o> read(412) -> 412: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   o> read(1) -> 1:
   o>     \n
   sending unbundle command
   i> write(9) -> 9:
   i>     unbundle\n
   i> write(9) -> 9:
   i>     heads 10\n
   i> write(10) -> 10: 666f726365
@@ -1821,19 +1821,19 @@ Pushing a bundle1 with no output
   creating ssh peer from handshake results
   i> write(104) -> 104:
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
   sending unbundle command
   i> write(9) -> 9:
   i>     unbundle\n
   i> write(9) -> 9:
@@ -1877,18 +1877,18 @@ Pushing a bundle1 with no output
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 62:
   o>     upgraded * exp-ssh-v2-0001\n (glob)
   o> readline() -> 4:
-  o>     402\n
-  o> read(402) -> 402: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  o>     412\n
+  o> read(412) -> 412: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   o> read(1) -> 1:
   o>     \n
   sending unbundle command
   i> write(9) -> 9:
   i>     unbundle\n
   i> write(9) -> 9:
   i>     heads 10\n
   i> write(10) -> 10: 666f726365
@@ -1953,19 +1953,19 @@ Pushing a bundle1 with ui.write() and ui
   creating ssh peer from handshake results
   i> write(104) -> 104:
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
   sending unbundle command
   i> write(9) -> 9:
   i>     unbundle\n
   i> write(9) -> 9:
@@ -2013,18 +2013,18 @@ Pushing a bundle1 with ui.write() and ui
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 62:
   o>     upgraded * exp-ssh-v2-0001\n (glob)
   o> readline() -> 4:
-  o>     402\n
-  o> read(402) -> 402: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  o>     412\n
+  o> read(412) -> 412: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   o> read(1) -> 1:
   o>     \n
   sending unbundle command
   i> write(9) -> 9:
   i>     unbundle\n
   i> write(9) -> 9:
   i>     heads 10\n
   i> write(10) -> 10: 666f726365
--- a/tests/test-ssh-proto.t
+++ b/tests/test-ssh-proto.t
@@ -58,72 +58,75 @@ Test a normal behaving server, for sanit
   $ hg --debug debugpeer ssh://user@dummy/server
   running * "*/tests/dummyssh" 'user@dummy' 'hg -R server serve --stdio' (glob) (no-windows !)
   running * "*\tests/dummyssh" "user@dummy" "hg -R server serve --stdio" (glob) (windows !)
   devel-peer-request: hello
   sending hello command
   devel-peer-request: between
   devel-peer-request:   pairs: 81 bytes
   sending between command
-  remote: 403
-  remote: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  remote: 413
+  remote: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   remote: 1
+  devel-peer-request: protocaps
+  devel-peer-request:   caps: * bytes (glob)
+  sending protocaps command
   url: ssh://user@dummy/server
   local: no
   pushable: yes
 
 Server should answer the "hello" command in isolation
 
   $ hg -R server debugwireproto --localssh --peer raw << EOF
   > raw
   >     hello\n
   > readline
   > readline
   > EOF
   using raw connection to peer
   i> write(6) -> 6:
   i>     hello\n
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
 
 `hg debugserve --sshstdio` works
 
   $ cd server
   $ hg debugserve --sshstdio << EOF
   > hello
   > EOF
-  403
-  capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  413
+  capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
 
 I/O logging works
 
   $ hg debugserve --sshstdio --logiofd 1 << EOF
   > hello
   > EOF
   o> write(4) -> 4:
-  o>     403\n
-  o> write(403) -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
-  403
-  capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  o>     413\n
+  o> write(413) -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
+  413
+  capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   o> flush() -> None
 
   $ hg debugserve --sshstdio --logiofile $TESTTMP/io << EOF
   > hello
   > EOF
-  403
-  capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  413
+  capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
 
   $ cat $TESTTMP/io
   o> write(4) -> 4:
-  o>     403\n
-  o> write(403) -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> write(413) -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   o> flush() -> None
 
   $ cd ..
 
 >=0.9.1 clients send a "hello" + "between" for the null range as part of handshake.
 Server should reply with capabilities and should send "1\n\n" as a successful
 reply with empty response to the "between".
 
@@ -138,19 +141,19 @@ reply with empty response to the "betwee
   >     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   > readline
   > readline
   > EOF
   using raw connection to peer
   i> write(6) -> 6:
   i>     hello\n
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   i> write(98) -> 98:
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
@@ -177,19 +180,22 @@ SSH banner is not printed by default, ig
   remote: banner: line 2
   remote: banner: line 3
   remote: banner: line 4
   remote: banner: line 5
   remote: banner: line 6
   remote: banner: line 7
   remote: banner: line 8
   remote: banner: line 9
-  remote: 403
-  remote: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  remote: 413
+  remote: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   remote: 1
+  devel-peer-request: protocaps
+  devel-peer-request:   caps: * bytes (glob)
+  sending protocaps command
   url: ssh://user@dummy/server
   local: no
   pushable: yes
 
 And test the banner with the raw protocol
 
   $ SSHSERVERMODE=banner hg -R server debugwireproto --localssh --peer raw << EOF
   > raw
@@ -232,19 +238,19 @@ And test the banner with the raw protoco
   o>     banner: line 6\n
   o> readline() -> 15:
   o>     banner: line 7\n
   o> readline() -> 15:
   o>     banner: line 8\n
   o> readline() -> 15:
   o>     banner: line 9\n
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   i> write(98) -> 98:
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
@@ -285,39 +291,42 @@ Sending an unknown command to the server
   using raw connection to peer
   i> write(10) -> 10:
   i>     pre-hello\n
   o> readline() -> 2:
   o>     0\n
   i> write(6) -> 6:
   i>     hello\n
   o> readline() -> 4:
-  o>     403\n
+  o>     413\n
   i> write(98) -> 98:
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   o> readline() -> 2:
   o>     1\n
 
   $ hg --config sshpeer.mode=extra-handshake-commands --config sshpeer.handshake-mode=pre-no-args --debug debugpeer ssh://user@dummy/server
   running * "*/tests/dummyssh" 'user@dummy' 'hg -R server serve --stdio' (glob) (no-windows !)
   running * "*\tests/dummyssh" "user@dummy" "hg -R server serve --stdio" (glob) (windows !)
   sending no-args command
   devel-peer-request: hello
   sending hello command
   devel-peer-request: between
   devel-peer-request:   pairs: 81 bytes
   sending between command
   remote: 0
-  remote: 403
-  remote: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  remote: 413
+  remote: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   remote: 1
+  devel-peer-request: protocaps
+  devel-peer-request:   caps: * bytes (glob)
+  sending protocaps command
   url: ssh://user@dummy/server
   local: no
   pushable: yes
 
 Send multiple unknown commands before hello
 
   $ hg -R server debugwireproto --localssh --peer raw << EOF
   > raw
@@ -351,19 +360,19 @@ Send multiple unknown commands before he
   o>     0\n
   i> write(9) -> 9:
   i>     unknown3\n
   o> readline() -> 2:
   o>     0\n
   i> write(6) -> 6:
   i>     hello\n
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   i> write(98) -> 98:
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
@@ -377,19 +386,22 @@ Send multiple unknown commands before he
   devel-peer-request: hello
   sending hello command
   devel-peer-request: between
   devel-peer-request:   pairs: 81 bytes
   sending between command
   remote: 0
   remote: 0
   remote: 0
-  remote: 403
-  remote: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  remote: 413
+  remote: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   remote: 1
+  devel-peer-request: protocaps
+  devel-peer-request:   caps: * bytes (glob)
+  sending protocaps command
   url: ssh://user@dummy/server
   local: no
   pushable: yes
 
 Send an unknown command before hello that has arguments
 
   $ cd server
 
@@ -431,19 +443,19 @@ Send an unknown command before hello tha
   o>     0\n
   o> readline() -> 2:
   o>     0\n
   o> readline() -> 2:
   o>     0\n
   i> write(6) -> 6:
   i>     hello\n
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   i> write(98) -> 98:
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
@@ -478,19 +490,19 @@ Send an unknown command having an argume
   o>     0\n
   o> readline() -> 2:
   o>     0\n
   o> readline() -> 2:
   o>     0\n
   i> write(6) -> 6:
   i>     hello\n
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   i> write(98) -> 98:
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
@@ -523,19 +535,19 @@ Send an unknown command having an argume
   o>     0\n
   o> readline() -> 2:
   o>     0\n
   o> readline() -> 2:
   o>     0\n
   i> write(6) -> 6:
   i>     hello\n
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   i> write(98) -> 98:
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
@@ -593,19 +605,19 @@ Dictionary value for unknown command
   o>     0\n
   o> readline() -> 2:
   o>     0\n
   o> readline() -> 2:
   o>     0\n
   i> write(6) -> 6:
   i>     hello\n
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
 
 Incomplete dictionary send
 
   $ hg debugwireproto --localssh --peer raw << EOF
   > raw
   >     unknown\n
   >     dict 3\n
   >     key1 3\n
@@ -675,19 +687,19 @@ Send a command line with spaces
   using raw connection to peer
   i> write(18) -> 18:
   i>     unknown withspace\n
   o> readline() -> 2:
   o>     0\n
   i> write(6) -> 6:
   i>     hello\n
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   i> write(98) -> 98:
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
@@ -709,19 +721,19 @@ Send a command line with spaces
   using raw connection to peer
   i> write(29) -> 29:
   i>     unknown with multiple spaces\n
   o> readline() -> 2:
   o>     0\n
   i> write(6) -> 6:
   i>     hello\n
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   i> write(98) -> 98:
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   o> readline() -> 2:
   o>     1\n
 
   $ hg debugwireproto --localssh --peer raw << EOF
@@ -752,19 +764,19 @@ Send a command line with spaces
   o>     0\n
   o> readline() -> 2:
   o>     0\n
   o> readline() -> 2:
   o>     0\n
   i> write(6) -> 6:
   i>     hello\n
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   i> write(98) -> 98:
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
@@ -781,19 +793,19 @@ Send an unknown command after the "betwe
   >     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000unknown
   > readline
   > readline
   > EOF
   using raw connection to peer
   i> write(6) -> 6:
   i>     hello\n
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   i> write(105) -> 105:
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000unknown
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
@@ -822,19 +834,19 @@ And one with arguments
   > EOF
   using raw connection to peer
   i> write(104) -> 104:
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
   i> write(31) -> 31:
   i>     unknown\n
   i>     foo 5\n
   i>     \n
@@ -871,19 +883,19 @@ Send a valid command before the handshak
   i> write(104) -> 104:
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   o> readline() -> 41:
   o>     68986213bd4485ea51533535e3fc9e78007a711f\n
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   o> readline() -> 2:
   o>     1\n
 
 And a variation that doesn't send the between command
 
   $ hg debugwireproto --localssh --peer raw << EOF
   > raw
   >     heads\n
@@ -898,17 +910,17 @@ And a variation that doesn't send the be
   i>     heads\n
   o> readline() -> 3:
   o>     41\n
   i> write(6) -> 6:
   i>     hello\n
   o> readline() -> 41:
   o>     68986213bd4485ea51533535e3fc9e78007a711f\n
   o> readline() -> 4:
-  o>     403\n
+  o>     413\n
 
 Send an upgrade request to a server that doesn't support that command
 
   $ hg debugwireproto --localssh --peer raw << EOF
   > raw
   >     upgrade 2e82ab3f-9ce3-4b4e-8f8c-6fd1c0e9e23a proto=irrelevant1%2Cirrelevant2\n
   > readline
   > raw
@@ -927,19 +939,19 @@ Send an upgrade request to a server that
   o> readline() -> 2:
   o>     0\n
   i> write(104) -> 104:
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
 
   $ cd ..
 
   $ hg --config experimental.sshpeer.advertise-v2=true --debug debugpeer ssh://user@dummy/server
@@ -947,19 +959,22 @@ Send an upgrade request to a server that
   running * "*\tests/dummyssh" "user@dummy" "hg -R server serve --stdio" (glob) (windows !)
   sending upgrade request: * proto=exp-ssh-v2-0001 (glob)
   devel-peer-request: hello
   sending hello command
   devel-peer-request: between
   devel-peer-request:   pairs: 81 bytes
   sending between command
   remote: 0
-  remote: 403
-  remote: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  remote: 413
+  remote: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   remote: 1
+  devel-peer-request: protocaps
+  devel-peer-request:   caps: * bytes (glob)
+  sending protocaps command
   url: ssh://user@dummy/server
   local: no
   pushable: yes
 
 Enable version 2 support on server. We need to do this in hgrc because we can't
 use --config with `hg serve --stdio`.
 
   $ cat >> server/.hg/hgrc << EOF
@@ -987,58 +1002,65 @@ Send an upgrade request to a server that
   i>     upgrade this-is-some-token proto=exp-ssh-v2-0001\n
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   o> readline() -> 44:
   o>     upgraded this-is-some-token exp-ssh-v2-0001\n
   o> readline() -> 4:
-  o>     402\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     412\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
 
   $ cd ..
 
   $ hg --config experimental.sshpeer.advertise-v2=true --debug debugpeer ssh://user@dummy/server
   running * "*/tests/dummyssh" 'user@dummy' 'hg -R server serve --stdio' (glob) (no-windows !)
   running * "*\tests/dummyssh" "user@dummy" "hg -R server serve --stdio" (glob) (windows !)
   sending upgrade request: * proto=exp-ssh-v2-0001 (glob)
   devel-peer-request: hello
   sending hello command
   devel-peer-request: between
   devel-peer-request:   pairs: 81 bytes
   sending between command
   protocol upgraded to exp-ssh-v2-0001
-  remote: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  remote: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
+  devel-peer-request: protocaps
+  devel-peer-request:   caps: * bytes (glob)
+  sending protocaps command
   url: ssh://user@dummy/server
   local: no
   pushable: yes
 
 Verify the peer has capabilities
 
   $ hg --config experimental.sshpeer.advertise-v2=true --debug debugcapabilities ssh://user@dummy/server
   running * "*/tests/dummyssh" 'user@dummy' 'hg -R server serve --stdio' (glob) (no-windows !)
   running * "*\tests/dummyssh" "user@dummy" "hg -R server serve --stdio" (glob) (windows !)
   sending upgrade request: * proto=exp-ssh-v2-0001 (glob)
   devel-peer-request: hello
   sending hello command
   devel-peer-request: between
   devel-peer-request:   pairs: 81 bytes
   sending between command
   protocol upgraded to exp-ssh-v2-0001
-  remote: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  remote: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
+  devel-peer-request: protocaps
+  devel-peer-request:   caps: * bytes (glob)
+  sending protocaps command
   Main capabilities:
     batch
     branchmap
     $USUAL_BUNDLE2_CAPS_SERVER$
     changegroupsubset
     getbundle
     known
     lookup
+    protocaps
     pushkey
     streamreqs=generaldelta,revlogv1
     unbundle=HG10GZ,HG10BZ,HG10UN
     unbundlehash
   Bundle2 capabilities:
     HG20
     bookmarks
     changegroup
@@ -1087,19 +1109,19 @@ Command after upgrade to version 2 is pr
   i>     upgrade this-is-some-token proto=exp-ssh-v2-0001\n
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   o> readline() -> 44:
   o>     upgraded this-is-some-token exp-ssh-v2-0001\n
   o> readline() -> 4:
-  o>     402\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     412\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   i> write(6) -> 6:
   i>     hello\n
   o> readline() -> 4:
   o>     403\n
   o> readline() -> 403:
   o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
 
 Multiple upgrades is not allowed
@@ -1125,19 +1147,19 @@ Multiple upgrades is not allowed
   i>     upgrade this-is-some-token proto=exp-ssh-v2-0001\n
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   o> readline() -> 44:
   o>     upgraded this-is-some-token exp-ssh-v2-0001\n
   o> readline() -> 4:
-  o>     402\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     412\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   i> write(45) -> 45:
   i>     upgrade another-token proto=irrelevant\n
   i>     hello\n
   o> readline() -> 1:
   o>     \n
   o> read(-1) -> 0: 
   e> read(-1) -> 42:
   e>     cannot upgrade protocols multiple times\n
@@ -1198,19 +1220,19 @@ Upgrade request to unsupported protocol 
   using raw connection to peer
   i> write(51) -> 51:
   i>     upgrade this-is-some-token proto=unknown1,unknown2\n
   o> readline() -> 2:
   o>     0\n
   i> write(6) -> 6:
   i>     hello\n
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   i> write(98) -> 98:
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
@@ -1320,19 +1342,19 @@ Test listkeys for listing namespaces
   creating ssh peer from handshake results
   i> write(104) -> 104:
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
   sending listkeys command
   i> write(9) -> 9:
   i>     listkeys\n
   i> write(13) -> 13:
@@ -1354,18 +1376,18 @@ Test listkeys for listing namespaces
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 62:
   o>     upgraded * exp-ssh-v2-0001\n (glob)
   o> readline() -> 4:
-  o>     402\n
-  o> read(402) -> 402: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  o>     412\n
+  o> read(412) -> 412: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   o> read(1) -> 1:
   o>     \n
   sending listkeys command
   i> write(9) -> 9:
   i>     listkeys\n
   i> write(13) -> 13:
   i>     namespace 10\n
   i> write(10) -> 10: namespaces
@@ -1400,19 +1422,19 @@ With no bookmarks set
   creating ssh peer from handshake results
   i> write(104) -> 104:
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
   sending listkeys command
   i> write(9) -> 9:
   i>     listkeys\n
   i> write(12) -> 12:
@@ -1430,18 +1452,18 @@ With no bookmarks set
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 62:
   o>     upgraded * exp-ssh-v2-0001\n (glob)
   o> readline() -> 4:
-  o>     402\n
-  o> read(402) -> 402: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  o>     412\n
+  o> read(412) -> 412: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   o> read(1) -> 1:
   o>     \n
   sending listkeys command
   i> write(9) -> 9:
   i>     listkeys\n
   i> write(12) -> 12:
   i>     namespace 9\n
   i> write(9) -> 9: bookmarks
@@ -1461,19 +1483,19 @@ With a single bookmark set
   creating ssh peer from handshake results
   i> write(104) -> 104:
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
   sending listkeys command
   i> write(9) -> 9:
   i>     listkeys\n
   i> write(12) -> 12:
@@ -1492,18 +1514,18 @@ With a single bookmark set
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 62:
   o>     upgraded * exp-ssh-v2-0001\n (glob)
   o> readline() -> 4:
-  o>     402\n
-  o> read(402) -> 402: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  o>     412\n
+  o> read(412) -> 412: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   o> read(1) -> 1:
   o>     \n
   sending listkeys command
   i> write(9) -> 9:
   i>     listkeys\n
   i> write(12) -> 12:
   i>     namespace 9\n
   i> write(9) -> 9: bookmarks
@@ -1524,19 +1546,19 @@ With multiple bookmarks set
   creating ssh peer from handshake results
   i> write(104) -> 104:
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
   sending listkeys command
   i> write(9) -> 9:
   i>     listkeys\n
   i> write(12) -> 12:
@@ -1557,18 +1579,18 @@ With multiple bookmarks set
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 62:
   o>     upgraded * exp-ssh-v2-0001\n (glob)
   o> readline() -> 4:
-  o>     402\n
-  o> read(402) -> 402: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  o>     412\n
+  o> read(412) -> 412: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   o> read(1) -> 1:
   o>     \n
   sending listkeys command
   i> write(9) -> 9:
   i>     listkeys\n
   i> write(12) -> 12:
   i>     namespace 9\n
   i> write(9) -> 9: bookmarks
@@ -1593,19 +1615,19 @@ Test pushkey for bookmarks
   creating ssh peer from handshake results
   i> write(104) -> 104:
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
   sending pushkey command
   i> write(8) -> 8:
   i>     pushkey\n
   i> write(6) -> 6:
@@ -1633,18 +1655,18 @@ Test pushkey for bookmarks
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 62:
   o>     upgraded * exp-ssh-v2-0001\n (glob)
   o> readline() -> 4:
-  o>     402\n
-  o> read(402) -> 402: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  o>     412\n
+  o> read(412) -> 412: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   o> read(1) -> 1:
   o>     \n
   sending pushkey command
   i> write(8) -> 8:
   i>     pushkey\n
   i> write(6) -> 6:
   i>     key 6\n
   i> write(6) -> 6: remote
@@ -1685,19 +1707,19 @@ Phases on empty repo
   creating ssh peer from handshake results
   i> write(104) -> 104:
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
   sending listkeys command
   i> write(9) -> 9:
   i>     listkeys\n
   i> write(12) -> 12:
@@ -1716,18 +1738,18 @@ Phases on empty repo
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 62:
   o>     upgraded * exp-ssh-v2-0001\n (glob)
   o> readline() -> 4:
-  o>     402\n
-  o> read(402) -> 402: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  o>     412\n
+  o> read(412) -> 412: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   o> read(1) -> 1:
   o>     \n
   sending listkeys command
   i> write(9) -> 9:
   i>     listkeys\n
   i> write(12) -> 12:
   i>     namespace 6\n
   i> write(6) -> 6: phases
@@ -1764,19 +1786,19 @@ Two draft heads
   creating ssh peer from handshake results
   i> write(104) -> 104:
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
   sending listkeys command
   i> write(9) -> 9:
   i>     listkeys\n
   i> write(12) -> 12:
@@ -1798,18 +1820,18 @@ Two draft heads
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 62:
   o>     upgraded * exp-ssh-v2-0001\n (glob)
   o> readline() -> 4:
-  o>     402\n
-  o> read(402) -> 402: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  o>     412\n
+  o> read(412) -> 412: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   o> read(1) -> 1:
   o>     \n
   sending listkeys command
   i> write(9) -> 9:
   i>     listkeys\n
   i> write(12) -> 12:
   i>     namespace 6\n
   i> write(6) -> 6: phases
@@ -1833,19 +1855,19 @@ Single draft head
   creating ssh peer from handshake results
   i> write(104) -> 104:
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
   sending listkeys command
   i> write(9) -> 9:
   i>     listkeys\n
   i> write(12) -> 12:
@@ -1866,18 +1888,18 @@ Single draft head
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 62:
   o>     upgraded * exp-ssh-v2-0001\n (glob)
   o> readline() -> 4:
-  o>     402\n
-  o> read(402) -> 402: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  o>     412\n
+  o> read(412) -> 412: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   o> read(1) -> 1:
   o>     \n
   sending listkeys command
   i> write(9) -> 9:
   i>     listkeys\n
   i> write(12) -> 12:
   i>     namespace 6\n
   i> write(6) -> 6: phases
@@ -1900,19 +1922,19 @@ All public heads
   creating ssh peer from handshake results
   i> write(104) -> 104:
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
   sending listkeys command
   i> write(9) -> 9:
   i>     listkeys\n
   i> write(12) -> 12:
@@ -1931,18 +1953,18 @@ All public heads
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 62:
   o>     upgraded * exp-ssh-v2-0001\n (glob)
   o> readline() -> 4:
-  o>     402\n
-  o> read(402) -> 402: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  o>     412\n
+  o> read(412) -> 412: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   o> read(1) -> 1:
   o>     \n
   sending listkeys command
   i> write(9) -> 9:
   i>     listkeys\n
   i> write(12) -> 12:
   i>     namespace 6\n
   i> write(6) -> 6: phases
@@ -1967,19 +1989,19 @@ Setting public phase via pushkey
   creating ssh peer from handshake results
   i> write(104) -> 104:
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
   sending pushkey command
   i> write(8) -> 8:
   i>     pushkey\n
   i> write(7) -> 7:
@@ -2008,18 +2030,18 @@ Setting public phase via pushkey
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 62:
   o>     upgraded * exp-ssh-v2-0001\n (glob)
   o> readline() -> 4:
-  o>     402\n
-  o> read(402) -> 402: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  o>     412\n
+  o> read(412) -> 412: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   o> read(1) -> 1:
   o>     \n
   sending pushkey command
   i> write(8) -> 8:
   i>     pushkey\n
   i> write(7) -> 7:
   i>     key 40\n
   i> write(40) -> 40: 7127240a084fd9dc86fe8d1f98e26229161ec82b
@@ -2074,19 +2096,19 @@ Test batching of requests
   creating ssh peer from handshake results
   i> write(104) -> 104:
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 4:
-  o>     403\n
-  o> readline() -> 403:
-  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch\n
+  o>     413\n
+  o> readline() -> 413:
+  o>     capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch\n
   o> readline() -> 2:
   o>     1\n
   o> readline() -> 1:
   o>     \n
   sending batch with 3 sub-commands
   i> write(6) -> 6:
   i>     batch\n
   i> write(4) -> 4:
@@ -2114,18 +2136,18 @@ Test batching of requests
   i>     hello\n
   i>     between\n
   i>     pairs 81\n
   i>     0000000000000000000000000000000000000000-0000000000000000000000000000000000000000
   i> flush() -> None
   o> readline() -> 62:
   o>     upgraded * exp-ssh-v2-0001\n (glob)
   o> readline() -> 4:
-  o>     402\n
-  o> read(402) -> 402: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  o>     412\n
+  o> read(412) -> 412: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   o> read(1) -> 1:
   o>     \n
   sending batch with 3 sub-commands
   i> write(6) -> 6:
   i>     batch\n
   i> write(4) -> 4:
   i>     * 0\n
   i> write(8) -> 8:
--- a/tests/test-ssh.t
+++ b/tests/test-ssh.t
@@ -490,20 +490,23 @@ debug output
   pulling from ssh://user@dummy/remote
   running .* ".*/dummyssh" ['"]user@dummy['"] ('|")hg -R remote serve --stdio('|") (re)
   sending upgrade request: * proto=exp-ssh-v2-0001 (glob) (sshv2 !)
   devel-peer-request: hello
   sending hello command
   devel-peer-request: between
   devel-peer-request:   pairs: 81 bytes
   sending between command
-  remote: 403 (sshv1 !)
+  remote: 413 (sshv1 !)
   protocol upgraded to exp-ssh-v2-0001 (sshv2 !)
-  remote: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN batch
+  remote: capabilities: lookup branchmap pushkey known getbundle unbundlehash changegroupsubset streamreqs=generaldelta,revlogv1 $USUAL_BUNDLE2_CAPS_SERVER$ unbundle=HG10GZ,HG10BZ,HG10UN protocaps batch
   remote: 1 (sshv1 !)
+  devel-peer-request: protocaps
+  devel-peer-request:   caps: * bytes (glob)
+  sending protocaps command
   query 1; heads
   devel-peer-request: batched-content
   devel-peer-request:    - heads (0 arguments)
   devel-peer-request:    - known (1 arguments)
   devel-peer-request: batch
   devel-peer-request:   cmds: 141 bytes
   sending batch command
   searching for changes