Git development
 help / color / mirror / Atom feed
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 5/8] connect: use write_command_and_capabilities() in get_remote_refs()
Date: Fri, 20 Nov 2026 17:48:18 +0100	[thread overview]
Message-ID: <20261120164812.707946-15-christian.couder@gmail.com> (raw)
In-Reply-To: <20261120164812.707946-10-christian.couder@gmail.com>

As previous commits made write_command_and_capabilities() more generic,
we can now use that function in get_remote_refs() instead of
send_capabilities() and the open-coded "server-option" loop. Let's do
that then, which prepares for removing send_capabilities() in a
following commit.

Let's also refactor writing the "promisor-remote" reply into a new
add_promisor_remote_reply() helper function. This duplicates code which
is in send_capabilities() but we are going to remove that function in a
following commit. Let's declare this new helper in "connect.h" as it
will also be used in "fetch-pack.c" in a following commit.

Note that the order of the `ls-refs` request lines changes. After

  "command, agent, [session-id]"

it used to be:

  "object-format, promisor-remote, server-option*"

but now it is:

  "server-option*, promisor-remote, object-format".

This should not affect the server's behavior as "serve.c" and JGit both
accept capabilities in any order after "command=...".

Also note that "command=ls-refs" no longer ends with "\n", which is
harmless because the server chomps newlines.

Signed-off-by: Christian Couder <christian.couder@gmail.com>
---
 connect.c | 34 +++++++++++++++++++++-------------
 connect.h |  8 ++++++++
 2 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/connect.c b/connect.c
index 1d923978ba..9d5585f72b 100644
--- a/connect.c
+++ b/connect.c
@@ -501,6 +501,21 @@ void check_stateless_delimiter(int stateless_rpc,
 		die("%s", error);
 }
 
+void add_promisor_remote_reply(struct strvec *capabilities)
+{
+	const char *promisor_remote_info;
+	char *reply;
+
+	if (!server_feature_v2("promisor-remote", &promisor_remote_info))
+		return;
+
+	promisor_remote_reply(promisor_remote_info, &reply);
+	if (reply) {
+		strvec_pushf(capabilities, "promisor-remote=%s", reply);
+		free(reply);
+	}
+}
+
 static void send_capabilities(struct strbuf *req_buf,
 			      struct packet_reader *reader)
 {
@@ -600,26 +615,18 @@ struct ref **get_remote_refs(int fd_out, struct packet_reader *reader,
 {
 	size_t i;
 	struct strbuf req_buf = STRBUF_INIT;
+	struct strvec capabilities = STRVEC_INIT;
 	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;
 
-	ensure_server_supports_v2("ls-refs");
-	packet_buf_write(&req_buf, "command=ls-refs\n");
-
-	/* Send capabilities */
-	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_buf_write(&req_buf, "server-option=%s",
-					 server_options->items[i].string);
-	}
+	add_server_options(&capabilities, server_options);
+	add_promisor_remote_reply(&capabilities);
+	write_command_and_capabilities(&req_buf, "ls-refs",
+				       &capabilities, reader);
 
-	packet_buf_delim(&req_buf);
 	/* When pushing we don't want to request the peeled tags */
 	if (!for_push)
 		packet_buf_write(&req_buf, "peel\n");
@@ -634,6 +641,7 @@ struct ref **get_remote_refs(int fd_out, struct packet_reader *reader,
 
 	if (write_in_full(fd_out, req_buf.buf, req_buf.len) < 0)
 		die_errno(_("unable to write request to remote"));
+	strvec_clear(&capabilities);
 	strbuf_release(&req_buf);
 
 	/* Process response from server */
diff --git a/connect.h b/connect.h
index cff987ae38..00afc8c95a 100644
--- a/connect.h
+++ b/connect.h
@@ -44,6 +44,14 @@ struct strvec;
 void add_server_options(struct strvec *capabilities,
 			const struct string_list *server_options);
 
+/*
+ * If the server advertised the "promisor-remote" capability, compute
+ * our reply, which also marks the accepted promisor remotes, and
+ * append "promisor-remote=<reply>" to `capabilities` if any remote
+ * was accepted.
+ */
+void add_promisor_remote_reply(struct strvec *capabilities);
+
 /*
  * Write a protocol v2 command request, along with the capability
  * advertisements, into req_buf. The "agent", "session-id" and
-- 
2.56.0


  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   ` [PATCH v2 4/8] connect: buffer the ls-refs and bundle-uri requests Christian Couder
2026-11-20 16:48   ` Christian Couder [this message]
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-15-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