Skip to content

Commit edc9caf

Browse files
bmwillgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 176e85c commit edc9caf

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

Documentation/gitremote-helpers.txt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ Capabilities for Pushing
102102
+
103103
Supported commands: 'connect'.
104104

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+
105113
'push'::
106114
Can discover remote refs and push local commits and the
107115
history leading up to them to new or existing remote refs.
@@ -136,6 +144,14 @@ Capabilities for Fetching
136144
+
137145
Supported commands: 'connect'.
138146

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+
139155
'fetch'::
140156
Can discover remote refs and transfer objects reachable from
141157
them to the local object store.
@@ -375,6 +391,22 @@ Supported if the helper has the "export" capability.
375391
+
376392
Supported if the helper has the "connect" capability.
377393

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+
378410
If a fatal error occurs, the program writes the error message to
379411
stderr and exits. The caller should expect that a suitable error
380412
message has been printed if the child closes the connection without

transport-helper.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "argv-array.h"
1313
#include "refs.h"
1414
#include "transport-internal.h"
15+
#include "protocol.h"
1516

1617
static int debug;
1718

@@ -26,6 +27,7 @@ struct helper_data {
2627
option : 1,
2728
push : 1,
2829
connect : 1,
30+
stateless_connect : 1,
2931
signed_tags : 1,
3032
check_connectivity : 1,
3133
no_disconnect_req : 1,
@@ -188,6 +190,8 @@ static struct child_process *get_helper(struct transport *transport)
188190
refspecs[refspec_nr++] = xstrdup(arg);
189191
} else if (!strcmp(capname, "connect")) {
190192
data->connect = 1;
193+
} else if (!strcmp(capname, "stateless-connect")) {
194+
data->stateless_connect = 1;
191195
} else if (!strcmp(capname, "signed-tags")) {
192196
data->signed_tags = 1;
193197
} else if (skip_prefix(capname, "export-marks ", &arg)) {
@@ -612,6 +616,13 @@ static int process_connect_service(struct transport *transport,
612616
if (data->connect) {
613617
strbuf_addf(&cmdbuf, "connect %s\n", name);
614618
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;
615626
}
616627

617628
strbuf_release(&cmdbuf);

transport.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ static int fetch_refs_via_pack(struct transport *transport,
252252
data->options.check_self_contained_and_connected;
253253
args.cloning = transport->cloning;
254254
args.update_shallow = data->options.update_shallow;
255+
args.stateless_rpc = transport->stateless_rpc;
255256

256257
if (!data->got_remote_heads)
257258
refs_tmp = get_refs_via_connect(transport, 0, NULL);

transport.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ struct transport {
5555
*/
5656
unsigned cloning : 1;
5757

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+
5864
/*
5965
* These strings will be passed to the {pre, post}-receive hook,
6066
* on the remote side, if both sides support the push options capability.

0 commit comments

Comments
 (0)