comparison mercurial/wireprototypes.py @ 37485:0b7475ea38cf

wireproto: port heads command to wire protocol v2 After much thought and consideration, wire protocol version 2's commands will be defined in different functions from the existing commands. This will make it easier to implement these commands because it won't require shoehorning things like response formatting and argument declaration into the same APIs. For example, wire protocol version 1 requires that commands declare a fixed and ordered list of argument names. It isn't really possible to insert new arguments or have optional arguments without breaking backwards compatibility. Wire protocol version 2, however, uses CBOR maps for passing arguments. So arguments a) can be optional b) can be added without BC c) can be strongly typed. This commit starts our trek towards reimplementing the wire protocol for version 2 with the heads command. It is pretty similar to the existing heads command. One added feature is it can be told to operate on only public phase changesets. This is useful for making discovery faster when a repo has tens of thousands of draft phase heads (such as Mozilla's "try" repository). The HTTPv2 server-side protocol has had its `getargs()` implementation updated to reflect that arguments are a map and not a list. Differential Revision: https://phab.mercurial-scm.org/D3179
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 28 Mar 2018 14:55:13 -0700
parents 2d965bfeb8f6
children 5e71dea79aae
comparison
equal deleted inserted replaced
37484:c22fd3c4c23e 37485:0b7475ea38cf
95 using the application/mercurial-0.1 media type. 95 using the application/mercurial-0.1 media type.
96 """ 96 """
97 def __init__(self, gen=None): 97 def __init__(self, gen=None):
98 self.gen = gen 98 self.gen = gen
99 99
100 class cborresponse(object):
101 """Encode the response value as CBOR."""
102 def __init__(self, v):
103 self.value = v
104
100 class baseprotocolhandler(zi.Interface): 105 class baseprotocolhandler(zi.Interface):
101 """Abstract base class for wire protocol handlers. 106 """Abstract base class for wire protocol handlers.
102 107
103 A wire protocol handler serves as an interface between protocol command 108 A wire protocol handler serves as an interface between protocol command
104 handlers and the wire protocol transport layer. Protocol handlers provide 109 handlers and the wire protocol transport layer. Protocol handlers provide
113 """) 118 """)
114 119
115 def getargs(args): 120 def getargs(args):
116 """return the value for arguments in <args> 121 """return the value for arguments in <args>
117 122
118 returns a list of values (same order as <args>)""" 123 For version 1 transports, returns a list of values in the same
124 order they appear in ``args``. For version 2 transports, returns
125 a dict mapping argument name to value.
126 """
119 127
120 def getprotocaps(): 128 def getprotocaps():
121 """Returns the list of protocol-level capabilities of client 129 """Returns the list of protocol-level capabilities of client
122 130
123 Returns a list of capabilities as declared by the client for 131 Returns a list of capabilities as declared by the client for