From: Christian Couder <christian.couder@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
Patrick Steinhardt <ps@pks.im>, Matt Cote <mcote@nvidia.com>,
Christian Couder <christian.couder@gmail.com>
Subject: [PATCH v2 4/8] connect: buffer the ls-refs and bundle-uri requests
Date: Fri, 20 Nov 2026 17:48:17 +0100 [thread overview]
Message-ID: <20261120164812.707946-14-christian.couder@gmail.com> (raw)
In-Reply-To: <20261120164812.707946-10-christian.couder@gmail.com>
The `fetch` and `object-info` requests are built into a `struct strbuf`
using write_command_and_capabilities() and packet_buf_*() functions,
and then sent with a single write_in_full() call. On the other hand,
the `ls-refs` and `bundle-uri` requests are written directly to the
file descriptor, packet by packet, using packet_write_fmt(),
packet_delim() and packet_flush().
To prepare for using write_command_and_capabilities() in
get_remote_refs() and get_remote_bundle_uri() in following commits,
let's build the `ls-refs` and `bundle-uri` requests into a
`struct strbuf` too, and send each of them with a single
write_in_full().
As send_capabilities() is used for both of these requests, let's make
it write into a `struct strbuf` instead of a file descriptor too.
As packet_buf_write() and packet_write_fmt() format packets in the
same way, the bytes sent on the wire are unchanged. If writing the
request fails though, we now die with "unable to write request to
remote", like for the `fetch` and `object-info` requests, instead of
with "packet write with format failed", or silently from SIGPIPE on
EPIPE.
Signed-off-by: Christian Couder <christian.couder@gmail.com>
---
connect.c | 47 +++++++++++++++++++++++++++++------------------
1 file changed, 29 insertions(+), 18 deletions(-)
diff --git a/connect.c b/connect.c
index 71d9e98a4b..1d923978ba 100644
--- a/connect.c
+++ b/connect.c
@@ -501,7 +501,8 @@ void check_stateless_delimiter(int stateless_rpc,
die("%s", error);
}
-static void send_capabilities(int fd_out, struct packet_reader *reader)
+static void send_capabilities(struct strbuf *req_buf,
+ struct packet_reader *reader)
{
const char *hash_name;
const char *promisor_remote_info;
@@ -510,17 +511,17 @@ static void send_capabilities(int fd_out, struct packet_reader *reader)
repo_config_get_bool(the_repository, "transfer.advertisesid", &advertise_sid);
if (server_supports_v2("agent"))
- packet_write_fmt(fd_out, "agent=%s", git_user_agent_sanitized());
+ packet_buf_write(req_buf, "agent=%s", git_user_agent_sanitized());
if (advertise_sid && server_supports_v2("session-id"))
- packet_write_fmt(fd_out, "session-id=%s", trace2_session_id());
+ packet_buf_write(req_buf, "session-id=%s", trace2_session_id());
if (server_feature_v2("object-format", &hash_name)) {
int hash_algo = hash_algo_by_name(hash_name);
if (hash_algo == GIT_HASH_UNKNOWN)
die(_("unknown object format '%s' specified by server"), hash_name);
reader->hash_algo = &hash_algos[hash_algo];
- packet_write_fmt(fd_out, "object-format=%s", reader->hash_algo->name);
+ packet_buf_write(req_buf, "object-format=%s", reader->hash_algo->name);
} else {
reader->hash_algo = &hash_algos[GIT_HASH_SHA1_LEGACY];
}
@@ -528,7 +529,7 @@ static void send_capabilities(int fd_out, struct packet_reader *reader)
char *reply;
promisor_remote_reply(promisor_remote_info, &reply);
if (reply) {
- packet_write_fmt(fd_out, "promisor-remote=%s", reply);
+ packet_buf_write(req_buf, "promisor-remote=%s", reply);
free(reply);
}
}
@@ -537,19 +538,24 @@ static void send_capabilities(int fd_out, struct packet_reader *reader)
int get_remote_bundle_uri(int fd_out, struct packet_reader *reader,
struct bundle_list *bundles, int stateless_rpc)
{
+ struct strbuf req_buf = STRBUF_INIT;
int line_nr = 1, err = 0;
/* Assert bundle-uri support */
ensure_server_supports_v2("bundle-uri");
/* (Re-)send capabilities */
- send_capabilities(fd_out, reader);
+ send_capabilities(&req_buf, reader);
/* Send command */
- packet_write_fmt(fd_out, "command=bundle-uri\n");
- packet_delim(fd_out);
+ packet_buf_write(&req_buf, "command=bundle-uri\n");
+ packet_buf_delim(&req_buf);
- packet_flush(fd_out);
+ packet_buf_flush(&req_buf);
+
+ if (write_in_full(fd_out, req_buf.buf, req_buf.len) < 0)
+ die_errno(_("unable to write request to remote"));
+ strbuf_release(&req_buf);
/* Process response from server */
while (packet_reader_read(reader) == PACKET_READ_NORMAL) {
@@ -593,6 +599,7 @@ struct ref **get_remote_refs(int fd_out, struct packet_reader *reader,
int stateless_rpc)
{
size_t i;
+ struct strbuf req_buf = STRBUF_INIT;
struct strvec *ref_prefixes = transport_options ?
&transport_options->ref_prefixes : NULL;
const char **unborn_head_target = transport_options ?
@@ -600,30 +607,34 @@ struct ref **get_remote_refs(int fd_out, struct packet_reader *reader,
*list = NULL;
ensure_server_supports_v2("ls-refs");
- packet_write_fmt(fd_out, "command=ls-refs\n");
+ packet_buf_write(&req_buf, "command=ls-refs\n");
/* Send capabilities */
- send_capabilities(fd_out, reader);
+ send_capabilities(&req_buf, reader);
if (server_options && server_options->nr) {
ensure_server_supports_v2("server-option");
for (i = 0; i < server_options->nr; i++)
- packet_write_fmt(fd_out, "server-option=%s",
+ packet_buf_write(&req_buf, "server-option=%s",
server_options->items[i].string);
}
- packet_delim(fd_out);
+ packet_buf_delim(&req_buf);
/* When pushing we don't want to request the peeled tags */
if (!for_push)
- packet_write_fmt(fd_out, "peel\n");
- packet_write_fmt(fd_out, "symrefs\n");
+ packet_buf_write(&req_buf, "peel\n");
+ packet_buf_write(&req_buf, "symrefs\n");
if (server_supports_feature("ls-refs", "unborn", 0))
- packet_write_fmt(fd_out, "unborn\n");
+ packet_buf_write(&req_buf, "unborn\n");
for (i = 0; ref_prefixes && i < ref_prefixes->nr; i++) {
- packet_write_fmt(fd_out, "ref-prefix %s\n",
+ packet_buf_write(&req_buf, "ref-prefix %s\n",
ref_prefixes->v[i]);
}
- packet_flush(fd_out);
+ packet_buf_flush(&req_buf);
+
+ if (write_in_full(fd_out, req_buf.buf, req_buf.len) < 0)
+ die_errno(_("unable to write request to remote"));
+ strbuf_release(&req_buf);
/* Process response from server */
while (packet_reader_read(reader) == PACKET_READ_NORMAL) {
--
2.56.0
next prev parent reply other threads:[~2026-11-20 16:48 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-12 19:58 [PATCH 0/3] Fix promisor-remote reply missing from fetch Christian Couder
2026-11-12 19:59 ` [PATCH 1/3] connect: let write_command_and_capabilities() send a promisor-remote reply Christian Couder
2026-11-12 22:18 ` Junio C Hamano
2026-11-12 22:34 ` Junio C Hamano
2026-11-13 13:10 ` Christian Couder
2026-11-13 19:11 ` Junio C Hamano
2026-11-20 16:57 ` Christian Couder
2026-11-12 19:59 ` [PATCH 2/3] fetch-pack: ensure fetch sends " Christian Couder
2026-11-12 19:59 ` [PATCH 3/3] doc: gitprotocol-v2: send the promisor-remote reply with fetch Christian Couder
2026-11-20 16:48 ` [PATCH v2 0/8] Fix promisor-remote reply missing from fetch Christian Couder
2026-11-20 16:48 ` [PATCH v2 1/8] connect: pass capability lines to write_command_and_capabilities() Christian Couder
2026-11-20 16:48 ` [PATCH v2 2/8] connect: send session-id with ls-refs and bundle-uri Christian Couder
2026-11-20 16:48 ` [PATCH v2 3/8] connect: pass a reader to write_command_and_capabilities() Christian Couder
2026-11-20 16:48 ` Christian Couder [this message]
2026-11-20 16:48 ` [PATCH v2 5/8] connect: use write_command_and_capabilities() in get_remote_refs() Christian Couder
2026-11-20 16:48 ` [PATCH v2 6/8] connect: use write_command_and_capabilities() in get_remote_bundle_uri() Christian Couder
2026-11-20 16:48 ` [PATCH v2 7/8] fetch-pack: ensure fetch sends a promisor-remote reply Christian Couder
2026-11-20 16:48 ` [PATCH v2 8/8] doc: gitprotocol-v2: send the promisor-remote reply with fetch Christian Couder
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261120164812.707946-14-christian.couder@gmail.com \
--to=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=mcote@nvidia.com \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox