Skip to content

Commit 6b5b6e4

Browse files
steadmongitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8073d75 commit 6b5b6e4

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

serve.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include "serve.h"
99
#include "upload-pack.h"
1010

11+
static int advertise_sid;
12+
1113
static int always_advertise(struct repository *r,
1214
struct strbuf *value)
1315
{
@@ -30,6 +32,15 @@ static int object_format_advertise(struct repository *r,
3032
return 1;
3133
}
3234

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+
3344
struct protocol_capability {
3445
/*
3546
* The name of the capability. The server uses this name when
@@ -66,6 +77,7 @@ static struct protocol_capability capabilities[] = {
6677
{ "fetch", upload_pack_advertise, upload_pack_v2 },
6778
{ "server-option", always_advertise, NULL },
6879
{ "object-format", object_format_advertise, NULL },
80+
{ "session-id", session_id_advertise, NULL },
6981
};
7082

7183
static void advertise_capabilities(void)
@@ -261,6 +273,8 @@ static int process_request(void)
261273
/* Main serve loop for protocol version 2 */
262274
void serve(struct serve_options *options)
263275
{
276+
git_config_get_bool("transfer.advertisesid", &advertise_sid);
277+
264278
if (options->advertise_capabilities || !options->stateless_rpc) {
265279
/* serve by default supports v2 */
266280
packet_write_fmt(1, "version 2\n");

0 commit comments

Comments
 (0)