transport-helper: introduce stateless-connect

Introduce the transport-helper capability 'stateless-connect'. This capability indicates that the transport-helper can be requested to run the 'stateless-connect' command which should attempt to make a stateless connection with a remote end. Once established, the connection can be used by the git client to communicate with the remote end natively in a stateless-rpc manner as supported by protocol v2. This means that the client must send everything the server needs in a single request as the client must not assume any state-storing on the part of the server or transport. If a stateless connection cannot be established then the remote-helper will respond in the same manner as the 'connect' command indicating that the client should fallback to using the dumb remote-helper commands. A future patch will implement the 'stateless-connect' capability in our http remote-helper (remote-curl) so that protocol v2 can be used using the http transport. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Williams committed Mar 15, 2018 at 10:31 UTC edc9caf7e2ecd3d5327e78a3e539eda61a0e4d81
4 files changed +50
Documentation/gitremote-helpers.txt
+32
@@ -102,6 +102,14 @@ Capabilities for Pushing
102 +
103 Supported commands: 'connect'.
104
105 +'stateless-connect'::
106 + Experimental; for internal use only.
107 + Can attempt to connect to a remote server for communication
108 + using git's wire-protocol version 2. See the documentation
109 + for the stateless-connect command for more information.
110 ++
111 +Supported commands: 'stateless-connect'.
112 +
113 'push'::
114 Can discover remote refs and push local commits and the
115 history leading up to them to new or existing remote refs.
@@ -136,6 +144,14 @@ Capabilities for Fetching
144 +
145 Supported commands: 'connect'.
146
147 +'stateless-connect'::
148 + Experimental; for internal use only.
149 + Can attempt to connect to a remote server for communication
150 + using git's wire-protocol version 2. See the documentation
151 + for the stateless-connect command for more information.
152 ++
153 +Supported commands: 'stateless-connect'.
154 +
155 'fetch'::
156 Can discover remote refs and transfer objects reachable from
157 them to the local object store.
@@ -375,6 +391,22 @@ Supported if the helper has the "export" capability.
391 +
392 Supported if the helper has the "connect" capability.
393
394 +'stateless-connect' <service>::
395 + Experimental; for internal use only.
396 + Connects to the given remote service for communication using
397 + git's wire-protocol version 2. Valid replies to this command
398 + are empty line (connection established), 'fallback' (no smart
399 + transport support, fall back to dumb transports) and just
400 + exiting with error message printed (can't connect, don't bother
401 + trying to fall back). After line feed terminating the positive
402 + (empty) response, the output of the service starts. Messages
403 + (both request and response) must consist of zero or more
404 + PKT-LINEs, terminating in a flush packet. The client must not
405 + expect the server to store any state in between request-response
406 + pairs. After the connection ends, the remote helper exits.
407 ++
408 +Supported if the helper has the "stateless-connect" capability.
409 +
410 If a fatal error occurs, the program writes the error message to
411 stderr and exits. The caller should expect that a suitable error
412 message has been printed if the child closes the connection without
transport-helper.c
+11
@@ -12,6 +12,7 @@
12 #include "argv-array.h"
13 #include "refs.h"
14 #include "transport-internal.h"
15 +#include "protocol.h"
16
17 static int debug;
18
@@ -26,6 +27,7 @@ struct helper_data {
27 option : 1,
28 push : 1,
29 connect : 1,
30 + stateless_connect : 1,
31 signed_tags : 1,
32 check_connectivity : 1,
33 no_disconnect_req : 1,
@@ -188,6 +190,8 @@ static struct child_process *get_helper(struct transport *transport)
190 refspecs[refspec_nr++] = xstrdup(arg);
191 } else if (!strcmp(capname, "connect")) {
192 data->connect = 1;
193 + } else if (!strcmp(capname, "stateless-connect")) {
194 + data->stateless_connect = 1;
195 } else if (!strcmp(capname, "signed-tags")) {
196 data->signed_tags = 1;
197 } else if (skip_prefix(capname, "export-marks ", &arg)) {
@@ -612,6 +616,13 @@ static int process_connect_service(struct transport *transport,
616 if (data->connect) {
617 strbuf_addf(&cmdbuf, "connect %s\n", name);
618 ret = run_connect(transport, &cmdbuf);
619 + } else if (data->stateless_connect &&
620 + (get_protocol_version_config() == protocol_v2) &&
621 + !strcmp("git-upload-pack", name)) {
622 + strbuf_addf(&cmdbuf, "stateless-connect %s\n", name);
623 + ret = run_connect(transport, &cmdbuf);
624 + if (ret)
625 + transport->stateless_rpc = 1;
626 }
627
628 strbuf_release(&cmdbuf);
transport.c
+1
@@ -252,6 +252,7 @@ static int fetch_refs_via_pack(struct transport *transport,
252 data->options.check_self_contained_and_connected;
253 args.cloning = transport->cloning;
254 args.update_shallow = data->options.update_shallow;
255 + args.stateless_rpc = transport->stateless_rpc;
256
257 if (!data->got_remote_heads)
258 refs_tmp = get_refs_via_connect(transport, 0, NULL);
transport.h
+6
@@ -55,6 +55,12 @@ struct transport {
55 */
56 unsigned cloning : 1;
57
58 + /*
59 + * Indicates that the transport is connected via a half-duplex
60 + * connection and should operate in stateless-rpc mode.
61 + */
62 + unsigned stateless_rpc : 1;
63 +
64 /*
65 * These strings will be passed to the {pre, post}-receive hook,
66 * on the remote side, if both sides support the push options capability.