fetch-pack: drop the static advertise_sid variable

write_fetch_command_and_capabilities() is moved to 'connect.c' in a subsequent commit. To prepare for that, drop the static variable usage of advertise_sid. Currently advertise_sid is set in fetch_pack_config() by reading "transfer.advertisesid". It is used in three places: 1. In do_fetch_pack(), to clear it when the server lacks support: if (!server_supports("session-id")) advertise_sid = 0; 2. In find_common(), to advertise the session id over protocol v0/v1: if (advertise_sid) strbuf_addf(&c, " session-id=%s", trace2_session_id()); 3. In write_fetch_command_and_capabilities(), to advertise it over protocol v2: if (advertise_sid && server_supports_v2("session-id")) packet_buf_write(req_buf, "session-id=%s", trace2_session_id()); About 1, the check only guards the v0/v1 path, and the v2 path already checks server support inline in its condition. Follow the same pattern and fold the check into the condition in find_common(). About 2 and 3, replace the static variable with a local read via repo_config_get_bool() in each function. Because repo_config_get_bool() leaves advertise_sid as is if it is not set, initialize it to 0, matching its default. Helped-by: Jonathan Tan <jonathantanmy@google.com> Helped-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Calvin Wan <calvinwan@google.com> Signed-off-by: Eric Ju <eric.peijian@gmail.com> Signed-off-by: Pablo Sabater <pabloosabaterr@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Pablo Sabater committed Jul 24, 2026 at 12:54 UTC b54d5e19f068a73bdbde5a9434fe72902764b958
1 file changed +7 -6
fetch-pack.c
+7 -6
@@ -49,7 +49,6 @@ static int fetch_fsck_objects = -1;
49 static int transfer_fsck_objects = -1;
50 static int agent_supported;
51 static int server_supports_filtering;
52 -static int advertise_sid;
52 static struct shallow_lock shallow_lock;
53 static const char *alternate_shallow_file;
54 static struct strbuf fsck_msg_types = STRBUF_INIT;
@@ -363,6 +362,9 @@ static int find_common(struct fetch_negotiator *negotiator,
362 size_t state_len = 0;
363 struct packet_reader reader;
364 struct oidset negotiation_include_oids = OIDSET_INIT;
365 + int advertise_sid = 0;
366 +
367 + repo_config_get_bool(the_repository, "transfer.advertisesid", &advertise_sid);
368
369 if (args->stateless_rpc && multi_ack == 1)
370 die(_("the option '%s' requires '%s'"), "--stateless-rpc", "multi_ack_detailed");
@@ -414,7 +416,7 @@ static int find_common(struct fetch_negotiator *negotiator,
416 if (deepen_not_ok) strbuf_addstr(&c, " deepen-not");
417 if (agent_supported) strbuf_addf(&c, " agent=%s",
418 git_user_agent_sanitized());
417 - if (advertise_sid)
419 + if (advertise_sid && server_supports("session-id"))
420 strbuf_addf(&c, " session-id=%s", trace2_session_id());
421 if (args->filter_options.choice)
422 strbuf_addstr(&c, " filter");
@@ -1160,9 +1162,6 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
1162 (int)agent_len, agent_feature);
1163 }
1164
1163 - if (!server_supports("session-id"))
1164 - advertise_sid = 0;
1165 -
1165 if (server_supports("shallow"))
1166 print_verbose(args, _("Server supports %s"), "shallow");
1167 else if (args->depth > 0 || is_repository_shallow(r))
@@ -1380,6 +1379,9 @@ static void write_fetch_command_and_capabilities(struct strbuf *req_buf,
1379 const struct string_list *server_options)
1380 {
1381 const char *hash_name;
1382 + int advertise_sid = 0;
1383 +
1384 + repo_config_get_bool(the_repository, "transfer.advertisesid", &advertise_sid);
1385
1386 ensure_server_supports_v2("fetch");
1387 packet_buf_write(req_buf, "command=fetch");
@@ -1998,7 +2000,6 @@ static void fetch_pack_config(void)
2000 repo_config_get_bool(the_repository, "repack.usedeltabaseoffset", &prefer_ofs_delta);
2001 repo_config_get_bool(the_repository, "fetch.fsckobjects", &fetch_fsck_objects);
2002 repo_config_get_bool(the_repository, "transfer.fsckobjects", &transfer_fsck_objects);
2001 - repo_config_get_bool(the_repository, "transfer.advertisesid", &advertise_sid);
2003 if (!uri_protocols.nr) {
2004 char *str;
2005