tests/wireprotohelpers.sh
author Gregory Szorc <gregory.szorc@gmail.com>
Mon, 09 Apr 2018 11:57:12 -0700
changeset 37540 693cb3768943
parent 37483 61e405fb6372
child 37718 ad1c07008e0b
permissions -rw-r--r--
wireproto: make @wireprotocommand version 1 only by default For backwards compatibility reasons. We want extension provided commands to opt in to version 2 rather than get inherited automatically. This will facilitate a clean break between the protocols. As part of this, we duplicate some commands used in tests so there are different command handlers per transport. Differential Revision: https://phab.mercurial-scm.org/D3207

HTTPV2=exp-http-v2-0001
MEDIATYPE=application/mercurial-exp-framing-0003

sendhttpraw() {
  hg --verbose debugwireproto --peer raw http://$LOCALIP:$HGPORT/
}

sendhttpv2peer() {
  hg --verbose debugwireproto --peer http2 http://$LOCALIP:$HGPORT/
}

cat > dummycommands.py << EOF
from mercurial import (
    wireprototypes,
    wireproto,
)

@wireproto.wireprotocommand('customreadonly', permission='pull')
def customreadonlyv1(repo, proto):
    return wireprototypes.bytesresponse(b'customreadonly bytes response')

@wireproto.wireprotocommand('customreadonly', permission='pull',
                            transportpolicy=wireproto.POLICY_V2_ONLY)
def customreadonlyv2(repo, proto):
    return wireprototypes.bytesresponse(b'customreadonly bytes response')

@wireproto.wireprotocommand('customreadwrite', permission='push')
def customreadwrite(repo, proto):
    return wireprototypes.bytesresponse(b'customreadwrite bytes response')

@wireproto.wireprotocommand('customreadwrite', permission='push',
                            transportpolicy=wireproto.POLICY_V2_ONLY)
def customreadwritev2(repo, proto):
    return wireprototypes.bytesresponse(b'customreadwrite bytes response')
EOF

cat >> $HGRCPATH << EOF
[extensions]
drawdag = $TESTDIR/drawdag.py
EOF

enabledummycommands() {
  cat >> $HGRCPATH << EOF
[extensions]
dummycommands = $TESTTMP/dummycommands.py
EOF
}

enablehttpv2() {
  cat >> $1/.hg/hgrc << EOF
[experimental]
web.apiserver = true
web.api.http-v2 = true
EOF
}