Show More
@@ -1,773 +1,907 | |||
|
1 | 1 | The Mercurial wire protocol is a request-response based protocol |
|
2 | 2 | with multiple wire representations. |
|
3 | 3 | |
|
4 | 4 | Each request is modeled as a command name, a dictionary of arguments, and |
|
5 | 5 | optional raw input. Command arguments and their types are intrinsic |
|
6 | 6 | properties of commands. So is the response type of the command. This means |
|
7 | 7 | clients can't always send arbitrary arguments to servers and servers can't |
|
8 | 8 | return multiple response types. |
|
9 | 9 | |
|
10 | 10 | The protocol is synchronous and does not support multiplexing (concurrent |
|
11 | 11 | commands). |
|
12 | 12 | |
|
13 | 13 | Transport Protocols |
|
14 | 14 | =================== |
|
15 | 15 | |
|
16 | 16 | HTTP Transport |
|
17 | 17 | -------------- |
|
18 | 18 | |
|
19 | 19 | Commands are issued as HTTP/1.0 or HTTP/1.1 requests. Commands are |
|
20 | 20 | sent to the base URL of the repository with the command name sent in |
|
21 | 21 | the ``cmd`` query string parameter. e.g. |
|
22 | 22 | ``https://example.com/repo?cmd=capabilities``. The HTTP method is ``GET`` |
|
23 | 23 | or ``POST`` depending on the command and whether there is a request |
|
24 | 24 | body. |
|
25 | 25 | |
|
26 | 26 | Command arguments can be sent multiple ways. |
|
27 | 27 | |
|
28 | 28 | The simplest is part of the URL query string using ``x-www-form-urlencoded`` |
|
29 | 29 | encoding (see Python's ``urllib.urlencode()``. However, many servers impose |
|
30 | 30 | length limitations on the URL. So this mechanism is typically only used if |
|
31 | 31 | the server doesn't support other mechanisms. |
|
32 | 32 | |
|
33 | 33 | If the server supports the ``httpheader`` capability, command arguments can |
|
34 | 34 | be sent in HTTP request headers named ``X-HgArg-<N>`` where ``<N>`` is an |
|
35 | 35 | integer starting at 1. A ``x-www-form-urlencoded`` representation of the |
|
36 | 36 | arguments is obtained. This full string is then split into chunks and sent |
|
37 | 37 | in numbered ``X-HgArg-<N>`` headers. The maximum length of each HTTP header |
|
38 | 38 | is defined by the server in the ``httpheader`` capability value, which defaults |
|
39 | 39 | to ``1024``. The server reassembles the encoded arguments string by |
|
40 | 40 | concatenating the ``X-HgArg-<N>`` headers then URL decodes them into a |
|
41 | 41 | dictionary. |
|
42 | 42 | |
|
43 | 43 | The list of ``X-HgArg-<N>`` headers should be added to the ``Vary`` request |
|
44 | 44 | header to instruct caches to take these headers into consideration when caching |
|
45 | 45 | requests. |
|
46 | 46 | |
|
47 | 47 | If the server supports the ``httppostargs`` capability, the client |
|
48 | 48 | may send command arguments in the HTTP request body as part of an |
|
49 | 49 | HTTP POST request. The command arguments will be URL encoded just like |
|
50 | 50 | they would for sending them via HTTP headers. However, no splitting is |
|
51 | 51 | performed: the raw arguments are included in the HTTP request body. |
|
52 | 52 | |
|
53 | 53 | The client sends a ``X-HgArgs-Post`` header with the string length of the |
|
54 | 54 | encoded arguments data. Additional data may be included in the HTTP |
|
55 | 55 | request body immediately following the argument data. The offset of the |
|
56 | 56 | non-argument data is defined by the ``X-HgArgs-Post`` header. The |
|
57 | 57 | ``X-HgArgs-Post`` header is not required if there is no argument data. |
|
58 | 58 | |
|
59 | 59 | Additional command data can be sent as part of the HTTP request body. The |
|
60 | 60 | default ``Content-Type`` when sending data is ``application/mercurial-0.1``. |
|
61 | 61 | A ``Content-Length`` header is currently always sent. |
|
62 | 62 | |
|
63 | 63 | Example HTTP requests:: |
|
64 | 64 | |
|
65 | 65 | GET /repo?cmd=capabilities |
|
66 | 66 | X-HgArg-1: foo=bar&baz=hello%20world |
|
67 | 67 | |
|
68 | The request media type should be chosen based on server support. If the | |
|
69 | ``httpmediatype`` server capability is present, the client should send | |
|
70 | the newest mutually supported media type. If this capability is absent, | |
|
71 | the client must assume the server only supports the | |
|
72 | ``application/mercurial-0.1`` media type. | |
|
73 | ||
|
68 | 74 | The ``Content-Type`` HTTP response header identifies the response as coming |
|
69 | 75 | from Mercurial and can also be used to signal an error has occurred. |
|
70 | 76 | |
|
71 |
The ``application/mercurial- |
|
|
72 | response. It matches the media type sent by the client. | |
|
77 | The ``application/mercurial-*`` media types indicate a generic Mercurial | |
|
78 | data type. | |
|
79 | ||
|
80 | The ``application/mercurial-0.1`` media type is raw Mercurial data. It is the | |
|
81 | predecessor of the format below. | |
|
82 | ||
|
83 | The ``application/mercurial-0.2`` media type is compression framed Mercurial | |
|
84 | data. The first byte of the payload indicates the length of the compression | |
|
85 | format identifier that follows. Next are N bytes indicating the compression | |
|
86 | format. e.g. ``zlib``. The remaining bytes are compressed according to that | |
|
87 | compression format. The decompressed data behaves the same as with | |
|
88 | ``application/mercurial-0.1``. | |
|
73 | 89 | |
|
74 | 90 | The ``application/hg-error`` media type indicates a generic error occurred. |
|
75 | 91 | The content of the HTTP response body typically holds text describing the |
|
76 | 92 | error. |
|
77 | 93 | |
|
78 | 94 | The ``application/hg-changegroup`` media type indicates a changegroup response |
|
79 | 95 | type. |
|
80 | 96 | |
|
81 | 97 | Clients also accept the ``text/plain`` media type. All other media |
|
82 | 98 | types should cause the client to error. |
|
83 | 99 | |
|
100 | Behavior of media types is further described in the ``Content Negotiation`` | |
|
101 | section below. | |
|
102 | ||
|
84 | 103 | Clients should issue a ``User-Agent`` request header that identifies the client. |
|
85 | 104 | The server should not use the ``User-Agent`` for feature detection. |
|
86 | 105 | |
|
87 |
A command returning a ``string`` response issues |
|
|
88 |
``application/mercurial-0. |
|
|
89 | the raw string value. A ``Content-Length`` header is typically issued. | |
|
106 | A command returning a ``string`` response issues a | |
|
107 | ``application/mercurial-0.*`` media type and the HTTP response body contains | |
|
108 | the raw string value (after compression decoding, if used). A | |
|
109 | ``Content-Length`` header is typically issued, but not required. | |
|
90 | 110 | |
|
91 |
A command returning a ``stream`` response issues |
|
|
92 |
``application/mercurial-0. |
|
|
111 | A command returning a ``stream`` response issues a | |
|
112 | ``application/mercurial-0.*`` media type and the HTTP response is typically | |
|
93 | 113 | using *chunked transfer* (``Transfer-Encoding: chunked``). |
|
94 | 114 | |
|
95 | 115 | SSH Transport |
|
96 | 116 | ============= |
|
97 | 117 | |
|
98 | 118 | The SSH transport is a custom text-based protocol suitable for use over any |
|
99 | 119 | bi-directional stream transport. It is most commonly used with SSH. |
|
100 | 120 | |
|
101 | 121 | A SSH transport server can be started with ``hg serve --stdio``. The stdin, |
|
102 | 122 | stderr, and stdout file descriptors of the started process are used to exchange |
|
103 | 123 | data. When Mercurial connects to a remote server over SSH, it actually starts |
|
104 | 124 | a ``hg serve --stdio`` process on the remote server. |
|
105 | 125 | |
|
106 | 126 | Commands are issued by sending the command name followed by a trailing newline |
|
107 | 127 | ``\n`` to the server. e.g. ``capabilities\n``. |
|
108 | 128 | |
|
109 | 129 | Command arguments are sent in the following format:: |
|
110 | 130 | |
|
111 | 131 | <argument> <length>\n<value> |
|
112 | 132 | |
|
113 | 133 | That is, the argument string name followed by a space followed by the |
|
114 | 134 | integer length of the value (expressed as a string) followed by a newline |
|
115 | 135 | (``\n``) followed by the raw argument value. |
|
116 | 136 | |
|
117 | 137 | Dictionary arguments are encoded differently:: |
|
118 | 138 | |
|
119 | 139 | <argument> <# elements>\n |
|
120 | 140 | <key1> <length1>\n<value1> |
|
121 | 141 | <key2> <length2>\n<value2> |
|
122 | 142 | ... |
|
123 | 143 | |
|
124 | 144 | Non-argument data is sent immediately after the final argument value. It is |
|
125 | 145 | encoded in chunks:: |
|
126 | 146 | |
|
127 | 147 | <length>\n<data> |
|
128 | 148 | |
|
129 | 149 | Each command declares a list of supported arguments and their types. If a |
|
130 | 150 | client sends an unknown argument to the server, the server should abort |
|
131 | 151 | immediately. The special argument ``*`` in a command's definition indicates |
|
132 | 152 | that all argument names are allowed. |
|
133 | 153 | |
|
134 | 154 | The definition of supported arguments and types is initially made when a |
|
135 | 155 | new command is implemented. The client and server must initially independently |
|
136 | 156 | agree on the arguments and their types. This initial set of arguments can be |
|
137 | 157 | supplemented through the presence of *capabilities* advertised by the server. |
|
138 | 158 | |
|
139 | 159 | Each command has a defined expected response type. |
|
140 | 160 | |
|
141 | 161 | A ``string`` response type is a length framed value. The response consists of |
|
142 | 162 | the string encoded integer length of a value followed by a newline (``\n``) |
|
143 | 163 | followed by the value. Empty values are allowed (and are represented as |
|
144 | 164 | ``0\n``). |
|
145 | 165 | |
|
146 | 166 | A ``stream`` response type consists of raw bytes of data. There is no framing. |
|
147 | 167 | |
|
148 | 168 | A generic error response type is also supported. It consists of a an error |
|
149 | 169 | message written to ``stderr`` followed by ``\n-\n``. In addition, ``\n`` is |
|
150 | 170 | written to ``stdout``. |
|
151 | 171 | |
|
152 | 172 | If the server receives an unknown command, it will send an empty ``string`` |
|
153 | 173 | response. |
|
154 | 174 | |
|
155 | 175 | The server terminates if it receives an empty command (a ``\n`` character). |
|
156 | 176 | |
|
157 | 177 | Capabilities |
|
158 | 178 | ============ |
|
159 | 179 | |
|
160 | 180 | Servers advertise supported wire protocol features. This allows clients to |
|
161 | 181 | probe for server features before blindly calling a command or passing a |
|
162 | 182 | specific argument. |
|
163 | 183 | |
|
164 | 184 | The server's features are exposed via a *capabilities* string. This is a |
|
165 | 185 | space-delimited string of tokens/features. Some features are single words |
|
166 | 186 | like ``lookup`` or ``batch``. Others are complicated key-value pairs |
|
167 | 187 | advertising sub-features. e.g. ``httpheader=2048``. When complex, non-word |
|
168 | 188 | values are used, each feature name can define its own encoding of sub-values. |
|
169 | 189 | Comma-delimited and ``x-www-form-urlencoded`` values are common. |
|
170 | 190 | |
|
171 | 191 | The following document capabilities defined by the canonical Mercurial server |
|
172 | 192 | implementation. |
|
173 | 193 | |
|
174 | 194 | batch |
|
175 | 195 | ----- |
|
176 | 196 | |
|
177 | 197 | Whether the server supports the ``batch`` command. |
|
178 | 198 | |
|
179 | 199 | This capability/command was introduced in Mercurial 1.9 (released July 2011). |
|
180 | 200 | |
|
181 | 201 | branchmap |
|
182 | 202 | --------- |
|
183 | 203 | |
|
184 | 204 | Whether the server supports the ``branchmap`` command. |
|
185 | 205 | |
|
186 | 206 | This capability/command was introduced in Mercurial 1.3 (released July 2009). |
|
187 | 207 | |
|
188 | 208 | bundle2-exp |
|
189 | 209 | ----------- |
|
190 | 210 | |
|
191 | 211 | Precursor to ``bundle2`` capability that was used before bundle2 was a |
|
192 | 212 | stable feature. |
|
193 | 213 | |
|
194 | 214 | This capability was introduced in Mercurial 3.0 behind an experimental |
|
195 | 215 | flag. This capability should not be observed in the wild. |
|
196 | 216 | |
|
197 | 217 | bundle2 |
|
198 | 218 | ------- |
|
199 | 219 | |
|
200 | 220 | Indicates whether the server supports the ``bundle2`` data exchange format. |
|
201 | 221 | |
|
202 | 222 | The value of the capability is a URL quoted, newline (``\n``) delimited |
|
203 | 223 | list of keys or key-value pairs. |
|
204 | 224 | |
|
205 | 225 | A key is simply a URL encoded string. |
|
206 | 226 | |
|
207 | 227 | A key-value pair is a URL encoded key separated from a URL encoded value by |
|
208 | 228 | an ``=``. If the value is a list, elements are delimited by a ``,`` after |
|
209 | 229 | URL encoding. |
|
210 | 230 | |
|
211 | 231 | For example, say we have the values:: |
|
212 | 232 | |
|
213 | 233 | {'HG20': [], 'changegroup': ['01', '02'], 'digests': ['sha1', 'sha512']} |
|
214 | 234 | |
|
215 | 235 | We would first construct a string:: |
|
216 | 236 | |
|
217 | 237 | HG20\nchangegroup=01,02\ndigests=sha1,sha512 |
|
218 | 238 | |
|
219 | 239 | We would then URL quote this string:: |
|
220 | 240 | |
|
221 | 241 | HG20%0Achangegroup%3D01%2C02%0Adigests%3Dsha1%2Csha512 |
|
222 | 242 | |
|
223 | 243 | This capability was introduced in Mercurial 3.4 (released May 2015). |
|
224 | 244 | |
|
225 | 245 | changegroupsubset |
|
226 | 246 | ----------------- |
|
227 | 247 | |
|
228 | 248 | Whether the server supports the ``changegroupsubset`` command. |
|
229 | 249 | |
|
230 | 250 | This capability was introduced in Mercurial 0.9.2 (released December |
|
231 | 251 | 2006). |
|
232 | 252 | |
|
233 | 253 | This capability was introduced at the same time as the ``lookup`` |
|
234 | 254 | capability/command. |
|
235 | 255 | |
|
256 | compression | |
|
257 | ----------- | |
|
258 | ||
|
259 | Declares support for negotiating compression formats. | |
|
260 | ||
|
261 | Presence of this capability indicates the server supports dynamic selection | |
|
262 | of compression formats based on the client request. | |
|
263 | ||
|
264 | Servers advertising this capability are required to support the | |
|
265 | ``application/mercurial-0.2`` media type in response to commands returning | |
|
266 | streams. Servers may support this media type on any command. | |
|
267 | ||
|
268 | The value of the capability is a comma-delimited list of strings declaring | |
|
269 | supported compression formats. The order of the compression formats is in | |
|
270 | server-preferred order, most preferred first. | |
|
271 | ||
|
272 | This capability was introduced in Mercurial 4.1 (released February 2017). | |
|
273 | ||
|
236 | 274 | getbundle |
|
237 | 275 | --------- |
|
238 | 276 | |
|
239 | 277 | Whether the server supports the ``getbundle`` command. |
|
240 | 278 | |
|
241 | 279 | This capability was introduced in Mercurial 1.9 (released July 2011). |
|
242 | 280 | |
|
243 | 281 | httpheader |
|
244 | 282 | ---------- |
|
245 | 283 | |
|
246 | 284 | Whether the server supports receiving command arguments via HTTP request |
|
247 | 285 | headers. |
|
248 | 286 | |
|
249 | 287 | The value of the capability is an integer describing the max header |
|
250 | 288 | length that clients should send. Clients should ignore any content after a |
|
251 | 289 | comma in the value, as this is reserved for future use. |
|
252 | 290 | |
|
253 | 291 | This capability was introduced in Mercurial 1.9 (released July 2011). |
|
254 | 292 | |
|
293 | httpmediatype | |
|
294 | ------------- | |
|
295 | ||
|
296 | Indicates which HTTP media types (``Content-Type`` header) the server is | |
|
297 | capable of receiving and sending. | |
|
298 | ||
|
299 | The value of the capability is a comma-delimited list of strings identifying | |
|
300 | support for media type and transmission direction. The following strings may | |
|
301 | be present: | |
|
302 | ||
|
303 | 0.1rx | |
|
304 | Indicates server support for receiving ``application/mercurial-0.1`` media | |
|
305 | types. | |
|
306 | ||
|
307 | 0.1tx | |
|
308 | Indicates server support for sending ``application/mercurial-0.1`` media | |
|
309 | types. | |
|
310 | ||
|
311 | 0.2rx | |
|
312 | Indicates server support for receiving ``application/mercurial-0.2`` media | |
|
313 | types. | |
|
314 | ||
|
315 | 0.2tx | |
|
316 | Indicates server support for sending ``application/mercurial-0.2`` media | |
|
317 | types. | |
|
318 | ||
|
319 | minrx=X | |
|
320 | Minimum media type version the server is capable of receiving. Value is a | |
|
321 | string like ``0.2``. | |
|
322 | ||
|
323 | This capability can be used by servers to limit connections from legacy | |
|
324 | clients not using the latest supported media type. However, only clients | |
|
325 | with knowledge of this capability will know to consult this value. This | |
|
326 | capability is present so the client may issue a more user-friendly error | |
|
327 | when the server has locked out a legacy client. | |
|
328 | ||
|
329 | mintx=X | |
|
330 | Minimum media type version the server is capable of sending. Value is a | |
|
331 | string like ``0.1``. | |
|
332 | ||
|
333 | Servers advertising support for the ``application/mercurial-0.2`` media type | |
|
334 | should also advertise the ``compression`` capability. | |
|
335 | ||
|
336 | This capability was introduced in Mercurial 4.1 (released February 2017). | |
|
337 | ||
|
255 | 338 | httppostargs |
|
256 | 339 | ------------ |
|
257 | 340 | |
|
258 | 341 | **Experimental** |
|
259 | 342 | |
|
260 | 343 | Indicates that the server supports and prefers clients send command arguments |
|
261 | 344 | via a HTTP POST request as part of the request body. |
|
262 | 345 | |
|
263 | 346 | This capability was introduced in Mercurial 3.8 (released May 2016). |
|
264 | 347 | |
|
265 | 348 | known |
|
266 | 349 | ----- |
|
267 | 350 | |
|
268 | 351 | Whether the server supports the ``known`` command. |
|
269 | 352 | |
|
270 | 353 | This capability/command was introduced in Mercurial 1.9 (released July 2011). |
|
271 | 354 | |
|
272 | 355 | lookup |
|
273 | 356 | ------ |
|
274 | 357 | |
|
275 | 358 | Whether the server supports the ``lookup`` command. |
|
276 | 359 | |
|
277 | 360 | This capability was introduced in Mercurial 0.9.2 (released December |
|
278 | 361 | 2006). |
|
279 | 362 | |
|
280 | 363 | This capability was introduced at the same time as the ``changegroupsubset`` |
|
281 | 364 | capability/command. |
|
282 | 365 | |
|
283 | 366 | pushkey |
|
284 | 367 | ------- |
|
285 | 368 | |
|
286 | 369 | Whether the server supports the ``pushkey`` and ``listkeys`` commands. |
|
287 | 370 | |
|
288 | 371 | This capability was introduced in Mercurial 1.6 (released July 2010). |
|
289 | 372 | |
|
290 | 373 | standardbundle |
|
291 | 374 | -------------- |
|
292 | 375 | |
|
293 | 376 | **Unsupported** |
|
294 | 377 | |
|
295 | 378 | This capability was introduced during the Mercurial 0.9.2 development cycle in |
|
296 | 379 | 2006. It was never present in a release, as it was replaced by the ``unbundle`` |
|
297 | 380 | capability. This capability should not be encountered in the wild. |
|
298 | 381 | |
|
299 | 382 | stream-preferred |
|
300 | 383 | ---------------- |
|
301 | 384 | |
|
302 | 385 | If present the server prefers that clients clone using the streaming clone |
|
303 | 386 | protocol (``hg clone --uncompressed``) rather than the standard |
|
304 | 387 | changegroup/bundle based protocol. |
|
305 | 388 | |
|
306 | 389 | This capability was introduced in Mercurial 2.2 (released May 2012). |
|
307 | 390 | |
|
308 | 391 | streamreqs |
|
309 | 392 | ---------- |
|
310 | 393 | |
|
311 | 394 | Indicates whether the server supports *streaming clones* and the *requirements* |
|
312 | 395 | that clients must support to receive it. |
|
313 | 396 | |
|
314 | 397 | If present, the server supports the ``stream_out`` command, which transmits |
|
315 | 398 | raw revlogs from the repository instead of changegroups. This provides a faster |
|
316 | 399 | cloning mechanism at the expense of more bandwidth used. |
|
317 | 400 | |
|
318 | 401 | The value of this capability is a comma-delimited list of repo format |
|
319 | 402 | *requirements*. These are requirements that impact the reading of data in |
|
320 | 403 | the ``.hg/store`` directory. An example value is |
|
321 | 404 | ``streamreqs=generaldelta,revlogv1`` indicating the server repo requires |
|
322 | 405 | the ``revlogv1`` and ``generaldelta`` requirements. |
|
323 | 406 | |
|
324 | 407 | If the only format requirement is ``revlogv1``, the server may expose the |
|
325 | 408 | ``stream`` capability instead of the ``streamreqs`` capability. |
|
326 | 409 | |
|
327 | 410 | This capability was introduced in Mercurial 1.7 (released November 2010). |
|
328 | 411 | |
|
329 | 412 | stream |
|
330 | 413 | ------ |
|
331 | 414 | |
|
332 | 415 | Whether the server supports *streaming clones* from ``revlogv1`` repos. |
|
333 | 416 | |
|
334 | 417 | If present, the server supports the ``stream_out`` command, which transmits |
|
335 | 418 | raw revlogs from the repository instead of changegroups. This provides a faster |
|
336 | 419 | cloning mechanism at the expense of more bandwidth used. |
|
337 | 420 | |
|
338 | 421 | This capability was introduced in Mercurial 0.9.1 (released July 2006). |
|
339 | 422 | |
|
340 | 423 | When initially introduced, the value of the capability was the numeric |
|
341 | 424 | revlog revision. e.g. ``stream=1``. This indicates the changegroup is using |
|
342 | 425 | ``revlogv1``. This simple integer value wasn't powerful enough, so the |
|
343 | 426 | ``streamreqs`` capability was invented to handle cases where the repo |
|
344 | 427 | requirements have more than just ``revlogv1``. Newer servers omit the |
|
345 | 428 | ``=1`` since it was the only value supported and the value of ``1`` can |
|
346 | 429 | be implied by clients. |
|
347 | 430 | |
|
348 | 431 | unbundlehash |
|
349 | 432 | ------------ |
|
350 | 433 | |
|
351 | 434 | Whether the ``unbundle`` commands supports receiving a hash of all the |
|
352 | 435 | heads instead of a list. |
|
353 | 436 | |
|
354 | 437 | For more, see the documentation for the ``unbundle`` command. |
|
355 | 438 | |
|
356 | 439 | This capability was introduced in Mercurial 1.9 (released July 2011). |
|
357 | 440 | |
|
358 | 441 | unbundle |
|
359 | 442 | -------- |
|
360 | 443 | |
|
361 | 444 | Whether the server supports pushing via the ``unbundle`` command. |
|
362 | 445 | |
|
363 | 446 | This capability/command has been present since Mercurial 0.9.1 (released |
|
364 | 447 | July 2006). |
|
365 | 448 | |
|
366 | 449 | Mercurial 0.9.2 (released December 2006) added values to the capability |
|
367 | 450 | indicating which bundle types the server supports receiving. This value is a |
|
368 | 451 | comma-delimited list. e.g. ``HG10GZ,HG10BZ,HG10UN``. The order of values |
|
369 | 452 | reflects the priority/preference of that type, where the first value is the |
|
370 | 453 | most preferred type. |
|
371 | 454 | |
|
372 | 455 | Handshake Protocol |
|
373 | 456 | ================== |
|
374 | 457 | |
|
375 | 458 | While not explicitly required, it is common for clients to perform a |
|
376 | 459 | *handshake* when connecting to a server. The handshake accomplishes 2 things: |
|
377 | 460 | |
|
378 | 461 | * Obtaining capabilities and other server features |
|
379 | 462 | * Flushing extra server output (e.g. SSH servers may print extra text |
|
380 | 463 | when connecting that may confuse the wire protocol) |
|
381 | 464 | |
|
382 | 465 | This isn't a traditional *handshake* as far as network protocols go because |
|
383 | 466 | there is no persistent state as a result of the handshake: the handshake is |
|
384 | 467 | simply the issuing of commands and commands are stateless. |
|
385 | 468 | |
|
386 | 469 | The canonical clients perform a capabilities lookup at connection establishment |
|
387 | 470 | time. This is because clients must assume a server only supports the features |
|
388 | 471 | of the original Mercurial server implementation until proven otherwise (from |
|
389 | 472 | advertised capabilities). Nearly every server running today supports features |
|
390 | 473 | that weren't present in the original Mercurial server implementation. Rather |
|
391 | 474 | than wait for a client to perform functionality that needs to consult |
|
392 | 475 | capabilities, it issues the lookup at connection start to avoid any delay later. |
|
393 | 476 | |
|
394 | 477 | For HTTP servers, the client sends a ``capabilities`` command request as |
|
395 | 478 | soon as the connection is established. The server responds with a capabilities |
|
396 | 479 | string, which the client parses. |
|
397 | 480 | |
|
398 | 481 | For SSH servers, the client sends the ``hello`` command (no arguments) |
|
399 | 482 | and a ``between`` command with the ``pairs`` argument having the value |
|
400 | 483 | ``0000000000000000000000000000000000000000-0000000000000000000000000000000000000000``. |
|
401 | 484 | |
|
402 | 485 | The ``between`` command has been supported since the original Mercurial |
|
403 | 486 | server. Requesting the empty range will return a ``\n`` string response, |
|
404 | 487 | which will be encoded as ``1\n\n`` (value length of ``1`` followed by a newline |
|
405 | 488 | followed by the value, which happens to be a newline). |
|
406 | 489 | |
|
407 | 490 | The ``hello`` command was later introduced. Servers supporting it will issue |
|
408 | 491 | a response to that command before sending the ``1\n\n`` response to the |
|
409 | 492 | ``between`` command. Servers not supporting ``hello`` will send an empty |
|
410 | 493 | response (``0\n``). |
|
411 | 494 | |
|
412 | 495 | In addition to the expected output from the ``hello`` and ``between`` commands, |
|
413 | 496 | servers may also send other output, such as *message of the day (MOTD)* |
|
414 | 497 | announcements. Clients assume servers will send this output before the |
|
415 | 498 | Mercurial server replies to the client-issued commands. So any server output |
|
416 | 499 | not conforming to the expected command responses is assumed to be not related |
|
417 | 500 | to Mercurial and can be ignored. |
|
418 | 501 | |
|
502 | Content Negotiation | |
|
503 | =================== | |
|
504 | ||
|
505 | The wire protocol has some mechanisms to help peers determine what content | |
|
506 | types and encoding the other side will accept. Historically, these mechanisms | |
|
507 | have been built into commands themselves because most commands only send a | |
|
508 | well-defined response type and only certain commands needed to support | |
|
509 | functionality like compression. | |
|
510 | ||
|
511 | Currently, only the HTTP transport supports content negotiation at the protocol | |
|
512 | layer. | |
|
513 | ||
|
514 | HTTP requests advertise supported response formats via the ``X-HgProto-<N>`` | |
|
515 | request header, where ``<N>`` is an integer starting at 1 allowing the logical | |
|
516 | value to span multiple headers. This value consists of a list of | |
|
517 | space-delimited parameters. Each parameter denotes a feature or capability. | |
|
518 | ||
|
519 | The following parameters are defined: | |
|
520 | ||
|
521 | 0.1 | |
|
522 | Indicates the client supports receiving ``application/mercurial-0.1`` | |
|
523 | responses. | |
|
524 | ||
|
525 | 0.2 | |
|
526 | Indicates the client supports receiving ``application/mercurial-0.2`` | |
|
527 | responses. | |
|
528 | ||
|
529 | comp | |
|
530 | Indicates compression formats the client can decode. Value is a list of | |
|
531 | comma delimited strings identifying compression formats ordered from | |
|
532 | most preferential to least preferential. e.g. ``comp=zstd,zlib,none``. | |
|
533 | ||
|
534 | This parameter does not have an effect if only the ``0.1`` parameter | |
|
535 | is defined, as support for ``application/mercurial-0.2`` or greater is | |
|
536 | required to use arbitrary compression formats. | |
|
537 | ||
|
538 | If this parameter is not advertised, the server interprets this as | |
|
539 | equivalent to ``zlib,none``. | |
|
540 | ||
|
541 | Clients may choose to only send this header if the ``httpmediatype`` | |
|
542 | server capability is present, as currently all server-side features | |
|
543 | consulting this header require the client to opt in to new protocol features | |
|
544 | advertised via the ``httpmediatype`` capability. | |
|
545 | ||
|
546 | A server that doesn't receive an ``X-HgProto-<N>`` header should infer a | |
|
547 | value of ``0.1``. This is compatible with legacy clients. | |
|
548 | ||
|
549 | A server receiving a request indicating support for multiple media type | |
|
550 | versions may respond with any of the supported media types. Not all servers | |
|
551 | may support all media types on all commands. | |
|
552 | ||
|
419 | 553 | Commands |
|
420 | 554 | ======== |
|
421 | 555 | |
|
422 | 556 | This section contains a list of all wire protocol commands implemented by |
|
423 | 557 | the canonical Mercurial server. |
|
424 | 558 | |
|
425 | 559 | batch |
|
426 | 560 | ----- |
|
427 | 561 | |
|
428 | 562 | Issue multiple commands while sending a single command request. The purpose |
|
429 | 563 | of this command is to allow a client to issue multiple commands while avoiding |
|
430 | 564 | multiple round trips to the server therefore enabling commands to complete |
|
431 | 565 | quicker. |
|
432 | 566 | |
|
433 | 567 | The command accepts a ``cmds`` argument that contains a list of commands to |
|
434 | 568 | execute. |
|
435 | 569 | |
|
436 | 570 | The value of ``cmds`` is a ``;`` delimited list of strings. Each string has the |
|
437 | 571 | form ``<command> <arguments>``. That is, the command name followed by a space |
|
438 | 572 | followed by an argument string. |
|
439 | 573 | |
|
440 | 574 | The argument string is a ``,`` delimited list of ``<key>=<value>`` values |
|
441 | 575 | corresponding to command arguments. Both the argument name and value are |
|
442 | 576 | escaped using a special substitution map:: |
|
443 | 577 | |
|
444 | 578 | : -> :c |
|
445 | 579 | , -> :o |
|
446 | 580 | ; -> :s |
|
447 | 581 | = -> :e |
|
448 | 582 | |
|
449 | 583 | The response type for this command is ``string``. The value contains a |
|
450 | 584 | ``;`` delimited list of responses for each requested command. Each value |
|
451 | 585 | in this list is escaped using the same substitution map used for arguments. |
|
452 | 586 | |
|
453 | 587 | If an error occurs, the generic error response may be sent. |
|
454 | 588 | |
|
455 | 589 | between |
|
456 | 590 | ------- |
|
457 | 591 | |
|
458 | 592 | (Legacy command used for discovery in old clients) |
|
459 | 593 | |
|
460 | 594 | Obtain nodes between pairs of nodes. |
|
461 | 595 | |
|
462 | 596 | The ``pairs`` arguments contains a space-delimited list of ``-`` delimited |
|
463 | 597 | hex node pairs. e.g.:: |
|
464 | 598 | |
|
465 | 599 | a072279d3f7fd3a4aa7ffa1a5af8efc573e1c896-6dc58916e7c070f678682bfe404d2e2d68291a18 |
|
466 | 600 | |
|
467 | 601 | Return type is a ``string``. Value consists of lines corresponding to each |
|
468 | 602 | requested range. Each line contains a space-delimited list of hex nodes. |
|
469 | 603 | A newline ``\n`` terminates each line, including the last one. |
|
470 | 604 | |
|
471 | 605 | branchmap |
|
472 | 606 | --------- |
|
473 | 607 | |
|
474 | 608 | Obtain heads in named branches. |
|
475 | 609 | |
|
476 | 610 | Accepts no arguments. Return type is a ``string``. |
|
477 | 611 | |
|
478 | 612 | Return value contains lines with URL encoded branch names followed by a space |
|
479 | 613 | followed by a space-delimited list of hex nodes of heads on that branch. |
|
480 | 614 | e.g.:: |
|
481 | 615 | |
|
482 | 616 | default a072279d3f7fd3a4aa7ffa1a5af8efc573e1c896 6dc58916e7c070f678682bfe404d2e2d68291a18 |
|
483 | 617 | stable baae3bf31522f41dd5e6d7377d0edd8d1cf3fccc |
|
484 | 618 | |
|
485 | 619 | There is no trailing newline. |
|
486 | 620 | |
|
487 | 621 | branches |
|
488 | 622 | -------- |
|
489 | 623 | |
|
490 | 624 | Obtain ancestor changesets of specific nodes back to a branch point. |
|
491 | 625 | |
|
492 | 626 | Despite the name, this command has nothing to do with Mercurial named branches. |
|
493 | 627 | Instead, it is related to DAG branches. |
|
494 | 628 | |
|
495 | 629 | The command accepts a ``nodes`` argument, which is a string of space-delimited |
|
496 | 630 | hex nodes. |
|
497 | 631 | |
|
498 | 632 | For each node requested, the server will find the first ancestor node that is |
|
499 | 633 | a DAG root or is a merge. |
|
500 | 634 | |
|
501 | 635 | Return type is a ``string``. Return value contains lines with result data for |
|
502 | 636 | each requested node. Each line contains space-delimited nodes followed by a |
|
503 | 637 | newline (``\n``). The 4 nodes reported on each line correspond to the requested |
|
504 | 638 | node, the ancestor node found, and its 2 parent nodes (which may be the null |
|
505 | 639 | node). |
|
506 | 640 | |
|
507 | 641 | capabilities |
|
508 | 642 | ------------ |
|
509 | 643 | |
|
510 | 644 | Obtain the capabilities string for the repo. |
|
511 | 645 | |
|
512 | 646 | Unlike the ``hello`` command, the capabilities string is not prefixed. |
|
513 | 647 | There is no trailing newline. |
|
514 | 648 | |
|
515 | 649 | This command does not accept any arguments. Return type is a ``string``. |
|
516 | 650 | |
|
517 | 651 | changegroup |
|
518 | 652 | ----------- |
|
519 | 653 | |
|
520 | 654 | (Legacy command: use ``getbundle`` instead) |
|
521 | 655 | |
|
522 | 656 | Obtain a changegroup version 1 with data for changesets that are |
|
523 | 657 | descendants of client-specified changesets. |
|
524 | 658 | |
|
525 | 659 | The ``roots`` arguments contains a list of space-delimited hex nodes. |
|
526 | 660 | |
|
527 | 661 | The server responds with a changegroup version 1 containing all |
|
528 | 662 | changesets between the requested root/base nodes and the repo's head nodes |
|
529 | 663 | at the time of the request. |
|
530 | 664 | |
|
531 | 665 | The return type is a ``stream``. |
|
532 | 666 | |
|
533 | 667 | changegroupsubset |
|
534 | 668 | ----------------- |
|
535 | 669 | |
|
536 | 670 | (Legacy command: use ``getbundle`` instead) |
|
537 | 671 | |
|
538 | 672 | Obtain a changegroup version 1 with data for changesetsets between |
|
539 | 673 | client specified base and head nodes. |
|
540 | 674 | |
|
541 | 675 | The ``bases`` argument contains a list of space-delimited hex nodes. |
|
542 | 676 | The ``heads`` argument contains a list of space-delimited hex nodes. |
|
543 | 677 | |
|
544 | 678 | The server responds with a changegroup version 1 containing all |
|
545 | 679 | changesets between the requested base and head nodes at the time of the |
|
546 | 680 | request. |
|
547 | 681 | |
|
548 | 682 | The return type is a ``stream``. |
|
549 | 683 | |
|
550 | 684 | clonebundles |
|
551 | 685 | ------------ |
|
552 | 686 | |
|
553 | 687 | Obtains a manifest of bundle URLs available to seed clones. |
|
554 | 688 | |
|
555 | 689 | Each returned line contains a URL followed by metadata. See the |
|
556 | 690 | documentation in the ``clonebundles`` extension for more. |
|
557 | 691 | |
|
558 | 692 | The return type is a ``string``. |
|
559 | 693 | |
|
560 | 694 | getbundle |
|
561 | 695 | --------- |
|
562 | 696 | |
|
563 | 697 | Obtain a bundle containing repository data. |
|
564 | 698 | |
|
565 | 699 | This command accepts the following arguments: |
|
566 | 700 | |
|
567 | 701 | heads |
|
568 | 702 | List of space-delimited hex nodes of heads to retrieve. |
|
569 | 703 | common |
|
570 | 704 | List of space-delimited hex nodes that the client has in common with the |
|
571 | 705 | server. |
|
572 | 706 | obsmarkers |
|
573 | 707 | Boolean indicating whether to include obsolescence markers as part |
|
574 | 708 | of the response. Only works with bundle2. |
|
575 | 709 | bundlecaps |
|
576 | 710 | Comma-delimited set of strings defining client bundle capabilities. |
|
577 | 711 | listkeys |
|
578 | 712 | Comma-delimited list of strings of ``pushkey`` namespaces. For each |
|
579 | 713 | namespace listed, a bundle2 part will be included with the content of |
|
580 | 714 | that namespace. |
|
581 | 715 | cg |
|
582 | 716 | Boolean indicating whether changegroup data is requested. |
|
583 | 717 | cbattempted |
|
584 | 718 | Boolean indicating whether the client attempted to use the *clone bundles* |
|
585 | 719 | feature before performing this request. |
|
586 | 720 | |
|
587 | 721 | The return type on success is a ``stream`` where the value is bundle. |
|
588 | 722 | On the HTTP transport, the response is zlib compressed. |
|
589 | 723 | |
|
590 | 724 | If an error occurs, a generic error response can be sent. |
|
591 | 725 | |
|
592 | 726 | Unless the client sends a false value for the ``cg`` argument, the returned |
|
593 | 727 | bundle contains a changegroup with the nodes between the specified ``common`` |
|
594 | 728 | and ``heads`` nodes. Depending on the command arguments, the type and content |
|
595 | 729 | of the returned bundle can vary significantly. |
|
596 | 730 | |
|
597 | 731 | The default behavior is for the server to send a raw changegroup version |
|
598 | 732 | ``01`` response. |
|
599 | 733 | |
|
600 | 734 | If the ``bundlecaps`` provided by the client contain a value beginning |
|
601 | 735 | with ``HG2``, a bundle2 will be returned. The bundle2 data may contain |
|
602 | 736 | additional repository data, such as ``pushkey`` namespace values. |
|
603 | 737 | |
|
604 | 738 | heads |
|
605 | 739 | ----- |
|
606 | 740 | |
|
607 | 741 | Returns a list of space-delimited hex nodes of repository heads followed |
|
608 | 742 | by a newline. e.g. |
|
609 | 743 | ``a9eeb3adc7ddb5006c088e9eda61791c777cbf7c 31f91a3da534dc849f0d6bfc00a395a97cf218a1\n`` |
|
610 | 744 | |
|
611 | 745 | This command does not accept any arguments. The return type is a ``string``. |
|
612 | 746 | |
|
613 | 747 | hello |
|
614 | 748 | ----- |
|
615 | 749 | |
|
616 | 750 | Returns lines describing interesting things about the server in an RFC-822 |
|
617 | 751 | like format. |
|
618 | 752 | |
|
619 | 753 | Currently, the only line defines the server capabilities. It has the form:: |
|
620 | 754 | |
|
621 | 755 | capabilities: <value> |
|
622 | 756 | |
|
623 | 757 | See above for more about the capabilities string. |
|
624 | 758 | |
|
625 | 759 | SSH clients typically issue this command as soon as a connection is |
|
626 | 760 | established. |
|
627 | 761 | |
|
628 | 762 | This command does not accept any arguments. The return type is a ``string``. |
|
629 | 763 | |
|
630 | 764 | listkeys |
|
631 | 765 | -------- |
|
632 | 766 | |
|
633 | 767 | List values in a specified ``pushkey`` namespace. |
|
634 | 768 | |
|
635 | 769 | The ``namespace`` argument defines the pushkey namespace to operate on. |
|
636 | 770 | |
|
637 | 771 | The return type is a ``string``. The value is an encoded dictionary of keys. |
|
638 | 772 | |
|
639 | 773 | Key-value pairs are delimited by newlines (``\n``). Within each line, keys and |
|
640 | 774 | values are separated by a tab (``\t``). Keys and values are both strings. |
|
641 | 775 | |
|
642 | 776 | lookup |
|
643 | 777 | ------ |
|
644 | 778 | |
|
645 | 779 | Try to resolve a value to a known repository revision. |
|
646 | 780 | |
|
647 | 781 | The ``key`` argument is converted from bytes to an |
|
648 | 782 | ``encoding.localstr`` instance then passed into |
|
649 | 783 | ``localrepository.__getitem__`` in an attempt to resolve it. |
|
650 | 784 | |
|
651 | 785 | The return type is a ``string``. |
|
652 | 786 | |
|
653 | 787 | Upon successful resolution, returns ``1 <hex node>\n``. On failure, |
|
654 | 788 | returns ``0 <error string>\n``. e.g.:: |
|
655 | 789 | |
|
656 | 790 | 1 273ce12ad8f155317b2c078ec75a4eba507f1fba\n |
|
657 | 791 | |
|
658 | 792 | 0 unknown revision 'foo'\n |
|
659 | 793 | |
|
660 | 794 | known |
|
661 | 795 | ----- |
|
662 | 796 | |
|
663 | 797 | Determine whether multiple nodes are known. |
|
664 | 798 | |
|
665 | 799 | The ``nodes`` argument is a list of space-delimited hex nodes to check |
|
666 | 800 | for existence. |
|
667 | 801 | |
|
668 | 802 | The return type is ``string``. |
|
669 | 803 | |
|
670 | 804 | Returns a string consisting of ``0``s and ``1``s indicating whether nodes |
|
671 | 805 | are known. If the Nth node specified in the ``nodes`` argument is known, |
|
672 | 806 | a ``1`` will be returned at byte offset N. If the node isn't known, ``0`` |
|
673 | 807 | will be present at byte offset N. |
|
674 | 808 | |
|
675 | 809 | There is no trailing newline. |
|
676 | 810 | |
|
677 | 811 | pushkey |
|
678 | 812 | ------- |
|
679 | 813 | |
|
680 | 814 | Set a value using the ``pushkey`` protocol. |
|
681 | 815 | |
|
682 | 816 | Accepts arguments ``namespace``, ``key``, ``old``, and ``new``, which |
|
683 | 817 | correspond to the pushkey namespace to operate on, the key within that |
|
684 | 818 | namespace to change, the old value (which may be empty), and the new value. |
|
685 | 819 | All arguments are string types. |
|
686 | 820 | |
|
687 | 821 | The return type is a ``string``. The value depends on the transport protocol. |
|
688 | 822 | |
|
689 | 823 | The SSH transport sends a string encoded integer followed by a newline |
|
690 | 824 | (``\n``) which indicates operation result. The server may send additional |
|
691 | 825 | output on the ``stderr`` stream that should be displayed to the user. |
|
692 | 826 | |
|
693 | 827 | The HTTP transport sends a string encoded integer followed by a newline |
|
694 | 828 | followed by additional server output that should be displayed to the user. |
|
695 | 829 | This may include output from hooks, etc. |
|
696 | 830 | |
|
697 | 831 | The integer result varies by namespace. ``0`` means an error has occurred |
|
698 | 832 | and there should be additional output to display to the user. |
|
699 | 833 | |
|
700 | 834 | stream_out |
|
701 | 835 | ---------- |
|
702 | 836 | |
|
703 | 837 | Obtain *streaming clone* data. |
|
704 | 838 | |
|
705 | 839 | The return type is either a ``string`` or a ``stream``, depending on |
|
706 | 840 | whether the request was fulfilled properly. |
|
707 | 841 | |
|
708 | 842 | A return value of ``1\n`` indicates the server is not configured to serve |
|
709 | 843 | this data. If this is seen by the client, they may not have verified the |
|
710 | 844 | ``stream`` capability is set before making the request. |
|
711 | 845 | |
|
712 | 846 | A return value of ``2\n`` indicates the server was unable to lock the |
|
713 | 847 | repository to generate data. |
|
714 | 848 | |
|
715 | 849 | All other responses are a ``stream`` of bytes. The first line of this data |
|
716 | 850 | contains 2 space-delimited integers corresponding to the path count and |
|
717 | 851 | payload size, respectively:: |
|
718 | 852 | |
|
719 | 853 | <path count> <payload size>\n |
|
720 | 854 | |
|
721 | 855 | The ``<payload size>`` is the total size of path data: it does not include |
|
722 | 856 | the size of the per-path header lines. |
|
723 | 857 | |
|
724 | 858 | Following that header are ``<path count>`` entries. Each entry consists of a |
|
725 | 859 | line with metadata followed by raw revlog data. The line consists of:: |
|
726 | 860 | |
|
727 | 861 | <store path>\0<size>\n |
|
728 | 862 | |
|
729 | 863 | The ``<store path>`` is the encoded store path of the data that follows. |
|
730 | 864 | ``<size>`` is the amount of data for this store path/revlog that follows the |
|
731 | 865 | newline. |
|
732 | 866 | |
|
733 | 867 | There is no trailer to indicate end of data. Instead, the client should stop |
|
734 | 868 | reading after ``<path count>`` entries are consumed. |
|
735 | 869 | |
|
736 | 870 | unbundle |
|
737 | 871 | -------- |
|
738 | 872 | |
|
739 | 873 | Send a bundle containing data (usually changegroup data) to the server. |
|
740 | 874 | |
|
741 | 875 | Accepts the argument ``heads``, which is a space-delimited list of hex nodes |
|
742 | 876 | corresponding to server repository heads observed by the client. This is used |
|
743 | 877 | to detect race conditions and abort push operations before a server performs |
|
744 | 878 | too much work or a client transfers too much data. |
|
745 | 879 | |
|
746 | 880 | The request payload consists of a bundle to be applied to the repository, |
|
747 | 881 | similarly to as if :hg:`unbundle` were called. |
|
748 | 882 | |
|
749 | 883 | In most scenarios, a special ``push response`` type is returned. This type |
|
750 | 884 | contains an integer describing the change in heads as a result of the |
|
751 | 885 | operation. A value of ``0`` indicates nothing changed. ``1`` means the number |
|
752 | 886 | of heads remained the same. Values ``2`` and larger indicate the number of |
|
753 | 887 | added heads minus 1. e.g. ``3`` means 2 heads were added. Negative values |
|
754 | 888 | indicate the number of fewer heads, also off by 1. e.g. ``-2`` means there |
|
755 | 889 | is 1 fewer head. |
|
756 | 890 | |
|
757 | 891 | The encoding of the ``push response`` type varies by transport. |
|
758 | 892 | |
|
759 | 893 | For the SSH transport, this type is composed of 2 ``string`` responses: an |
|
760 | 894 | empty response (``0\n``) followed by the integer result value. e.g. |
|
761 | 895 | ``1\n2``. So the full response might be ``0\n1\n2``. |
|
762 | 896 | |
|
763 | 897 | For the HTTP transport, the response is a ``string`` type composed of an |
|
764 | 898 | integer result value followed by a newline (``\n``) followed by string |
|
765 | 899 | content holding server output that should be displayed on the client (output |
|
766 | 900 | hooks, etc). |
|
767 | 901 | |
|
768 | 902 | In some cases, the server may respond with a ``bundle2`` bundle. In this |
|
769 | 903 | case, the response type is ``stream``. For the HTTP transport, the response |
|
770 | 904 | is zlib compressed. |
|
771 | 905 | |
|
772 | 906 | The server may also respond with a generic error type, which contains a string |
|
773 | 907 | indicating the failure. |
General Comments 0
You need to be logged in to leave comments.
Login now