From 86f4e31298e4440a08da277966a52adeb982a1fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Mon, 16 May 2022 20:10:58 +0000 Subject: [PATCH] connect.c: refactor sending of agent & object-format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactor the sending of the "agent" and "object-format" capabilities into a function. This was added in its current form in ab67235bc4 (connect: parse v2 refs with correct hash algorithm, 2020-05-25). When we connect to a v2 server we need to know about its object-format, and it needs to know about ours. Since most things in connect.c and transport.c piggy-back on the eager getting of remote refs via the handshake() those commands can make use of the just-sent-over object-format by ls-refs. But I'm about to add a command that may come after ls-refs, and may not, but we need the server to know about our user-agent and object-format. So let's split this into a function. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Derrick Stolee Signed-off-by: Junio C Hamano --- connect.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/connect.c b/connect.c index afc79a6236..e6d0b1d34b 100644 --- a/connect.c +++ b/connect.c @@ -473,22 +473,9 @@ void check_stateless_delimiter(int stateless_rpc, die("%s", error); } -struct ref **get_remote_refs(int fd_out, struct packet_reader *reader, - struct ref **list, int for_push, - struct transport_ls_refs_options *transport_options, - const struct string_list *server_options, - int stateless_rpc) +static void send_capabilities(int fd_out, struct packet_reader *reader) { - int i; const char *hash_name; - struct strvec *ref_prefixes = transport_options ? - &transport_options->ref_prefixes : NULL; - const char **unborn_head_target = transport_options ? - &transport_options->unborn_head_target : NULL; - *list = NULL; - - if (server_supports_v2("ls-refs", 1)) - packet_write_fmt(fd_out, "command=ls-refs\n"); if (server_supports_v2("agent", 0)) packet_write_fmt(fd_out, "agent=%s", git_user_agent_sanitized()); @@ -502,6 +489,26 @@ struct ref **get_remote_refs(int fd_out, struct packet_reader *reader, } else { reader->hash_algo = &hash_algos[GIT_HASH_SHA1]; } +} + +struct ref **get_remote_refs(int fd_out, struct packet_reader *reader, + struct ref **list, int for_push, + struct transport_ls_refs_options *transport_options, + const struct string_list *server_options, + int stateless_rpc) +{ + int i; + struct strvec *ref_prefixes = transport_options ? + &transport_options->ref_prefixes : NULL; + const char **unborn_head_target = transport_options ? + &transport_options->unborn_head_target : NULL; + *list = NULL; + + if (server_supports_v2("ls-refs", 1)) + packet_write_fmt(fd_out, "command=ls-refs\n"); + + /* Send capabilities */ + send_capabilities(fd_out, reader); if (server_options && server_options->nr && server_supports_v2("server-option", 1))