git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 5/8] connect: use write_command_and_capabilities() in get_remote_refs()

From
Christian Couder <christian.couder@gmail.com>
Date
Nov 20, 2026, 16:48 UTC
Message-ID
<20261120164812.707946-15-christian.couder@gmail.com>
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
Previous: Christian CouderNext: Christian Couder
Message 15 of 18 in “Fix promisor-remote reply missing from fetch”
  1. 0/3 Fix promisor-remote reply missing from fetchChristian Couder, Nov 12, 2026
  2. 1/3 connect: let write_command_and_capabilities() send a promisor-remote replyChristian Couder, Nov 12, 2026
  3. Junio C HamanoNov 12, 2026
  4. Junio C HamanoNov 12, 2026
  5. Christian CouderNov 13, 2026
  6. Junio C HamanoNov 13, 2026
  7. Christian CouderNov 20, 2026
  8. 2/3 fetch-pack: ensure fetch sends a promisor-remote replyChristian Couder, Nov 12, 2026
  9. 3/3 doc: gitprotocol-v2: send the promisor-remote reply with fetchChristian Couder, Nov 12, 2026
  10. 0/8 Fix promisor-remote reply missing from fetchChristian Couder, Nov 20, 2026
  11. 1/8 connect: pass capability lines to write_command_and_capabilities()Christian Couder, Nov 20, 2026
  12. 2/8 connect: send session-id with ls-refs and bundle-uriChristian Couder, Nov 20, 2026
  13. 3/8 connect: pass a reader to write_command_and_capabilities()Christian Couder, Nov 20, 2026
  14. 4/8 connect: buffer the ls-refs and bundle-uri requestsChristian Couder, Nov 20, 2026
  15. 5/8 connect: use write_command_and_capabilities() in get_remote_refs()Christian Couder, Nov 20, 2026
  16. 6/8 connect: use write_command_and_capabilities() in get_remote_bundle_uri()Christian Couder, Nov 20, 2026
  17. 7/8 fetch-pack: ensure fetch sends a promisor-remote replyChristian Couder, Nov 20, 2026
  18. 8/8 doc: gitprotocol-v2: send the promisor-remote reply with fetchChristian Couder, Nov 20, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.