@matheusbsbs / matheus-bagliano / commits / 6b5b6e422e
Fork 0

serve: advertise session ID in v2 capabilities

When transfer.advertiseSID is true, advertise the server's session ID for all protocol v2 connections via the new session-id capability. Signed-off-by: Josh Steadmon <steadmon@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Josh Steadmon committed Nov 11, 2020 at 15:29 UTC 6b5b6e422ee3d84feccc1b09c18188fedaaed761
1 file changed +14
serve.c
+14
@@ -8,6 +8,8 @@
8 #include "serve.h"
9 #include "upload-pack.h"
10
11 +static int advertise_sid;
12 +
13 static int always_advertise(struct repository *r,
14 struct strbuf *value)
15 {
@@ -30,6 +32,15 @@ static int object_format_advertise(struct repository *r,
32 return 1;
33 }
34
35 +static int session_id_advertise(struct repository *r, struct strbuf *value)
36 +{
37 + if (!advertise_sid)
38 + return 0;
39 + if (value)
40 + strbuf_addstr(value, trace2_session_id());
41 + return 1;
42 +}
43 +
44 struct protocol_capability {
45 /*
46 * The name of the capability. The server uses this name when
@@ -66,6 +77,7 @@ static struct protocol_capability capabilities[] = {
77 { "fetch", upload_pack_advertise, upload_pack_v2 },
78 { "server-option", always_advertise, NULL },
79 { "object-format", object_format_advertise, NULL },
80 + { "session-id", session_id_advertise, NULL },
81 };
82
83 static void advertise_capabilities(void)
@@ -261,6 +273,8 @@ static int process_request(void)
273 /* Main serve loop for protocol version 2 */
274 void serve(struct serve_options *options)
275 {
276 + git_config_get_bool("transfer.advertisesid", &advertise_sid);
277 +
278 if (options->advertise_capabilities || !options->stateless_rpc) {
279 /* serve by default supports v2 */
280 packet_write_fmt(1, "version 2\n");