fetch-pack: advertise session ID in capabilities
When the server sent a session-id capability and transfer.advertiseSID is true, advertise fetch-pack's own session ID back to the server. 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
1e905bbc008dfc3c0ffe14b55bd920e188e51b4e
1 file changed
+9
fetch-pack.c
+9
@@ -35,6 +35,7 @@ static int fetch_fsck_objects = -1;
35
static int transfer_fsck_objects = -1;
36
static int agent_supported;
37
static int server_supports_filtering;
38
+static int advertise_sid;
39
static struct shallow_lock shallow_lock;
40
static const char *alternate_shallow_file;
41
static struct strbuf fsck_msg_types = STRBUF_INIT;
@@ -326,6 +327,8 @@ static int find_common(struct fetch_negotiator *negotiator,
327
if (deepen_not_ok) strbuf_addstr(&c, " deepen-not");
328
if (agent_supported) strbuf_addf(&c, " agent=%s",
329
git_user_agent_sanitized());
330
+ if (advertise_sid)
331
+ strbuf_addf(&c, " session-id=%s", trace2_session_id());
332
if (args->filter_options.choice)
333
strbuf_addstr(&c, " filter");
334
packet_buf_write(&req_buf, "want %s%s\n", remote_hex, c.buf);
@@ -979,6 +982,9 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
982
agent_len, agent_feature);
983
}
984
985
+ if (!server_supports("session-id"))
986
+ advertise_sid = 0;
987
+
988
if (server_supports("shallow"))
989
print_verbose(args, _("Server supports %s"), "shallow");
990
else if (args->depth > 0 || is_repository_shallow(r))
@@ -1191,6 +1197,8 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
1197
packet_buf_write(&req_buf, "command=fetch");
1198
if (server_supports_v2("agent", 0))
1199
packet_buf_write(&req_buf, "agent=%s", git_user_agent_sanitized());
1200
+ if (advertise_sid && server_supports_v2("session-id", 0))
1201
+ packet_buf_write(&req_buf, "session-id=%s", trace2_session_id());
1202
if (args->server_options && args->server_options->nr &&
1203
server_supports_v2("server-option", 1)) {
1204
int i;
@@ -1711,6 +1719,7 @@ static void fetch_pack_config(void)
1719
git_config_get_bool("repack.usedeltabaseoffset", &prefer_ofs_delta);
1720
git_config_get_bool("fetch.fsckobjects", &fetch_fsck_objects);
1721
git_config_get_bool("transfer.fsckobjects", &transfer_fsck_objects);
1722
+ git_config_get_bool("transfer.advertisesid", &advertise_sid);
1723
if (!uri_protocols.nr) {
1724
char *str;
1725