connect: make write_fetch_command_and_capabilities() more generic

Refactor write_fetch_command_and_capabilities(), enabling it to serve both fetch and additional commands. In this context, "command" refers to the "operations" supported by Git's wire protocol Documentation/gitprotocol-v2.adoc, such as a Git subcommand (e.g., git-fetch(1)) or a server-side operation like "object-info" as implemented in commit a2ba162cda (object-info: support for retrieving object info, 2021-04-20). Refactor the function signature to accept a command instead of the hardcoded "fetch". 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 eb1fbc64b705deaf600bbba777616209280f43a5
3 files changed +12 -8
connect.c
+4 -4
@@ -700,16 +700,16 @@ int server_supports(const char *feature)
700 return !!server_feature_value(feature, NULL);
701 }
702
703 -void write_fetch_command_and_capabilities(struct strbuf *req_buf,
704 - const struct string_list *server_options)
703 +void write_command_and_capabilities(struct strbuf *req_buf, const char *command,
704 + const struct string_list *server_options)
705 {
706 const char *hash_name;
707 int advertise_sid = 0;
708
709 repo_config_get_bool(the_repository, "transfer.advertisesid", &advertise_sid);
710
711 - ensure_server_supports_v2("fetch");
712 - packet_buf_write(req_buf, "command=fetch");
711 + ensure_server_supports_v2(command);
712 + packet_buf_write(req_buf, "command=%s", command);
713 if (server_supports_v2("agent"))
714 packet_buf_write(req_buf, "agent=%s", git_user_agent_sanitized());
715 if (advertise_sid && server_supports_v2("session-id"))
connect.h
+6 -2
@@ -35,7 +35,11 @@ void check_stateless_delimiter(int stateless_rpc,
35 const char *error);
36
37 struct string_list;
38 -void write_fetch_command_and_capabilities(struct strbuf *req_buf,
39 - const struct string_list *server_options);
38 +/*
39 + * Write a protocol v2 command request, along with the capability
40 + * advertisements, into req_buf.
41 + */
42 +void write_command_and_capabilities(struct strbuf *req_buf, const char *command,
43 + const struct string_list *server_options);
44
45 #endif
fetch-pack.c
+2 -2
@@ -1386,7 +1386,7 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
1386 int done_sent = 0;
1387 struct strbuf req_buf = STRBUF_INIT;
1388
1389 - write_fetch_command_and_capabilities(&req_buf, args->server_options);
1389 + write_command_and_capabilities(&req_buf, "fetch", args->server_options);
1390
1391 if (args->use_thin_pack)
1392 packet_buf_write(&req_buf, "thin-pack");
@@ -2253,7 +2253,7 @@ void negotiate_using_fetch(const struct oid_array *negotiation_restrict_tips,
2253 the_repository, "%d",
2254 negotiation_round);
2255 strbuf_reset(&req_buf);
2256 - write_fetch_command_and_capabilities(&req_buf, server_options);
2256 + write_command_and_capabilities(&req_buf, "fetch", server_options);
2257
2258 packet_buf_write(&req_buf, "wait-for-done");
2259