{"thread":{"id":"66840","subject":"[PATCH 0/3] Fix promisor-remote reply missing from fetch","startedAt":"2026-11-12T19:58:59Z","lastAt":"2026-11-20T16:57:43Z","messageCount":18,"participants":["Christian Couder","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"558339","messageId":"20261112195858.53788-5-christian.couder@gmail.com","threadId":"66840","inReplyTo":null,"subject":"[PATCH 0/3] Fix promisor-remote reply missing from fetch","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2026-11-12T19:58:59Z","receivedAt":"2026-11-12T19:58:59Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"This small series fixes a brown paper bag bug in the \"promisor-remote\"\nprotocol v2 capability found by Matt Cote during the NVIDIA hackathon\nfollowing the Gerrit User Summit 2026.\n\nThe client doesn't send a \"promisor-remote=...\" reply with the `fetch`\nprotocol commands. It does send such a reply with the `ls-refs` and\n`bundle-uri` protocol commands. So this works by luck with a Git\nserver over file:// or ssh://, as the same `upload-pack` process\nhandles all the requests and remembers the reply from `ls-refs`.\n\nBut it doesn't work with servers that handle each request on its own,\nlike Git over HTTP or JGit (so Gerrit). It also doesn't work when only\nobject IDs are fetched, as no `ls-refs` is sent then.\n\nIn these cases, the server doesn't know that the client accepted a\npromisor remote, so it doesn't allow the objects available on the\naccepted promisor remotes to be missing from the pack, and fails with\n\"could not fetch <oid> from promisor remote\".\n\nThis has been the case since the capability was introduced in v2.49,\nso it would be nice to have the fix in maint too.\n\nOther related issues were found during the hackathon, but this one is\nthe most annoying. The others will be addressed in separate series.\n\nOverview of the patches\n=======================\n\n  - Patch 1/3 lets write_command_and_capabilities() send a\n    promisor-remote reply, without any change in behavior.\n\n  - Patch 2/3 is the actual fix, with new tests in t5710, and in a new\n    t5711 test script for HTTP.\n\n  - Patch 3/3 documents that the client should send the reply with\n    `fetch`.\n\nCI tests\n========\n\nSome failed, others didn't even started, see:\n\nhttps://github.com/chriscool/git/actions/runs/43285535901\n\nBut the failures all seem related to the test infrastructure.\n\nChristian Couder (3):\n  connect: let write_command_and_capabilities() send a promisor-remote\n    reply\n  fetch-pack: ensure fetch sends a promisor-remote reply\n  doc: gitprotocol-v2: send the promisor-remote reply with fetch\n\n Documentation/gitprotocol-v2.adoc          |   6 +\n connect.c                                  |   6 +-\n connect.h                                  |   6 +-\n fetch-object-info.c                        |   3 +-\n fetch-pack.c                               |  17 ++-\n t/meson.build                              |   1 +\n t/t5710-promisor-remote-capability.sh      |  40 +++++++\n t/t5711-promisor-remote-capability-http.sh | 126 +++++++++++++++++++++\n 8 files changed, 196 insertions(+), 9 deletions(-)\n create mode 100755 t/t5711-promisor-remote-capability-http.sh\n\n\nbase-commit: 1891de46f79dc444a47db1c87bd0c8c76b5463f2\n-- \n2.56.0\n\n\n"},{"id":"558340","messageId":"20261112195858.53788-6-christian.couder@gmail.com","threadId":"66840","inReplyTo":"20261112195858.53788-5-christian.couder@gmail.com","subject":"[PATCH 1/3] connect: let write_command_and_capabilities() send a promisor-remote reply","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2026-11-12T19:59:00Z","receivedAt":"2026-11-12T19:59:00Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"In protocol v2, the `promisor-remote=...` reply is only written by\nsend_capabilities(), which is used to send the `ls-refs` and\n`bundle-uri` protocol commands.\n\nThe request for the `fetch` protocol command is built by\nwrite_command_and_capabilities() called by send_fetch_request() in\n\"fetch-pack.c\" which cannot send that reply.\n\nIn a following commit, we will need send_fetch_request() to send that\nreply.\n\nLet's prepare for that by adding a new `promisor_remote_reply` argument\nto write_command_and_capabilities(). When it is not NULL, a\n`promisor-remote=...` capability with that value is written into the\nrequest.\n\nFor now, all the callers pass NULL, so there is no change in behavior.\n\nSigned-off-by: Christian Couder <christian.couder@gmail.com>\n---\n connect.c           | 6 +++++-\n connect.h           | 6 ++++--\n fetch-object-info.c | 3 ++-\n fetch-pack.c        | 6 ++++--\n 4 files changed, 15 insertions(+), 6 deletions(-)\n\ndiff --git a/connect.c b/connect.c\nindex 87d2e8bccd..32243948b4 100644\n--- a/connect.c\n+++ b/connect.c\n@@ -724,7 +724,8 @@ int server_supports(const char *feature)\n }\n \n void write_command_and_capabilities(struct strbuf *req_buf, const char *command,\n-\t\t\t\t    const struct string_list *server_options)\n+\t\t\t\t    const struct string_list *server_options,\n+\t\t\t\t    const char *promisor_remote_reply)\n {\n \tconst char *hash_name;\n \tint advertise_sid = 0;\n@@ -754,6 +755,9 @@ void write_command_and_capabilities(struct strbuf *req_buf, const char *command,\n \t\tdie(_(\"the server does not support algorithm '%s'\"),\n \t\t    the_hash_algo->name);\n \t}\n+\tif (promisor_remote_reply)\n+\t\tpacket_buf_write(req_buf, \"promisor-remote=%s\",\n+\t\t\t\t promisor_remote_reply);\n \tpacket_buf_delim(req_buf);\n }\n \ndiff --git a/connect.h b/connect.h\nindex 957e5fe2b9..8914d131c7 100644\n--- a/connect.h\n+++ b/connect.h\n@@ -37,9 +37,11 @@ void check_stateless_delimiter(int stateless_rpc,\n struct string_list;\n /*\n  * Write a protocol v2 command request, along with the capability\n- * advertisements, into req_buf.\n+ * advertisements, into req_buf. When `promisor_remote_reply` is not\n+ * NULL, a `promisor-remote` capability is sent with that value.\n  */\n void write_command_and_capabilities(struct strbuf *req_buf, const char *command,\n-\t\t\t\t    const struct string_list *server_options);\n+\t\t\t\t    const struct string_list *server_options,\n+\t\t\t\t    const char *promisor_remote_reply);\n \n #endif\ndiff --git a/fetch-object-info.c b/fetch-object-info.c\nindex 0a58308f9b..7fe6e4e864 100644\n--- a/fetch-object-info.c\n+++ b/fetch-object-info.c\n@@ -18,7 +18,8 @@ static void send_object_info_request(const int fd_out,\n {\n \tstruct strbuf req_buf = STRBUF_INIT;\n \n-\twrite_command_and_capabilities(&req_buf, \"object-info\", server_options);\n+\twrite_command_and_capabilities(&req_buf, \"object-info\",\n+\t\t\t\t       server_options, NULL);\n \n \tif (ask_size)\n \t\tpacket_buf_write(&req_buf, \"size\");\ndiff --git a/fetch-pack.c b/fetch-pack.c\nindex 55d311c0c3..50c97f561e 100644\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -1386,7 +1386,8 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,\n \tint done_sent = 0;\n \tstruct strbuf req_buf = STRBUF_INIT;\n \n-\twrite_command_and_capabilities(&req_buf, \"fetch\", args->server_options);\n+\twrite_command_and_capabilities(&req_buf, \"fetch\",\n+\t\t\t\t       args->server_options, NULL);\n \n \tif (args->use_thin_pack)\n \t\tpacket_buf_write(&req_buf, \"thin-pack\");\n@@ -2269,7 +2270,8 @@ void negotiate_using_fetch(const struct oid_array *negotiation_restrict_tips,\n \t\t\t\t\t   the_repository, \"%d\",\n \t\t\t\t\t   negotiation_round);\n \t\tstrbuf_reset(&req_buf);\n-\t\twrite_command_and_capabilities(&req_buf, \"fetch\", server_options);\n+\t\twrite_command_and_capabilities(&req_buf, \"fetch\",\n+\t\t\t\t\t       server_options, NULL);\n \n \t\tpacket_buf_write(&req_buf, \"wait-for-done\");\n \n-- \n2.56.0\n\n\n"},{"id":"558341","messageId":"20261112195858.53788-7-christian.couder@gmail.com","threadId":"66840","inReplyTo":"20261112195858.53788-5-christian.couder@gmail.com","subject":"[PATCH 2/3] fetch-pack: ensure fetch sends a promisor-remote reply","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2026-11-12T19:59:01Z","receivedAt":"2026-11-12T19:59:01Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"In protocol v2, when the client accepts promisor remotes, the\n`promisor-remote=...` reply is only written by send_capabilities(),\nwhich is used to send the `ls-refs` and `bundle-uri` protocol commands.\n\nThe request for the `fetch` protocol command is built by\nwrite_command_and_capabilities() called by send_fetch_request() in\n\"fetch-pack.c\" which doesn't send that reply. do_fetch_pack_v2() calls\npromisor_remote_reply(), but only to mark the accepted remotes, as\ne15a6b2f8b (promisor-remote: change promisor_remote_reply()'s\nsignature, 2026-02-16) assumed that fetch-pack would not need to send\na reply.\n\nWith file:// and ssh:// URLs on a Git server, one upload-pack process\nhandles both `ls-refs` and `fetch`. The acceptance recorded during\n`ls-refs` by promisor_remote_receive() in \"serve.c\" is still there at\n`fetch` time, so the clone succeeds. But it fails when each request is\nhandled on its own, for example with HTTP where different upload-pack\nprocesses are used, or with other server implementations like JGit.\n\nIt also fails when only object IDs are fetched, as no `ls-refs`\ncommand is then sent. In these cases, the server doesn't know that the\nclient accepted a promisor remote, so it doesn't allow promisor\nobjects to be missing from the pack it sends, and it fails with \"could\nnot fetch <oid> from promisor remote\".\n\nLet's fix that by always properly sending the `promisor-remote=...`\nreply when sending a `fetch` request from do_fetch_pack_v2().\n\nThe `fetch` requests sent by negotiate_using_fetch() don't ask for a\npack, so they don't need that reply.\n\nLet's also add tests in t5710 to check that the reply is sent with the\n`fetch` request, and that fetching only an object ID works. For HTTP,\nlet's add a new t5711 test script, copying the setup from t5710.\n\nReported-by: Matt Cote <mcote@nvidia.com>\nSigned-off-by: Christian Couder <christian.couder@gmail.com>\n---\n fetch-pack.c                               |  13 ++-\n t/meson.build                              |   1 +\n t/t5710-promisor-remote-capability.sh      |  40 +++++++\n t/t5711-promisor-remote-capability-http.sh | 126 +++++++++++++++++++++\n 4 files changed, 176 insertions(+), 4 deletions(-)\n create mode 100755 t/t5711-promisor-remote-capability-http.sh\n\ndiff --git a/fetch-pack.c b/fetch-pack.c\nindex 50c97f561e..2f1bb9d62c 100644\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -1380,14 +1380,16 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,\n \t\t\t      const struct ref *wants, struct oidset *common,\n \t\t\t      int *haves_to_send, int *in_vain,\n \t\t\t      int sideband_all, int seen_ack,\n-\t\t\t      struct oidset *negotiation_include_oids)\n+\t\t\t      struct oidset *negotiation_include_oids,\n+\t\t\t      const char *promisor_remote_reply)\n {\n \tint haves_added;\n \tint done_sent = 0;\n \tstruct strbuf req_buf = STRBUF_INIT;\n \n \twrite_command_and_capabilities(&req_buf, \"fetch\",\n-\t\t\t\t       args->server_options, NULL);\n+\t\t\t\t       args->server_options,\n+\t\t\t\t       promisor_remote_reply);\n \n \tif (args->use_thin_pack)\n \t\tpacket_buf_write(&req_buf, \"thin-pack\");\n@@ -1696,11 +1698,12 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,\n \tint i;\n \tstruct strvec index_pack_args = STRVEC_INIT;\n \tconst char *promisor_remote_config;\n+\tchar *accepted = NULL;\n \n \tfsck_options_init(&fsck_options, the_repository, FSCK_OPTIONS_MISSING_GITMODULES);\n \n \tif (server_feature_v2(\"promisor-remote\", &promisor_remote_config))\n-\t\tpromisor_remote_reply(promisor_remote_config, NULL);\n+\t\tpromisor_remote_reply(promisor_remote_config, &accepted);\n \n \tif (args->filter_options.choice == LOFC_AUTO) {\n \t\tstruct strbuf errbuf = STRBUF_INIT;\n@@ -1778,7 +1781,8 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,\n \t\t\t\t\t       &haves_to_send, &in_vain,\n \t\t\t\t\t       reader.use_sideband,\n \t\t\t\t\t       seen_ack,\n-\t\t\t\t\t       &negotiation_include_oids)) {\n+\t\t\t\t\t       &negotiation_include_oids,\n+\t\t\t\t\t       accepted)) {\n \t\t\t\ttrace2_region_leave_printf(\"negotiation_v2\", \"round\",\n \t\t\t\t\t\t\t   the_repository, \"%d\",\n \t\t\t\t\t\t\t   negotiation_round);\n@@ -1928,6 +1932,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,\n \tif (negotiator)\n \t\tnegotiator->release(negotiator);\n \n+\tfree(accepted);\n \tfsck_options_clear(&fsck_options);\n \toidset_clear(&common);\n \toidset_clear(&negotiation_include_oids);\ndiff --git a/t/meson.build b/t/meson.build\nindex 1cf1d95f70..84644703f1 100644\n--- a/t/meson.build\n+++ b/t/meson.build\n@@ -766,6 +766,7 @@ integration_tests = [\n   't5704-protocol-violations.sh',\n   't5705-session-id-in-capabilities.sh',\n   't5710-promisor-remote-capability.sh',\n+  't5711-promisor-remote-capability-http.sh',\n   't5730-protocol-v2-bundle-uri-file.sh',\n   't5731-protocol-v2-bundle-uri-git.sh',\n   't5732-protocol-v2-bundle-uri-http.sh',\ndiff --git a/t/t5710-promisor-remote-capability.sh b/t/t5710-promisor-remote-capability.sh\nindex 463e9e00b0..e5d6f9d1c6 100755\n--- a/t/t5710-promisor-remote-capability.sh\n+++ b/t/t5710-promisor-remote-capability.sh\n@@ -999,6 +999,46 @@ test_expect_success \"clone and fetch with --filter=auto\" '\n \tcheck_missing_objects server 1 \"$oid\"\n '\n \n+test_expect_success \"clone sends the promisor-remote reply with fetch\" '\n+\tgit -C server config promisor.advertise true &&\n+\ttest_when_finished \"rm -rf client trace\" &&\n+\n+\tGIT_TRACE_PACKET=\"$(pwd)/trace\" git clone \\\n+\t\t-c remote.lop.promisor=true \\\n+\t\t-c remote.lop.url=\"$TRASH_DIRECTORY_URL/lop\" \\\n+\t\t-c promisor.acceptfromserver=All \\\n+\t\t--no-local --filter=\"blob:limit=5k\" server client &&\n+\n+\t# Check that the reply is part of the fetch request\n+\tsed -n \"/clone> command=fetch/,/clone> 0001/p\" trace >request &&\n+\ttest_grep \"clone> promisor-remote=lop\" request &&\n+\n+\t# Check that the largest object is still missing on the server\n+\tcheck_missing_objects server 1 \"$oid\"\n+'\n+\n+test_expect_success \"fetch by object ID sends the promisor-remote reply\" '\n+\tgit -C server config promisor.advertise true &&\n+\ttest_when_finished \"rm -rf client trace\" &&\n+\n+\tgit init client &&\n+\tgit -C client remote add origin \"$TRASH_DIRECTORY_URL/server\" &&\n+\tgit -C client config remote.lop.promisor true &&\n+\tgit -C client config remote.lop.url \"$TRASH_DIRECTORY_URL/lop\" &&\n+\tgit -C client config promisor.acceptfromserver All &&\n+\n+\t# Fetching only an object ID skips the \"ls-refs\" command, so the\n+\t# reply can only be sent with \"fetch\"\n+\thead=$(git -C server rev-parse HEAD) &&\n+\tGIT_TRACE_PACKET=\"$(pwd)/trace\" git -C client fetch --no-tags \\\n+\t\t--filter=\"blob:limit=5k\" origin \"$head\" &&\n+\ttest_grep ! \"fetch> command=ls-refs\" trace &&\n+\ttest_grep \"fetch> promisor-remote=lop\" trace &&\n+\n+\t# Check that the largest object is still missing on the server\n+\tcheck_missing_objects server 1 \"$oid\"\n+'\n+\n test_expect_success \"clone with promisor.advertise set to 'true' but don't delete the client\" '\n \tgit -C server config promisor.advertise true &&\n \ndiff --git a/t/t5711-promisor-remote-capability-http.sh b/t/t5711-promisor-remote-capability-http.sh\nnew file mode 100755\nindex 0000000000..c08cca3e51\n--- /dev/null\n+++ b/t/t5711-promisor-remote-capability-http.sh\n@@ -0,0 +1,126 @@\n+#!/bin/sh\n+\n+test_description='handling of promisor remote advertisement over HTTP'\n+\n+. ./test-lib.sh\n+\n+if ! test_have_prereq PERL_TEST_HELPERS\n+then\n+\tskip_all='skipping promisor remote capabilities tests; Perl not available'\n+\ttest_done\n+fi\n+\n+. \"$TEST_DIRECTORY\"/lib-httpd.sh\n+start_httpd\n+\n+GIT_TEST_MULTI_PACK_INDEX=0\n+GIT_TEST_MULTI_PACK_INDEX_WRITE_INCREMENTAL=0\n+\n+# The setup and helpers below are copied from t5710, except that the\n+# server repository is in the HTTP document root.\n+\n+SERVER=\"$HTTPD_DOCUMENT_ROOT_PATH/server.git\"\n+\n+check_missing_objects () {\n+\tgit -C \"$1\" rev-list --objects --all --missing=print > all.txt &&\n+\tperl -ne 'print if s/^[?]//' all.txt >missing.txt &&\n+\ttest_line_count = \"$2\" missing.txt &&\n+\ttest \"$3\" = \"$(cat missing.txt)\"\n+}\n+\n+initialize_server () {\n+\t# Repack everything first\n+\tgit -C \"$SERVER\" -c repack.writebitmaps=false repack -a -d &&\n+\n+\t# Repack without the largest object and create a promisor pack on server\n+\tgit -C \"$SERVER\" -c repack.writebitmaps=false repack -a -d \\\n+\t    --filter=blob:limit=5k --filter-to=\"$(pwd)/pack\" &&\n+\tpromisor_file=$(ls \"$SERVER\"/objects/pack/*.pack | sed \"s/\\.pack/.promisor/\") &&\n+\t>\"$promisor_file\" &&\n+\n+\t# Check objects missing on the server\n+\tcheck_missing_objects \"$SERVER\" 1 \"$1\"\n+}\n+\n+copy_to_lop () {\n+\toid_path=\"$(test_oid_to_path $1)\" &&\n+\tpath=\"$SERVER/objects/$oid_path\" &&\n+\tpath2=\"lop/objects/$oid_path\" &&\n+\tmkdir -p $(dirname \"$path2\") &&\n+\tcp \"$path\" \"$path2\"\n+}\n+\n+# On Windows, `pwd` returns a path like 'D:/foo/bar'. Prepend '/' to turn\n+# it into '/D:/foo/bar', which is what git expects in file:// URLs on Windows.\n+# On Unix, the path already starts with '/', so this is a no-op.\n+pwd_path=$(pwd)\n+case \"$pwd_path\" in\n+[a-zA-Z]:*) pwd_path=\"/$pwd_path\" ;;\n+esac\n+\n+TRASH_DIRECTORY_URL=\"file://$pwd_path\"\n+\n+test_expect_success 'setup: create \"template\" repository' '\n+\tgit init template &&\n+\ttest_commit -C template 1 &&\n+\ttest_commit -C template 2 &&\n+\ttest_commit -C template 3 &&\n+\ttest-tool genrandom foo 10k >template/foo &&\n+\tgit -C template add foo &&\n+\tgit -C template commit -m foo\n+'\n+\n+# A bare repo will act as a server repo with unpacked objects.\n+test_expect_success 'setup: create bare \"server\" repository' '\n+\tgit clone --bare --no-local template \"$SERVER\" &&\n+\tmv \"$SERVER\"/objects/pack/pack-* . &&\n+\tpackfile=$(ls pack-*.pack) &&\n+\tgit -C \"$SERVER\" unpack-objects --strict <\"$packfile\"\n+'\n+\n+test_expect_success \"setup for testing promisor remote advertisement\" '\n+\t# Create another bare repo called \"lop\" (for Large Object Promisor)\n+\tgit init --bare lop &&\n+\n+\t# Copy the largest object from server to lop\n+\tobj=\"HEAD:foo\" &&\n+\toid=\"$(git -C \"$SERVER\" rev-parse $obj)\" &&\n+\tcopy_to_lop \"$oid\" &&\n+\n+\tinitialize_server \"$oid\" &&\n+\n+\t# Configure lop as promisor remote for server\n+\tgit -C \"$SERVER\" remote add lop \"$TRASH_DIRECTORY_URL/lop\" &&\n+\tgit -C \"$SERVER\" config remote.lop.promisor true &&\n+\n+\tgit -C lop config uploadpack.allowFilter true &&\n+\tgit -C lop config uploadpack.allowAnySHA1InWant true &&\n+\tgit -C \"$SERVER\" config uploadpack.allowFilter true &&\n+\tgit -C \"$SERVER\" config uploadpack.allowAnySHA1InWant true &&\n+\tgit -C \"$SERVER\" config promisor.advertise true\n+'\n+\n+# Over HTTP, each request is handled by a separate upload-pack process,\n+# so the server knows that the client accepted \"lop\" only if the reply\n+# is sent with the \"fetch\" request itself.\n+test_expect_success \"clone over HTTP with an accepted promisor remote\" '\n+\ttest_when_finished \"rm -rf client trace\" &&\n+\n+\tGIT_TRACE_PACKET=\"$(pwd)/trace\" git -c protocol.version=2 clone \\\n+\t\t-c remote.lop.promisor=true \\\n+\t\t-c remote.lop.url=\"$TRASH_DIRECTORY_URL/lop\" \\\n+\t\t-c promisor.acceptfromserver=All \\\n+\t\t--filter=\"blob:limit=5k\" \"$HTTPD_URL/smart/server.git\" client &&\n+\n+\t# Check that the reply is part of the fetch request\n+\tsed -n \"/clone> command=fetch/,/clone> 0001/p\" trace >request &&\n+\ttest_grep \"clone> promisor-remote=lop\" request &&\n+\n+\t# Check that the largest object was lazily fetched from lop\n+\ttest_cmp template/foo client/foo &&\n+\n+\t# Check that the largest object is still missing on the server\n+\tcheck_missing_objects \"$SERVER\" 1 \"$oid\"\n+'\n+\n+test_done\n-- \n2.56.0\n\n\n"},{"id":"558342","messageId":"20261112195858.53788-8-christian.couder@gmail.com","threadId":"66840","inReplyTo":"20261112195858.53788-5-christian.couder@gmail.com","subject":"[PATCH 3/3] doc: gitprotocol-v2: send the promisor-remote reply with fetch","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2026-11-12T19:59:02Z","receivedAt":"2026-11-12T19:59:02Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Until a previous commit, a client sent its `promisor-remote=...` reply\nonly with the `ls-refs` and `bundle-uri` protocol commands.\n\nLet's clearly document that the client should send that reply with the\n`fetch` command request too.\n\nReported-by: Matt Cote <mcote@nvidia.com>\nSigned-off-by: Christian Couder <christian.couder@gmail.com>\n---\n Documentation/gitprotocol-v2.adoc | 6 ++++++\n 1 file changed, 6 insertions(+)\n\ndiff --git a/Documentation/gitprotocol-v2.adoc b/Documentation/gitprotocol-v2.adoc\nindex dd52fd8110..b8732173cd 100644\n--- a/Documentation/gitprotocol-v2.adoc\n+++ b/Documentation/gitprotocol-v2.adoc\n@@ -879,6 +879,12 @@ In this case, or if the client doesn't want to use any promisor remote\n the server advertised, the client shouldn't advertise the\n \"promisor-remote\" capability at all in its reply.\n \n+As protocol v2 is stateless (see the \"Capabilities\" section above),\n+the client should send this reply with the `fetch` command request,\n+even if it has already sent it with an earlier command request, like\n+`ls-refs`. Note that when only some object IDs are fetched, the client\n+might not send any `ls-refs` command request at all.\n+\n On the server side, the \"promisor.advertise\" and \"promisor.sendFields\"\n configuration options can be used to control what it advertises. On\n the client side, the \"promisor.acceptFromServer\" and\n-- \n2.56.0\n\n\n"},{"id":"558355","messageId":"xmqq8q2xhexs.fsf@gitster.g","threadId":"66840","inReplyTo":"20261112195858.53788-6-christian.couder@gmail.com","subject":"Re: [PATCH 1/3] connect: let write_command_and_capabilities() send a promisor-remote reply","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-12T22:18:07Z","receivedAt":"2026-11-12T22:18:07Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christian Couder <christian.couder@gmail.com> writes:\n\n>  void write_command_and_capabilities(struct strbuf *req_buf, const char *command,\n> -\t\t\t\t    const struct string_list *server_options)\n> +\t\t\t\t    const struct string_list *server_options,\n> +\t\t\t\t    const char *promisor_remote_reply)\n>  {\n>  \tconst char *hash_name;\n>  \tint advertise_sid = 0;\n> @@ -754,6 +755,9 @@ void write_command_and_capabilities(struct strbuf *req_buf, const char *command,\n>  \t\tdie(_(\"the server does not support algorithm '%s'\"),\n>  \t\t    the_hash_algo->name);\n>  \t}\n> +\tif (promisor_remote_reply)\n> +\t\tpacket_buf_write(req_buf, \"promisor-remote=%s\",\n> +\t\t\t\t promisor_remote_reply);\n>  \tpacket_buf_delim(req_buf);\n>  }\n\nThis function was designed to have a fairly generic \"here we send a\ncommand and then capability exchange based on the settings stored in\nthe string list\" interface for extensibility.  It is highly annoying\nthat we are now adding a specific option here to be sent outside the\nframework.\n\nIsn't the misdesign being corrected that the \"promisor-remote=...\"\nstring was not sent as part of these server options list of strings?\nCan we fix it without contaminating the API like this patch does, or\nis it too late?\n\n"},{"id":"558357","messageId":"xmqq4idlhe69.fsf@gitster.g","threadId":"66840","inReplyTo":"xmqq8q2xhexs.fsf@gitster.g","subject":"Re: [PATCH 1/3] connect: let write_command_and_capabilities() send a promisor-remote reply","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-12T22:34:38Z","receivedAt":"2026-11-12T22:34:38Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Christian Couder <christian.couder@gmail.com> writes:\n>\n>>  void write_command_and_capabilities(struct strbuf *req_buf, const char *command,\n>> -\t\t\t\t    const struct string_list *server_options)\n>> +\t\t\t\t    const struct string_list *server_options,\n>> +\t\t\t\t    const char *promisor_remote_reply)\n>>  {\n>>  \tconst char *hash_name;\n>>  \tint advertise_sid = 0;\n>> @@ -754,6 +755,9 @@ void write_command_and_capabilities(struct strbuf *req_buf, const char *command,\n>>  \t\tdie(_(\"the server does not support algorithm '%s'\"),\n>>  \t\t    the_hash_algo->name);\n>>  \t}\n>> +\tif (promisor_remote_reply)\n>> +\t\tpacket_buf_write(req_buf, \"promisor-remote=%s\",\n>> +\t\t\t\t promisor_remote_reply);\n>>  \tpacket_buf_delim(req_buf);\n>>  }\n>\n> This function was designed to have a fairly generic \"here we send a\n> command and then capability exchange based on the settings stored in\n> the string list\" interface for extensibility.  It is highly annoying\n> that we are now adding a specific option here to be sent outside the\n> framework.\n>\n> Isn't the misdesign being corrected that the \"promisor-remote=...\"\n> string was not sent as part of these server options list of strings?\n> Can we fix it without contaminating the API like this patch does, or\n> is it too late?\n\nBy this I do not mean that promisor-remote=... has to be sent as one\nof the server options (i.e., making the string sent to something\nsilly like \"server-option=promisor-remote=...\").  Rather, I am\nwondering if the existing server_options string list should be made\ninto a more generalized form so that the string list can contain\nelements whose keys other than \"server-option\" can also be\ncontained (like \"promisor-remote\").  IOW, the caller can decide to\nput \"promisor-remote=...promisor remote reply...\" in the list,\ninstead of sending it as a totally separate parameter, whose\nsemantics is hardcoded (i.e. the fourth parameter to this function\nwill be sent as a value to \"promistor-remote=...\").\n\n\n\n"},{"id":"558387","messageId":"CAP8UFD18rTvM0mu9oSPMd3V+J9GBgc07RM91Pfh4RJqZg0s9aw@mail.gmail.com","threadId":"66840","inReplyTo":"xmqq4idlhe69.fsf@gitster.g","subject":"Re: [PATCH 1/3] connect: let write_command_and_capabilities() send a promisor-remote reply","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2026-11-13T13:10:57Z","receivedAt":"2026-11-13T13:10:57Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Thu, Nov 12, 2026 at 11:34 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Junio C Hamano <gitster@pobox.com> writes:\n>\n> > Christian Couder <christian.couder@gmail.com> writes:\n> >\n> >>  void write_command_and_capabilities(struct strbuf *req_buf, const char *command,\n> >> -                                const struct string_list *server_options)\n> >> +                                const struct string_list *server_options,\n> >> +                                const char *promisor_remote_reply)\n> >>  {\n> >>      const char *hash_name;\n> >>      int advertise_sid = 0;\n> >> @@ -754,6 +755,9 @@ void write_command_and_capabilities(struct strbuf *req_buf, const char *command,\n> >>              die(_(\"the server does not support algorithm '%s'\"),\n> >>                  the_hash_algo->name);\n> >>      }\n> >> +    if (promisor_remote_reply)\n> >> +            packet_buf_write(req_buf, \"promisor-remote=%s\",\n> >> +                             promisor_remote_reply);\n> >>      packet_buf_delim(req_buf);\n> >>  }\n> >\n> > This function was designed to have a fairly generic \"here we send a\n> > command and then capability exchange based on the settings stored in\n> > the string list\" interface for extensibility.  It is highly annoying\n> > that we are now adding a specific option here to be sent outside the\n> > framework.\n> >\n> > Isn't the misdesign being corrected that the \"promisor-remote=...\"\n> > string was not sent as part of these server options list of strings?\n> > Can we fix it without contaminating the API like this patch does, or\n> > is it too late?\n\nI think that if we wanted to clean this up, it would need a\nsignificant refactor as there are three separate places in \"connect.c\"\nthat write the client's protocol v2 capabilities:\n\n- send_capabilities() used for `bundle-uri`,\n- get_remote_refs() (using send_capabilities() and its own loop) used\nfor `ls-refs`,\n- write_command_and_capabilities() used for `fetch` and `object-info`.\n\nThey duplicate code for sending \"server-option\", \"agent\" and\n\"object-format\", while each sends a different set of capabilities.\n\nThe server side already has a table of  capabilities (`capabilities[]`\nin \"serve.c\") with generic advertise/receive handling. The client side\ncould have something similar for building requests.\n\n> By this I do not mean that promisor-remote=... has to be sent as one\n> of the server options (i.e., making the string sent to something\n> silly like \"server-option=promisor-remote=...\").  Rather, I am\n> wondering if the existing server_options string list should be made\n> into a more generalized form so that the string list can contain\n> elements whose keys other than \"server-option\" can also be\n> contained (like \"promisor-remote\").  IOW, the caller can decide to\n> put \"promisor-remote=...promisor remote reply...\" in the list,\n> instead of sending it as a totally separate parameter, whose\n> semantics is hardcoded (i.e. the fourth parameter to this function\n> will be sent as a value to \"promistor-remote=...\").\n\nI am willing to work on a significant refactoring along what you\nsuggest, but I think it should be a separate series from this bug fix\nseries, especially as we might want this fix to also go to maint.\n\nIn the meantime, I can send a v2 of this series with something like a\nNEEDSWORK comment, for example one in front of\nwrite_command_and_capabilities() saying that it should be refactored\nwith send_capabilities() and get_remote_refs(), so that callers build\nthe full list of capabilities, which would remove the\n`promisor_remote_reply` parameter\n\n"},{"id":"558419","messageId":"xmqqh5hkbl6t.fsf@gitster.g","threadId":"66840","inReplyTo":"CAP8UFD18rTvM0mu9oSPMd3V+J9GBgc07RM91Pfh4RJqZg0s9aw@mail.gmail.com","subject":"Re: [PATCH 1/3] connect: let write_command_and_capabilities() send a promisor-remote reply","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-13T19:11:54Z","receivedAt":"2026-11-13T19:11:54Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christian Couder <christian.couder@gmail.com> writes:\n\n> They duplicate code for sending \"server-option\", \"agent\" and\n> \"object-format\", while each sends a different set of capabilities.\n\nThat is all the more reason to clean them up before we pile more\nstuff on top, no?\n\nI do not know if that deserves to be called \"significant\"\nrefactoring, though.  It would not take a series with 20 patches\neach of which weigh more than 30 lines touched, no?\n\nThanks.\n\n\n\n"},{"id":"558964","messageId":"20261120164812.707946-10-christian.couder@gmail.com","threadId":"66840","inReplyTo":"20261112195858.53788-5-christian.couder@gmail.com","subject":"[PATCH v2 0/8] Fix promisor-remote reply missing from fetch","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2026-11-20T16:48:13Z","receivedAt":"2026-11-20T16:48:13Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"This started as a small series to fix a brown paper bag bug in the\n\"promisor-remote\" protocol v2 capability found by Matt Cote during the\nNVIDIA hackathon following the Gerrit User Summit 2026.\n\nBut with this version 2, it has become more of a refactoring of the\ncode that clients use to write protocol v2 capabilities. That's\nbecause there are three different places doing that in \"connect.c\":\n\n  - send_capabilities() used for `bundle-uri`,\n  - get_remote_refs() (using send_capabilities() and its own loop) used\n    for `ls-refs`,\n  - write_command_and_capabilities() used for `fetch` and `object-info`.\n\nSo a large part of this version 2 series refactors this, and now only\nwrite_command_and_capabilities() does it.\n\nThe bug, which is addressed in the last two patches of the series, is\nthat the client doesn't send a \"promisor-remote=...\" reply with the\n`fetch` protocol commands. It does send such a reply with the\n`ls-refs` and `bundle-uri` protocol commands. So this works by luck\nwith a Git server over file:// or ssh://, as the same `upload-pack`\nprocess handles all the requests and remembers the reply from\n`ls-refs`.\n\nBut it doesn't work with servers that handle each request on its own,\nlike Git over HTTP. (This is also how it was found with a JGit/Gerrit\nsetup during the hackathon.) It also doesn't work when only object IDs\nare fetched, as no `ls-refs` is sent then.\n\nIn these cases, the server doesn't know that the client accepted a\npromisor remote, so it doesn't allow the objects available on the\naccepted promisor remotes to be missing from the pack, and fails with\n\"could not fetch <oid> from promisor remote\".\n\nThis has been the case since the capability was introduced in v2.49,\nso it would be nice to have the fix in maint too. The series still\napplies cleanly on top of maint (v2.56.1) and the tests pass there. As\nthe wire changes in the first part of the series are small (see\nbelow), I hope the whole series can be considered for maint.\n\nOther related issues were found during the NVIDIA hackathon, but this\none is the most annoying. The others will be addressed in separate\nseries.\n\nOverview of the patches\n=======================\n\n  - Patches 1/8 to 6/8 make write_command_and_capabilities() the only\n    function that writes protocol v2 capabilities. That function\n    becomes more generic, while helper functions are added for callers\n    to prepare capabilities before passing them to that function.\n\n    There are a few wire changes in those mostly refactoring patches,\n    to unify the behavior when sending different requests:\n\n    - patch 2/8 sends \"session-id\" with `ls-refs` and `bundle-uri`\n      requests (only when `transfer.advertiseSID` is set),\n\n    - patch 4/8 changes how failing to write `ls-refs` and\n      `bundle-uri` requests is reported, as we now die with \"unable to\n      write request to remote\", like for `fetch` and `object-info`\n      requests, instead of with \"packet write with format failed\" (or\n      silently from SIGPIPE on EPIPE),\n\n    - patches 5/8 and 6/8 change the order of the capability lines,\n      and \"command=bundle-uri\" now comes first,\n\n    - patches 5/8 and 6/8 also stop sending a trailing \"\\n\" after\n      \"command=ls-refs\" and \"command=bundle-uri\".\n\n  - Patch 7/8 (\"fetch-pack: ensure fetch sends a promisor-remote\n    reply\") is the actual fix, with new tests in t5710, and in a new\n    t5711 test script for HTTP.\n\n  - Patch 8/8 (\"doc: gitprotocol-v2: send the promisor-remote reply\n    with fetch\") documents that the client should send the reply with\n    `fetch` requests asking for a pack.\n\nChanges compared to v1\n======================\n\nThanks to Junio for reviewing v1. As he suggested, callers now build\nthe list of capabilities they want to send and pass it to\nwrite_command_and_capabilities(), instead of passing a specific\npromisor-remote reply argument.\n\n  - Patches 1/8 to 6/8 are new. They replace patch 1/3 in v1 (which\n    only added a new `const char *promisor_remote_reply` argument to\n    write_command_and_capabilities() so that this function could send\n    a promisor-remote reply).\n\n  - Patch 7/8 now uses a new add_promisor_remote_reply() helper\n    function introduced by previous patches to prepare the\n    \"promisor-remote\" capability reply, and then always writes it with\n    the improved write_command_and_capabilities() when sending a\n    `fetch` request. The added tests are the same as in v1.\n\n  - Patch 8/8 now documents that the reply should be sent with each\n    `fetch` request asking for a pack (so not with negotiation-only\n    requests), and mentions `bundle-uri` along with `ls-refs`.\n\nCI tests\n========\n\nSome failed, others didn't even start, see:\n\nhttps://github.com/chriscool/git/actions/runs/44747276981\n\nBut all these issues look unrelated to this series.\n\nRange-diff compared to v1\n=========================\n\n1:  523fec7fc3 < -:  ---------- connect: let write_command_and_capabilities() send a promisor-remote reply\n-:  ---------- > 1:  0b8a469426 connect: pass capability lines to write_command_and_capabilities()\n-:  ---------- > 2:  b5814012e7 connect: send session-id with ls-refs and bundle-uri\n-:  ---------- > 3:  9ae83a24d4 connect: pass a reader to write_command_and_capabilities()\n-:  ---------- > 4:  b9393478d9 connect: buffer the ls-refs and bundle-uri requests\n-:  ---------- > 5:  c7bb7aea1e connect: use write_command_and_capabilities() in get_remote_refs()\n-:  ---------- > 6:  6f8b694584 connect: use write_command_and_capabilities() in get_remote_bundle_uri()\n2:  8e2294ec62 ! 7:  d3ab977624 fetch-pack: ensure fetch sends a promisor-remote reply\n    @@ Commit message\n         fetch-pack: ensure fetch sends a promisor-remote reply\n     \n         In protocol v2, when the client accepts promisor remotes, the\n    -    `promisor-remote=...` reply is only written by send_capabilities(),\n    -    which is used to send the `ls-refs` and `bundle-uri` protocol commands.\n    +    `promisor-remote=...` reply is only sent with the `ls-refs` and\n    +    `bundle-uri` protocol commands, by get_remote_refs() and\n    +    get_remote_bundle_uri() in \"connect.c\".\n     \n         The request for the `fetch` protocol command is built by\n    -    write_command_and_capabilities() called by send_fetch_request() in\n    -    \"fetch-pack.c\" which doesn't send that reply. do_fetch_pack_v2() calls\n    -    promisor_remote_reply(), but only to mark the accepted remotes, as\n    -    e15a6b2f8b (promisor-remote: change promisor_remote_reply()'s\n    -    signature, 2026-02-16) assumed that fetch-pack would not need to send\n    -    a reply.\n    +    send_fetch_request() in \"fetch-pack.c\" which doesn't send that reply.\n    +    do_fetch_pack_v2() calls promisor_remote_reply(), but only to mark the\n    +    accepted remotes, as e15a6b2f8b (promisor-remote: change\n    +    promisor_remote_reply()'s signature, 2026-02-16) assumed that\n    +    fetch-pack would not need to send a reply.\n     \n         With file:// and ssh:// URLs on a Git server, one upload-pack process\n         handles both `ls-refs` and `fetch`. The acceptance recorded during\n         `ls-refs` by promisor_remote_receive() in \"serve.c\" is still there at\n         `fetch` time, so the clone succeeds. But it fails when each request is\n         handled on its own, for example with HTTP where different upload-pack\n    -    processes are used, or with other server implementations like JGit.\n    +    processes are used.\n     \n         It also fails when only object IDs are fetched, as no `ls-refs`\n         command is then sent. In these cases, the server doesn't know that the\n    @@ Commit message\n         objects to be missing from the pack it sends, and it fails with \"could\n         not fetch <oid> from promisor remote\".\n     \n    -    Let's fix that by always properly sending the `promisor-remote=...`\n    -    reply when sending a `fetch` request from do_fetch_pack_v2().\n    +    Let's fix that by building the list of capabilities for the `fetch`\n    +    requests once in do_fetch_pack_v2(), using add_server_options() and\n    +    add_promisor_remote_reply(), and by passing that list to\n    +    send_fetch_request(). This way the `promisor-remote=...` reply is\n    +    always properly sent with the `fetch` requests, and the accepted\n    +    remotes are still marked at the same point as before.\n     \n         The `fetch` requests sent by negotiate_using_fetch() don't ask for a\n         pack, so they don't need that reply.\n    @@ fetch-pack.c: static int send_fetch_request(struct fetch_negotiator *negotiator,\n      \t\t\t      int sideband_all, int seen_ack,\n     -\t\t\t      struct oidset *negotiation_include_oids)\n     +\t\t\t      struct oidset *negotiation_include_oids,\n    -+\t\t\t      const char *promisor_remote_reply)\n    ++\t\t\t      const struct strvec *capabilities)\n      {\n      \tint haves_added;\n      \tint done_sent = 0;\n      \tstruct strbuf req_buf = STRBUF_INIT;\n    +-\tstruct strvec capabilities = STRVEC_INIT;\n      \n    +-\tadd_server_options(&capabilities, args->server_options);\n      \twrite_command_and_capabilities(&req_buf, \"fetch\",\n    --\t\t\t\t       args->server_options, NULL);\n    -+\t\t\t\t       args->server_options,\n    -+\t\t\t\t       promisor_remote_reply);\n    +-\t\t\t\t       &capabilities, NULL);\n    ++\t\t\t\t       capabilities, NULL);\n      \n      \tif (args->use_thin_pack)\n      \t\tpacket_buf_write(&req_buf, \"thin-pack\");\n    +@@ fetch-pack.c: static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,\n    + \tif (write_in_full(fd_out, req_buf.buf, req_buf.len) < 0)\n    + \t\tdie_errno(_(\"unable to write request to remote\"));\n    + \n    +-\tstrvec_clear(&capabilities);\n    + \tstrbuf_release(&req_buf);\n    + \treturn done_sent;\n    + }\n     @@ fetch-pack.c: static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,\n    + \tstruct string_list packfile_uris = STRING_LIST_INIT_DUP;\n      \tint i;\n      \tstruct strvec index_pack_args = STRVEC_INIT;\n    - \tconst char *promisor_remote_config;\n    -+\tchar *accepted = NULL;\n    +-\tconst char *promisor_remote_config;\n    ++\tstruct strvec capabilities = STRVEC_INIT;\n      \n      \tfsck_options_init(&fsck_options, the_repository, FSCK_OPTIONS_MISSING_GITMODULES);\n      \n    - \tif (server_feature_v2(\"promisor-remote\", &promisor_remote_config))\n    +-\tif (server_feature_v2(\"promisor-remote\", &promisor_remote_config))\n     -\t\tpromisor_remote_reply(promisor_remote_config, NULL);\n    -+\t\tpromisor_remote_reply(promisor_remote_config, &accepted);\n    ++\tadd_server_options(&capabilities, args->server_options);\n    ++\tadd_promisor_remote_reply(&capabilities);\n      \n      \tif (args->filter_options.choice == LOFC_AUTO) {\n      \t\tstruct strbuf errbuf = STRBUF_INIT;\n    @@ fetch-pack.c: static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,\n      \t\t\t\t\t       seen_ack,\n     -\t\t\t\t\t       &negotiation_include_oids)) {\n     +\t\t\t\t\t       &negotiation_include_oids,\n    -+\t\t\t\t\t       accepted)) {\n    ++\t\t\t\t\t       &capabilities)) {\n      \t\t\t\ttrace2_region_leave_printf(\"negotiation_v2\", \"round\",\n      \t\t\t\t\t\t\t   the_repository, \"%d\",\n      \t\t\t\t\t\t\t   negotiation_round);\n     @@ fetch-pack.c: static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,\n    - \tif (negotiator)\n    - \t\tnegotiator->release(negotiator);\n      \n    -+\tfree(accepted);\n    - \tfsck_options_clear(&fsck_options);\n    - \toidset_clear(&common);\n    - \toidset_clear(&negotiation_include_oids);\n    + \tstring_list_clear(&packfile_uris, 0);\n    + \tstrvec_clear(&index_pack_args);\n    ++\tstrvec_clear(&capabilities);\n    + \n    + \tif (fsck_finish(&fsck_options))\n    + \t\tdie(\"fsck failed\");\n     \n      ## t/meson.build ##\n     @@ t/meson.build: integration_tests = [\n3:  4103b0f449 ! 8:  40f7866ade doc: gitprotocol-v2: send the promisor-remote reply with fetch\n    @@ Commit message\n         Until a previous commit, a client sent its `promisor-remote=...` reply\n         only with the `ls-refs` and `bundle-uri` protocol commands.\n     \n    -    Let's clearly document that the client should send that reply with the\n    -    `fetch` command request too.\n    +    Let's clearly document that the client should send that reply with each\n    +    `fetch` command request asking for a pack too, as protocol v2 is\n    +    stateless.\n    +\n    +    The `fetch` requests sent only for negotiation, like with `git fetch\n    +    --negotiate-only`, don't ask for a pack, so they don't need that reply.\n     \n         Reported-by: Matt Cote <mcote@nvidia.com>\n         Signed-off-by: Christian Couder <christian.couder@gmail.com>\n    @@ Documentation/gitprotocol-v2.adoc: In this case, or if the client doesn't want t\n      \"promisor-remote\" capability at all in its reply.\n      \n     +As protocol v2 is stateless (see the \"Capabilities\" section above),\n    -+the client should send this reply with the `fetch` command request,\n    -+even if it has already sent it with an earlier command request, like\n    -+`ls-refs`. Note that when only some object IDs are fetched, the client\n    -+might not send any `ls-refs` command request at all.\n    ++the client should send this reply with each `fetch` command request\n    ++asking for a pack, even if it has already sent it with an earlier\n    ++command request, like `ls-refs` or `bundle-uri`. Note that when only\n    ++some object IDs are fetched, the client might not send any `ls-refs`\n    ++command request at all.\n     +\n      On the server side, the \"promisor.advertise\" and \"promisor.sendFields\"\n      configuration options can be used to control what it advertises. On\n\nChristian Couder (8):\n  connect: pass capability lines to write_command_and_capabilities()\n  connect: send session-id with ls-refs and bundle-uri\n  connect: pass a reader to write_command_and_capabilities()\n  connect: buffer the ls-refs and bundle-uri requests\n  connect: use write_command_and_capabilities() in get_remote_refs()\n  connect: use write_command_and_capabilities() in\n    get_remote_bundle_uri()\n  fetch-pack: ensure fetch sends a promisor-remote reply\n  doc: gitprotocol-v2: send the promisor-remote reply with fetch\n\n Documentation/gitprotocol-v2.adoc          |   7 ++\n connect.c                                  | 128 ++++++++++++---------\n connect.h                                  |  30 ++++-\n fetch-object-info.c                        |   7 +-\n fetch-pack.c                               |  23 ++--\n t/meson.build                              |   1 +\n t/t5705-session-id-in-capabilities.sh      |  26 +++++\n t/t5710-promisor-remote-capability.sh      |  40 +++++++\n t/t5711-promisor-remote-capability-http.sh | 126 ++++++++++++++++++++\n 9 files changed, 322 insertions(+), 66 deletions(-)\n create mode 100755 t/t5711-promisor-remote-capability-http.sh\n\n\nbase-commit: e1ec09b23c8e0deb21a0b95ac5996422277395d4\n-- \n2.56.0\n\n\n"},{"id":"558965","messageId":"20261120164812.707946-11-christian.couder@gmail.com","threadId":"66840","inReplyTo":"20261120164812.707946-10-christian.couder@gmail.com","subject":"[PATCH v2 1/8] connect: pass capability lines to write_command_and_capabilities()","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2026-11-20T16:48:14Z","receivedAt":"2026-11-20T16:48:14Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"There are three different functions that write capabilities on the\nclient side:\n\n  - get_remote_refs(),\n  - send_capabilities(), and\n  - write_command_and_capabilities().\n\nThey duplicate code and make things difficult to understand, fix and\nextend.\n\nTo start rationalizing this, let's make the\nwrite_command_and_capabilities() function more generic, by replacing\nits `const struct string_list *server_options` argument with a\n`const struct strvec *capabilities` argument.\n\nThis will make it possible for other functions to reuse this function\nin following commits.\n\nTo allow callers to generate the \"server-option=...\" capability lines\nthat can then be passed to write_command_and_capabilities() through its\nnew `capabilities` argument, let's also add a new add_server_options()\nhelper function.\n\nNo change in behavior is intended.\n\nSigned-off-by: Christian Couder <christian.couder@gmail.com>\n---\n connect.c           | 32 ++++++++++++++++++++++++++------\n connect.h           | 17 +++++++++++++++--\n fetch-object-info.c |  6 +++++-\n fetch-pack.c        | 11 +++++++++--\n 4 files changed, 55 insertions(+), 11 deletions(-)\n\ndiff --git a/connect.c b/connect.c\nindex 87d2e8bccd..5f73fd9e7e 100644\n--- a/connect.c\n+++ b/connect.c\n@@ -723,9 +723,22 @@ int server_supports(const char *feature)\n \treturn !!server_feature_value(feature, NULL);\n }\n \n+void add_server_options(struct strvec *capabilities,\n+\t\t\tconst struct string_list *server_options)\n+{\n+\tstruct string_list_item *item;\n+\n+\tif (!server_options)\n+\t\treturn;\n+\n+\tfor_each_string_list_item(item, server_options)\n+\t\tstrvec_pushf(capabilities, \"server-option=%s\", item->string);\n+}\n+\n void write_command_and_capabilities(struct strbuf *req_buf, const char *command,\n-\t\t\t\t    const struct string_list *server_options)\n+\t\t\t\t    const struct strvec *capabilities)\n {\n+\tstruct strbuf key = STRBUF_INIT;\n \tconst char *hash_name;\n \tint advertise_sid = 0;\n \n@@ -737,11 +750,16 @@ void write_command_and_capabilities(struct strbuf *req_buf, const char *command,\n \t\tpacket_buf_write(req_buf, \"agent=%s\", git_user_agent_sanitized());\n \tif (advertise_sid && server_supports_v2(\"session-id\"))\n \t\tpacket_buf_write(req_buf, \"session-id=%s\", trace2_session_id());\n-\tif (server_options && server_options->nr) {\n-\t\tensure_server_supports_v2(\"server-option\");\n-\t\tfor (size_t i = 0; i < server_options->nr; i++)\n-\t\t\tpacket_buf_write(req_buf, \"server-option=%s\",\n-\t\t\t\t\t server_options->items[i].string);\n+\n+\tfor (size_t i = 0; i < capabilities->nr; i++) {\n+\t\tconst char *cap = capabilities->v[i];\n+\t\tsize_t key_len = strcspn(cap, \"=\");\n+\n+\t\tstrbuf_add(&key, cap, key_len);\n+\t\tensure_server_supports_v2(key.buf);\n+\t\tpacket_buf_write(req_buf, \"%s\", cap);\n+\n+\t\tstrbuf_reset(&key);\n \t}\n \n \tif (server_feature_v2(\"object-format\", &hash_name)) {\n@@ -754,7 +772,9 @@ void write_command_and_capabilities(struct strbuf *req_buf, const char *command,\n \t\tdie(_(\"the server does not support algorithm '%s'\"),\n \t\t    the_hash_algo->name);\n \t}\n+\n \tpacket_buf_delim(req_buf);\n+\tstrbuf_release(&key);\n }\n \n static const char *url_scheme_name(enum url_scheme scheme)\ndiff --git a/connect.h b/connect.h\nindex 957e5fe2b9..2d5f9e2b83 100644\n--- a/connect.h\n+++ b/connect.h\n@@ -35,11 +35,24 @@ void check_stateless_delimiter(int stateless_rpc,\n \t\t\t       const char *error);\n \n struct string_list;\n+struct strvec;\n+\n+/*\n+ * Append a \"server-option=<value>\" capability to `capabilities` for\n+ * each item in `server_options`, which may be NULL.\n+ */\n+void add_server_options(struct strvec *capabilities,\n+\t\t\tconst struct string_list *server_options);\n+\n /*\n  * Write a protocol v2 command request, along with the capability\n- * advertisements, into req_buf.\n+ * advertisements, into req_buf. The \"agent\", \"session-id\" and\n+ * \"object-format\" capabilities are handled here, and must not be in\n+ * `capabilities`. `capabilities` contains complete \"key[=value]\"\n+ * lines and must not be NULL. The keys in `capabilities` must have\n+ * been advertised by the server, otherwise we die().\n  */\n void write_command_and_capabilities(struct strbuf *req_buf, const char *command,\n-\t\t\t\t    const struct string_list *server_options);\n+\t\t\t\t    const struct strvec *capabilities);\n \n #endif\ndiff --git a/fetch-object-info.c b/fetch-object-info.c\nindex 0a58308f9b..cd14105836 100644\n--- a/fetch-object-info.c\n+++ b/fetch-object-info.c\n@@ -8,6 +8,7 @@\n #include \"odb.h\"\n #include \"fetch-object-info.h\"\n #include \"string-list.h\"\n+#include \"strvec.h\"\n \n /* Sends object-info command and its arguments into the request buffer. */\n static void send_object_info_request(const int fd_out,\n@@ -17,8 +18,10 @@ static void send_object_info_request(const int fd_out,\n \t\t\t\t     unsigned ask_type)\n {\n \tstruct strbuf req_buf = STRBUF_INIT;\n+\tstruct strvec capabilities = STRVEC_INIT;\n \n-\twrite_command_and_capabilities(&req_buf, \"object-info\", server_options);\n+\tadd_server_options(&capabilities, server_options);\n+\twrite_command_and_capabilities(&req_buf, \"object-info\", &capabilities);\n \n \tif (ask_size)\n \t\tpacket_buf_write(&req_buf, \"size\");\n@@ -35,6 +38,7 @@ static void send_object_info_request(const int fd_out,\n \tif (write_in_full(fd_out, req_buf.buf, req_buf.len) < 0)\n \t\tdie_errno(_(\"unable to write request to remote\"));\n \n+\tstrvec_clear(&capabilities);\n \tstrbuf_release(&req_buf);\n }\n \ndiff --git a/fetch-pack.c b/fetch-pack.c\nindex 55d311c0c3..ecb384211c 100644\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -1385,8 +1385,10 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,\n \tint haves_added;\n \tint done_sent = 0;\n \tstruct strbuf req_buf = STRBUF_INIT;\n+\tstruct strvec capabilities = STRVEC_INIT;\n \n-\twrite_command_and_capabilities(&req_buf, \"fetch\", args->server_options);\n+\tadd_server_options(&capabilities, args->server_options);\n+\twrite_command_and_capabilities(&req_buf, \"fetch\", &capabilities);\n \n \tif (args->use_thin_pack)\n \t\tpacket_buf_write(&req_buf, \"thin-pack\");\n@@ -1451,6 +1453,7 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,\n \tif (write_in_full(fd_out, req_buf.buf, req_buf.len) < 0)\n \t\tdie_errno(_(\"unable to write request to remote\"));\n \n+\tstrvec_clear(&capabilities);\n \tstrbuf_release(&req_buf);\n \treturn done_sent;\n }\n@@ -2242,6 +2245,7 @@ void negotiate_using_fetch(const struct oid_array *negotiation_restrict_tips,\n \tint last_iteration = 0;\n \tint negotiation_round = 0;\n \ttimestamp_t min_generation = GENERATION_NUMBER_INFINITY;\n+\tstruct strvec capabilities = STRVEC_INIT;\n \n \tfetch_negotiator_init(the_repository, &negotiator);\n \tmark_tips(&negotiator, negotiation_restrict_tips);\n@@ -2257,6 +2261,8 @@ void negotiate_using_fetch(const struct oid_array *negotiation_restrict_tips,\n \t\t\t   add_to_object_array,\n \t\t\t   &nt_object_array);\n \n+\tadd_server_options(&capabilities, server_options);\n+\n \ttrace2_region_enter(\"fetch-pack\", \"negotiate_using_fetch\", the_repository);\n \twhile (!last_iteration) {\n \t\tint haves_added;\n@@ -2269,7 +2275,7 @@ void negotiate_using_fetch(const struct oid_array *negotiation_restrict_tips,\n \t\t\t\t\t   the_repository, \"%d\",\n \t\t\t\t\t   negotiation_round);\n \t\tstrbuf_reset(&req_buf);\n-\t\twrite_command_and_capabilities(&req_buf, \"fetch\", server_options);\n+\t\twrite_command_and_capabilities(&req_buf, \"fetch\", &capabilities);\n \n \t\tpacket_buf_write(&req_buf, \"wait-for-done\");\n \n@@ -2324,6 +2330,7 @@ void negotiate_using_fetch(const struct oid_array *negotiation_restrict_tips,\n \ttrace2_data_intmax(\"negotiate_using_fetch\", the_repository,\n \t\t\t   \"total_rounds\", negotiation_round);\n \n+\tstrvec_clear(&capabilities);\n \tclear_common_flag(acked_commits);\n \tobject_array_clear(&nt_object_array);\n \toidset_clear(&negotiation_include_oids);\n-- \n2.56.0\n\n\n"},{"id":"558966","messageId":"20261120164812.707946-12-christian.couder@gmail.com","threadId":"66840","inReplyTo":"20261120164812.707946-10-christian.couder@gmail.com","subject":"[PATCH v2 2/8] connect: send session-id with ls-refs and bundle-uri","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2026-11-20T16:48:15Z","receivedAt":"2026-11-20T16:48:15Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"1e905bbc00 (fetch-pack: advertise session ID in capabilities,\n2020-11-11) only added session-id to fetch-pack and doesn't say why it\nwas left out elsewhere. According to our \"gitprotocol-v2.adoc\"\ndocumentation, the goal of session IDs is to identify the process\nacross multiple requests, so there is no reason to not send it with\nevery request.\n\nLet's then also send session-id in the `ls-refs` and `bundle-uri`\nrequests which go through send_capabilities().\n\nNote that this only changes behavior when `transfer.advertiseSID` is\nset, which is not the default.\n\nAlso note that over file:// and ssh:// one upload-pack process handles\nboth `ls-refs` and `fetch`, so the server now logs the client's\nsession-id twice per process, but this is harmless.\n\nLet's add tests in t5705 to check that the server receives the\nclient's session-id when only `ls-refs` is sent (with `git ls-remote`)\nand when only `bundle-uri` is sent (with `test-tool bundle-uri\nls-remote`), as the existing tests there only use `fetch`, which\nalready sent it.\n\nSigned-off-by: Christian Couder <christian.couder@gmail.com>\n---\n connect.c                             |  6 ++++++\n t/t5705-session-id-in-capabilities.sh | 26 ++++++++++++++++++++++++++\n 2 files changed, 32 insertions(+)\n\ndiff --git a/connect.c b/connect.c\nindex 5f73fd9e7e..40cd279290 100644\n--- a/connect.c\n+++ b/connect.c\n@@ -505,10 +505,16 @@ static void send_capabilities(int fd_out, struct packet_reader *reader)\n {\n \tconst char *hash_name;\n \tconst char *promisor_remote_info;\n+\tint advertise_sid = 0;\n+\n+\trepo_config_get_bool(the_repository, \"transfer.advertisesid\", &advertise_sid);\n \n \tif (server_supports_v2(\"agent\"))\n \t\tpacket_write_fmt(fd_out, \"agent=%s\", git_user_agent_sanitized());\n \n+\tif (advertise_sid && server_supports_v2(\"session-id\"))\n+\t\tpacket_write_fmt(fd_out, \"session-id=%s\", trace2_session_id());\n+\n \tif (server_feature_v2(\"object-format\", &hash_name)) {\n \t\tint hash_algo = hash_algo_by_name(hash_name);\n \t\tif (hash_algo == GIT_HASH_UNKNOWN)\ndiff --git a/t/t5705-session-id-in-capabilities.sh b/t/t5705-session-id-in-capabilities.sh\nindex ef0db57d1f..9b35c62629 100755\n--- a/t/t5705-session-id-in-capabilities.sh\n+++ b/t/t5705-session-id-in-capabilities.sh\n@@ -84,4 +84,30 @@ do\n \t'\n done\n \n+test_expect_success 'session IDs advertised (ls-remote v2)' '\n+\ttest_when_finished \"rm -rf local tr2-server-events\" &&\n+\tcp -r \"$LOCAL_PRISTINE\" local &&\n+\tgit -c protocol.version=2 -C local ls-remote \\\n+\t\t--upload-pack \"GIT_TRACE2_EVENT=\\\"$(pwd)/tr2-server-events\\\" git-upload-pack\" \\\n+\t\torigin &&\n+\ttest_grep \\\"key\\\":\\\"client-sid\\\" tr2-server-events\n+'\n+\n+test_expect_success 'session IDs advertised (bundle-uri v2)' '\n+\ttest_when_finished \"rm -f trace tr2-events\" &&\n+\ttest_config -C \"$REPO\" uploadpack.advertiseBundleURIs true &&\n+\ttest_config_global transfer.advertiseSID true &&\n+\ttest_config_global transfer.bundleURI true &&\n+\n+\t# Only the server logs \"client-sid\", so the client and the\n+\t# server can share the same trace2 event file.\n+\tGIT_TRACE_PACKET=\"$(pwd)/trace\" GIT_TRACE2_EVENT=\"$(pwd)/tr2-events\" \\\n+\ttest-tool bundle-uri ls-remote \"file://$REPO\" &&\n+\n+\t# Only the \"bundle-uri\" command is sent\n+\ttest_grep \"> command=bundle-uri\" trace &&\n+\ttest_grep ! \"> command=ls-refs\" trace &&\n+\ttest_grep \\\"key\\\":\\\"client-sid\\\" tr2-events\n+'\n+\n test_done\n-- \n2.56.0\n\n\n"},{"id":"558967","messageId":"20261120164812.707946-13-christian.couder@gmail.com","threadId":"66840","inReplyTo":"20261120164812.707946-10-christian.couder@gmail.com","subject":"[PATCH v2 3/8] connect: pass a reader to write_command_and_capabilities()","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2026-11-20T16:48:16Z","receivedAt":"2026-11-20T16:48:16Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"send_capabilities(), used for `ls-refs` and `bundle-uri`, sets\n`reader->hash_algo` to the object format advertised by the server, as\nthe client may not know its own yet (for example in `git clone`). On\nthe other hand, write_command_and_capabilities(), used for `fetch` and\n`object-info`, checks the server's object format against\n`the_hash_algo`.\n\nTo enable write_command_and_capabilities() to replace\nsend_capabilities() in a following commit, let's add a\n`struct packet_reader *reader` argument to it.\n\nWhen that `reader` is NULL, write_command_and_capabilities() behaves as\nit used to, but when it is not NULL, it behaves as send_capabilities()\ndoes, and sets `reader->hash_algo` to the server's algorithm.\n\nNo behavior change is intended in this patch as callers always pass a\nNULL `reader` to write_command_and_capabilities().\n\nSigned-off-by: Christian Couder <christian.couder@gmail.com>\n---\n connect.c           | 16 +++++++++++++---\n connect.h           |  9 +++++++--\n fetch-object-info.c |  3 ++-\n fetch-pack.c        |  6 ++++--\n 4 files changed, 26 insertions(+), 8 deletions(-)\n\ndiff --git a/connect.c b/connect.c\nindex 40cd279290..71d9e98a4b 100644\n--- a/connect.c\n+++ b/connect.c\n@@ -742,7 +742,8 @@ void add_server_options(struct strvec *capabilities,\n }\n \n void write_command_and_capabilities(struct strbuf *req_buf, const char *command,\n-\t\t\t\t    const struct strvec *capabilities)\n+\t\t\t\t    const struct strvec *capabilities,\n+\t\t\t\t    struct packet_reader *reader)\n {\n \tstruct strbuf key = STRBUF_INIT;\n \tconst char *hash_name;\n@@ -770,10 +771,19 @@ void write_command_and_capabilities(struct strbuf *req_buf, const char *command,\n \n \tif (server_feature_v2(\"object-format\", &hash_name)) {\n \t\tconst unsigned int hash_algo = hash_algo_by_name(hash_name);\n-\t\tif (hash_algo_by_ptr(the_hash_algo) != hash_algo)\n+\t\tif (reader) {\n+\t\t\tif (hash_algo == GIT_HASH_UNKNOWN)\n+\t\t\t\tdie(_(\"unknown object format '%s' specified by server\"),\n+\t\t\t\t    hash_name);\n+\t\t\treader->hash_algo = &hash_algos[hash_algo];\n+\t\t} else if (hash_algo_by_ptr(the_hash_algo) != hash_algo) {\n \t\t\tdie(_(\"mismatched algorithms: client %s; server %s\"),\n \t\t\t    the_hash_algo->name, hash_name);\n-\t\tpacket_buf_write(req_buf, \"object-format=%s\", the_hash_algo->name);\n+\t\t}\n+\t\tpacket_buf_write(req_buf, \"object-format=%s\",\n+\t\t\t\t hash_algos[hash_algo].name);\n+\t} else if (reader) {\n+\t\treader->hash_algo = &hash_algos[GIT_HASH_SHA1_LEGACY];\n \t} else if (hash_algo_by_ptr(the_hash_algo) != GIT_HASH_SHA1_LEGACY) {\n \t\tdie(_(\"the server does not support algorithm '%s'\"),\n \t\t    the_hash_algo->name);\ndiff --git a/connect.h b/connect.h\nindex 2d5f9e2b83..cff987ae38 100644\n--- a/connect.h\n+++ b/connect.h\n@@ -50,9 +50,14 @@ void add_server_options(struct strvec *capabilities,\n  * \"object-format\" capabilities are handled here, and must not be in\n  * `capabilities`. `capabilities` contains complete \"key[=value]\"\n  * lines and must not be NULL. The keys in `capabilities` must have\n- * been advertised by the server, otherwise we die().\n+ * been advertised by the server, otherwise we die(). If `reader` is\n+ * not NULL, its `hash_algo` member is set from the \"object-format\"\n+ * capability sent by the server (or to SHA-1 if the server didn't\n+ * send one). Otherwise that capability is checked against\n+ * `the_hash_algo`, and we die() if they don't match.\n  */\n void write_command_and_capabilities(struct strbuf *req_buf, const char *command,\n-\t\t\t\t    const struct strvec *capabilities);\n+\t\t\t\t    const struct strvec *capabilities,\n+\t\t\t\t    struct packet_reader *reader);\n \n #endif\ndiff --git a/fetch-object-info.c b/fetch-object-info.c\nindex cd14105836..b7a5996233 100644\n--- a/fetch-object-info.c\n+++ b/fetch-object-info.c\n@@ -21,7 +21,8 @@ static void send_object_info_request(const int fd_out,\n \tstruct strvec capabilities = STRVEC_INIT;\n \n \tadd_server_options(&capabilities, server_options);\n-\twrite_command_and_capabilities(&req_buf, \"object-info\", &capabilities);\n+\twrite_command_and_capabilities(&req_buf, \"object-info\",\n+\t\t\t\t       &capabilities, NULL);\n \n \tif (ask_size)\n \t\tpacket_buf_write(&req_buf, \"size\");\ndiff --git a/fetch-pack.c b/fetch-pack.c\nindex ecb384211c..176d625936 100644\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -1388,7 +1388,8 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,\n \tstruct strvec capabilities = STRVEC_INIT;\n \n \tadd_server_options(&capabilities, args->server_options);\n-\twrite_command_and_capabilities(&req_buf, \"fetch\", &capabilities);\n+\twrite_command_and_capabilities(&req_buf, \"fetch\",\n+\t\t\t\t       &capabilities, NULL);\n \n \tif (args->use_thin_pack)\n \t\tpacket_buf_write(&req_buf, \"thin-pack\");\n@@ -2275,7 +2276,8 @@ void negotiate_using_fetch(const struct oid_array *negotiation_restrict_tips,\n \t\t\t\t\t   the_repository, \"%d\",\n \t\t\t\t\t   negotiation_round);\n \t\tstrbuf_reset(&req_buf);\n-\t\twrite_command_and_capabilities(&req_buf, \"fetch\", &capabilities);\n+\t\twrite_command_and_capabilities(&req_buf, \"fetch\",\n+\t\t\t\t\t       &capabilities, NULL);\n \n \t\tpacket_buf_write(&req_buf, \"wait-for-done\");\n \n-- \n2.56.0\n\n\n"},{"id":"558968","messageId":"20261120164812.707946-14-christian.couder@gmail.com","threadId":"66840","inReplyTo":"20261120164812.707946-10-christian.couder@gmail.com","subject":"[PATCH v2 4/8] connect: buffer the ls-refs and bundle-uri requests","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2026-11-20T16:48:17Z","receivedAt":"2026-11-20T16:48:17Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"The `fetch` and `object-info` requests are built into a `struct strbuf`\nusing write_command_and_capabilities() and packet_buf_*() functions,\nand then sent with a single write_in_full() call. On the other hand,\nthe `ls-refs` and `bundle-uri` requests are written directly to the\nfile descriptor, packet by packet, using packet_write_fmt(),\npacket_delim() and packet_flush().\n\nTo prepare for using write_command_and_capabilities() in\nget_remote_refs() and get_remote_bundle_uri() in following commits,\nlet's build the `ls-refs` and `bundle-uri` requests into a\n`struct strbuf` too, and send each of them with a single\nwrite_in_full().\n\nAs send_capabilities() is used for both of these requests, let's make\nit write into a `struct strbuf` instead of a file descriptor too.\n\nAs packet_buf_write() and packet_write_fmt() format packets in the\nsame way, the bytes sent on the wire are unchanged. If writing the\nrequest fails though, we now die with \"unable to write request to\nremote\", like for the `fetch` and `object-info` requests, instead of\nwith \"packet write with format failed\", or silently from SIGPIPE on\nEPIPE.\n\nSigned-off-by: Christian Couder <christian.couder@gmail.com>\n---\n connect.c | 47 +++++++++++++++++++++++++++++------------------\n 1 file changed, 29 insertions(+), 18 deletions(-)\n\ndiff --git a/connect.c b/connect.c\nindex 71d9e98a4b..1d923978ba 100644\n--- a/connect.c\n+++ b/connect.c\n@@ -501,7 +501,8 @@ void check_stateless_delimiter(int stateless_rpc,\n \t\tdie(\"%s\", error);\n }\n \n-static void send_capabilities(int fd_out, struct packet_reader *reader)\n+static void send_capabilities(struct strbuf *req_buf,\n+\t\t\t      struct packet_reader *reader)\n {\n \tconst char *hash_name;\n \tconst char *promisor_remote_info;\n@@ -510,17 +511,17 @@ static void send_capabilities(int fd_out, struct packet_reader *reader)\n \trepo_config_get_bool(the_repository, \"transfer.advertisesid\", &advertise_sid);\n \n \tif (server_supports_v2(\"agent\"))\n-\t\tpacket_write_fmt(fd_out, \"agent=%s\", git_user_agent_sanitized());\n+\t\tpacket_buf_write(req_buf, \"agent=%s\", git_user_agent_sanitized());\n \n \tif (advertise_sid && server_supports_v2(\"session-id\"))\n-\t\tpacket_write_fmt(fd_out, \"session-id=%s\", trace2_session_id());\n+\t\tpacket_buf_write(req_buf, \"session-id=%s\", trace2_session_id());\n \n \tif (server_feature_v2(\"object-format\", &hash_name)) {\n \t\tint hash_algo = hash_algo_by_name(hash_name);\n \t\tif (hash_algo == GIT_HASH_UNKNOWN)\n \t\t\tdie(_(\"unknown object format '%s' specified by server\"), hash_name);\n \t\treader->hash_algo = &hash_algos[hash_algo];\n-\t\tpacket_write_fmt(fd_out, \"object-format=%s\", reader->hash_algo->name);\n+\t\tpacket_buf_write(req_buf, \"object-format=%s\", reader->hash_algo->name);\n \t} else {\n \t\treader->hash_algo = &hash_algos[GIT_HASH_SHA1_LEGACY];\n \t}\n@@ -528,7 +529,7 @@ static void send_capabilities(int fd_out, struct packet_reader *reader)\n \t\tchar *reply;\n \t\tpromisor_remote_reply(promisor_remote_info, &reply);\n \t\tif (reply) {\n-\t\t\tpacket_write_fmt(fd_out, \"promisor-remote=%s\", reply);\n+\t\t\tpacket_buf_write(req_buf, \"promisor-remote=%s\", reply);\n \t\t\tfree(reply);\n \t\t}\n \t}\n@@ -537,19 +538,24 @@ static void send_capabilities(int fd_out, struct packet_reader *reader)\n int get_remote_bundle_uri(int fd_out, struct packet_reader *reader,\n \t\t\t  struct bundle_list *bundles, int stateless_rpc)\n {\n+\tstruct strbuf req_buf = STRBUF_INIT;\n \tint line_nr = 1, err = 0;\n \n \t/* Assert bundle-uri support */\n \tensure_server_supports_v2(\"bundle-uri\");\n \n \t/* (Re-)send capabilities */\n-\tsend_capabilities(fd_out, reader);\n+\tsend_capabilities(&req_buf, reader);\n \n \t/* Send command */\n-\tpacket_write_fmt(fd_out, \"command=bundle-uri\\n\");\n-\tpacket_delim(fd_out);\n+\tpacket_buf_write(&req_buf, \"command=bundle-uri\\n\");\n+\tpacket_buf_delim(&req_buf);\n \n-\tpacket_flush(fd_out);\n+\tpacket_buf_flush(&req_buf);\n+\n+\tif (write_in_full(fd_out, req_buf.buf, req_buf.len) < 0)\n+\t\tdie_errno(_(\"unable to write request to remote\"));\n+\tstrbuf_release(&req_buf);\n \n \t/* Process response from server */\n \twhile (packet_reader_read(reader) == PACKET_READ_NORMAL) {\n@@ -593,6 +599,7 @@ struct ref **get_remote_refs(int fd_out, struct packet_reader *reader,\n \t\t\t     int stateless_rpc)\n {\n \tsize_t i;\n+\tstruct strbuf req_buf = STRBUF_INIT;\n \tstruct strvec *ref_prefixes = transport_options ?\n \t\t&transport_options->ref_prefixes : NULL;\n \tconst char **unborn_head_target = transport_options ?\n@@ -600,30 +607,34 @@ struct ref **get_remote_refs(int fd_out, struct packet_reader *reader,\n \t*list = NULL;\n \n \tensure_server_supports_v2(\"ls-refs\");\n-\tpacket_write_fmt(fd_out, \"command=ls-refs\\n\");\n+\tpacket_buf_write(&req_buf, \"command=ls-refs\\n\");\n \n \t/* Send capabilities */\n-\tsend_capabilities(fd_out, reader);\n+\tsend_capabilities(&req_buf, reader);\n \n \tif (server_options && server_options->nr) {\n \t\tensure_server_supports_v2(\"server-option\");\n \t\tfor (i = 0; i < server_options->nr; i++)\n-\t\t\tpacket_write_fmt(fd_out, \"server-option=%s\",\n+\t\t\tpacket_buf_write(&req_buf, \"server-option=%s\",\n \t\t\t\t\t server_options->items[i].string);\n \t}\n \n-\tpacket_delim(fd_out);\n+\tpacket_buf_delim(&req_buf);\n \t/* When pushing we don't want to request the peeled tags */\n \tif (!for_push)\n-\t\tpacket_write_fmt(fd_out, \"peel\\n\");\n-\tpacket_write_fmt(fd_out, \"symrefs\\n\");\n+\t\tpacket_buf_write(&req_buf, \"peel\\n\");\n+\tpacket_buf_write(&req_buf, \"symrefs\\n\");\n \tif (server_supports_feature(\"ls-refs\", \"unborn\", 0))\n-\t\tpacket_write_fmt(fd_out, \"unborn\\n\");\n+\t\tpacket_buf_write(&req_buf, \"unborn\\n\");\n \tfor (i = 0; ref_prefixes && i < ref_prefixes->nr; i++) {\n-\t\tpacket_write_fmt(fd_out, \"ref-prefix %s\\n\",\n+\t\tpacket_buf_write(&req_buf, \"ref-prefix %s\\n\",\n \t\t\t\t ref_prefixes->v[i]);\n \t}\n-\tpacket_flush(fd_out);\n+\tpacket_buf_flush(&req_buf);\n+\n+\tif (write_in_full(fd_out, req_buf.buf, req_buf.len) < 0)\n+\t\tdie_errno(_(\"unable to write request to remote\"));\n+\tstrbuf_release(&req_buf);\n \n \t/* Process response from server */\n \twhile (packet_reader_read(reader) == PACKET_READ_NORMAL) {\n-- \n2.56.0\n\n\n"},{"id":"558969","messageId":"20261120164812.707946-15-christian.couder@gmail.com","threadId":"66840","inReplyTo":"20261120164812.707946-10-christian.couder@gmail.com","subject":"[PATCH v2 5/8] connect: use write_command_and_capabilities() in get_remote_refs()","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2026-11-20T16:48:18Z","receivedAt":"2026-11-20T16:48:18Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"As previous commits made write_command_and_capabilities() more generic,\nwe can now use that function in get_remote_refs() instead of\nsend_capabilities() and the open-coded \"server-option\" loop. Let's do\nthat then, which prepares for removing send_capabilities() in a\nfollowing commit.\n\nLet's also refactor writing the \"promisor-remote\" reply into a new\nadd_promisor_remote_reply() helper function. This duplicates code which\nis in send_capabilities() but we are going to remove that function in a\nfollowing commit. Let's declare this new helper in \"connect.h\" as it\nwill also be used in \"fetch-pack.c\" in a following commit.\n\nNote that the order of the `ls-refs` request lines changes. After\n\n  \"command, agent, [session-id]\"\n\nit used to be:\n\n  \"object-format, promisor-remote, server-option*\"\n\nbut now it is:\n\n  \"server-option*, promisor-remote, object-format\".\n\nThis should not affect the server's behavior as \"serve.c\" and JGit both\naccept capabilities in any order after \"command=...\".\n\nAlso note that \"command=ls-refs\" no longer ends with \"\\n\", which is\nharmless because the server chomps newlines.\n\nSigned-off-by: Christian Couder <christian.couder@gmail.com>\n---\n connect.c | 34 +++++++++++++++++++++-------------\n connect.h |  8 ++++++++\n 2 files changed, 29 insertions(+), 13 deletions(-)\n\ndiff --git a/connect.c b/connect.c\nindex 1d923978ba..9d5585f72b 100644\n--- a/connect.c\n+++ b/connect.c\n@@ -501,6 +501,21 @@ void check_stateless_delimiter(int stateless_rpc,\n \t\tdie(\"%s\", error);\n }\n \n+void add_promisor_remote_reply(struct strvec *capabilities)\n+{\n+\tconst char *promisor_remote_info;\n+\tchar *reply;\n+\n+\tif (!server_feature_v2(\"promisor-remote\", &promisor_remote_info))\n+\t\treturn;\n+\n+\tpromisor_remote_reply(promisor_remote_info, &reply);\n+\tif (reply) {\n+\t\tstrvec_pushf(capabilities, \"promisor-remote=%s\", reply);\n+\t\tfree(reply);\n+\t}\n+}\n+\n static void send_capabilities(struct strbuf *req_buf,\n \t\t\t      struct packet_reader *reader)\n {\n@@ -600,26 +615,18 @@ struct ref **get_remote_refs(int fd_out, struct packet_reader *reader,\n {\n \tsize_t i;\n \tstruct strbuf req_buf = STRBUF_INIT;\n+\tstruct strvec capabilities = STRVEC_INIT;\n \tstruct strvec *ref_prefixes = transport_options ?\n \t\t&transport_options->ref_prefixes : NULL;\n \tconst char **unborn_head_target = transport_options ?\n \t\t&transport_options->unborn_head_target : NULL;\n \t*list = NULL;\n \n-\tensure_server_supports_v2(\"ls-refs\");\n-\tpacket_buf_write(&req_buf, \"command=ls-refs\\n\");\n-\n-\t/* Send capabilities */\n-\tsend_capabilities(&req_buf, reader);\n-\n-\tif (server_options && server_options->nr) {\n-\t\tensure_server_supports_v2(\"server-option\");\n-\t\tfor (i = 0; i < server_options->nr; i++)\n-\t\t\tpacket_buf_write(&req_buf, \"server-option=%s\",\n-\t\t\t\t\t server_options->items[i].string);\n-\t}\n+\tadd_server_options(&capabilities, server_options);\n+\tadd_promisor_remote_reply(&capabilities);\n+\twrite_command_and_capabilities(&req_buf, \"ls-refs\",\n+\t\t\t\t       &capabilities, reader);\n \n-\tpacket_buf_delim(&req_buf);\n \t/* When pushing we don't want to request the peeled tags */\n \tif (!for_push)\n \t\tpacket_buf_write(&req_buf, \"peel\\n\");\n@@ -634,6 +641,7 @@ struct ref **get_remote_refs(int fd_out, struct packet_reader *reader,\n \n \tif (write_in_full(fd_out, req_buf.buf, req_buf.len) < 0)\n \t\tdie_errno(_(\"unable to write request to remote\"));\n+\tstrvec_clear(&capabilities);\n \tstrbuf_release(&req_buf);\n \n \t/* Process response from server */\ndiff --git a/connect.h b/connect.h\nindex cff987ae38..00afc8c95a 100644\n--- a/connect.h\n+++ b/connect.h\n@@ -44,6 +44,14 @@ struct strvec;\n void add_server_options(struct strvec *capabilities,\n \t\t\tconst struct string_list *server_options);\n \n+/*\n+ * If the server advertised the \"promisor-remote\" capability, compute\n+ * our reply, which also marks the accepted promisor remotes, and\n+ * append \"promisor-remote=<reply>\" to `capabilities` if any remote\n+ * was accepted.\n+ */\n+void add_promisor_remote_reply(struct strvec *capabilities);\n+\n /*\n  * Write a protocol v2 command request, along with the capability\n  * advertisements, into req_buf. The \"agent\", \"session-id\" and\n-- \n2.56.0\n\n\n"},{"id":"558970","messageId":"20261120164812.707946-16-christian.couder@gmail.com","threadId":"66840","inReplyTo":"20261120164812.707946-10-christian.couder@gmail.com","subject":"[PATCH v2 6/8] connect: use write_command_and_capabilities() in get_remote_bundle_uri()","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2026-11-20T16:48:19Z","receivedAt":"2026-11-20T16:48:19Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Now that previous commits made write_command_and_capabilities() more\ngeneric, we can use that function in get_remote_bundle_uri() instead of\nsend_capabilities().\n\nLet's do that then, and let's remove send_capabilities() while at it,\nas it no longer has any caller.\n\nAs before, no \"server-option\" capability is sent with the `bundle-uri`\nrequest.\n\nNote that now \"command=bundle-uri\" comes first on the wire instead of\nlast, and \"promisor-remote\" now comes before \"object-format\", but this\nshould not be an issue as \"serve.c\" accepts capabilities and\n\"command=...\" in any order, and JGit doesn't implement \"bundle-uri\".\n\nAlso note that \"command=bundle-uri\" no longer ends with \"\\n\", which is\nharmless because the server chomps newlines.\n\nSigned-off-by: Christian Couder <christian.couder@gmail.com>\n---\n connect.c | 49 +++++--------------------------------------------\n 1 file changed, 5 insertions(+), 44 deletions(-)\n\ndiff --git a/connect.c b/connect.c\nindex 9d5585f72b..3d0afb2d27 100644\n--- a/connect.c\n+++ b/connect.c\n@@ -516,60 +516,21 @@ void add_promisor_remote_reply(struct strvec *capabilities)\n \t}\n }\n \n-static void send_capabilities(struct strbuf *req_buf,\n-\t\t\t      struct packet_reader *reader)\n-{\n-\tconst char *hash_name;\n-\tconst char *promisor_remote_info;\n-\tint advertise_sid = 0;\n-\n-\trepo_config_get_bool(the_repository, \"transfer.advertisesid\", &advertise_sid);\n-\n-\tif (server_supports_v2(\"agent\"))\n-\t\tpacket_buf_write(req_buf, \"agent=%s\", git_user_agent_sanitized());\n-\n-\tif (advertise_sid && server_supports_v2(\"session-id\"))\n-\t\tpacket_buf_write(req_buf, \"session-id=%s\", trace2_session_id());\n-\n-\tif (server_feature_v2(\"object-format\", &hash_name)) {\n-\t\tint hash_algo = hash_algo_by_name(hash_name);\n-\t\tif (hash_algo == GIT_HASH_UNKNOWN)\n-\t\t\tdie(_(\"unknown object format '%s' specified by server\"), hash_name);\n-\t\treader->hash_algo = &hash_algos[hash_algo];\n-\t\tpacket_buf_write(req_buf, \"object-format=%s\", reader->hash_algo->name);\n-\t} else {\n-\t\treader->hash_algo = &hash_algos[GIT_HASH_SHA1_LEGACY];\n-\t}\n-\tif (server_feature_v2(\"promisor-remote\", &promisor_remote_info)) {\n-\t\tchar *reply;\n-\t\tpromisor_remote_reply(promisor_remote_info, &reply);\n-\t\tif (reply) {\n-\t\t\tpacket_buf_write(req_buf, \"promisor-remote=%s\", reply);\n-\t\t\tfree(reply);\n-\t\t}\n-\t}\n-}\n-\n int get_remote_bundle_uri(int fd_out, struct packet_reader *reader,\n \t\t\t  struct bundle_list *bundles, int stateless_rpc)\n {\n \tstruct strbuf req_buf = STRBUF_INIT;\n+\tstruct strvec capabilities = STRVEC_INIT;\n \tint line_nr = 1, err = 0;\n \n-\t/* Assert bundle-uri support */\n-\tensure_server_supports_v2(\"bundle-uri\");\n-\n-\t/* (Re-)send capabilities */\n-\tsend_capabilities(&req_buf, reader);\n-\n-\t/* Send command */\n-\tpacket_buf_write(&req_buf, \"command=bundle-uri\\n\");\n-\tpacket_buf_delim(&req_buf);\n-\n+\tadd_promisor_remote_reply(&capabilities);\n+\twrite_command_and_capabilities(&req_buf, \"bundle-uri\",\n+\t\t\t\t       &capabilities, reader);\n \tpacket_buf_flush(&req_buf);\n \n \tif (write_in_full(fd_out, req_buf.buf, req_buf.len) < 0)\n \t\tdie_errno(_(\"unable to write request to remote\"));\n+\tstrvec_clear(&capabilities);\n \tstrbuf_release(&req_buf);\n \n \t/* Process response from server */\n-- \n2.56.0\n\n\n"},{"id":"558971","messageId":"20261120164812.707946-17-christian.couder@gmail.com","threadId":"66840","inReplyTo":"20261120164812.707946-10-christian.couder@gmail.com","subject":"[PATCH v2 7/8] fetch-pack: ensure fetch sends a promisor-remote reply","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2026-11-20T16:48:20Z","receivedAt":"2026-11-20T16:48:20Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"In protocol v2, when the client accepts promisor remotes, the\n`promisor-remote=...` reply is only sent with the `ls-refs` and\n`bundle-uri` protocol commands, by get_remote_refs() and\nget_remote_bundle_uri() in \"connect.c\".\n\nThe request for the `fetch` protocol command is built by\nsend_fetch_request() in \"fetch-pack.c\" which doesn't send that reply.\ndo_fetch_pack_v2() calls promisor_remote_reply(), but only to mark the\naccepted remotes, as e15a6b2f8b (promisor-remote: change\npromisor_remote_reply()'s signature, 2026-02-16) assumed that\nfetch-pack would not need to send a reply.\n\nWith file:// and ssh:// URLs on a Git server, one upload-pack process\nhandles both `ls-refs` and `fetch`. The acceptance recorded during\n`ls-refs` by promisor_remote_receive() in \"serve.c\" is still there at\n`fetch` time, so the clone succeeds. But it fails when each request is\nhandled on its own, for example with HTTP where different upload-pack\nprocesses are used.\n\nIt also fails when only object IDs are fetched, as no `ls-refs`\ncommand is then sent. In these cases, the server doesn't know that the\nclient accepted a promisor remote, so it doesn't allow promisor\nobjects to be missing from the pack it sends, and it fails with \"could\nnot fetch <oid> from promisor remote\".\n\nLet's fix that by building the list of capabilities for the `fetch`\nrequests once in do_fetch_pack_v2(), using add_server_options() and\nadd_promisor_remote_reply(), and by passing that list to\nsend_fetch_request(). This way the `promisor-remote=...` reply is\nalways properly sent with the `fetch` requests, and the accepted\nremotes are still marked at the same point as before.\n\nThe `fetch` requests sent by negotiate_using_fetch() don't ask for a\npack, so they don't need that reply.\n\nLet's also add tests in t5710 to check that the reply is sent with the\n`fetch` request, and that fetching only an object ID works. For HTTP,\nlet's add a new t5711 test script, copying the setup from t5710.\n\nReported-by: Matt Cote <mcote@nvidia.com>\nSigned-off-by: Christian Couder <christian.couder@gmail.com>\n---\n fetch-pack.c                               |  18 +--\n t/meson.build                              |   1 +\n t/t5710-promisor-remote-capability.sh      |  40 +++++++\n t/t5711-promisor-remote-capability-http.sh | 126 +++++++++++++++++++++\n 4 files changed, 176 insertions(+), 9 deletions(-)\n create mode 100755 t/t5711-promisor-remote-capability-http.sh\n\ndiff --git a/fetch-pack.c b/fetch-pack.c\nindex 176d625936..3d6d3e33a2 100644\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -1380,16 +1380,15 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,\n \t\t\t      const struct ref *wants, struct oidset *common,\n \t\t\t      int *haves_to_send, int *in_vain,\n \t\t\t      int sideband_all, int seen_ack,\n-\t\t\t      struct oidset *negotiation_include_oids)\n+\t\t\t      struct oidset *negotiation_include_oids,\n+\t\t\t      const struct strvec *capabilities)\n {\n \tint haves_added;\n \tint done_sent = 0;\n \tstruct strbuf req_buf = STRBUF_INIT;\n-\tstruct strvec capabilities = STRVEC_INIT;\n \n-\tadd_server_options(&capabilities, args->server_options);\n \twrite_command_and_capabilities(&req_buf, \"fetch\",\n-\t\t\t\t       &capabilities, NULL);\n+\t\t\t\t       capabilities, NULL);\n \n \tif (args->use_thin_pack)\n \t\tpacket_buf_write(&req_buf, \"thin-pack\");\n@@ -1454,7 +1453,6 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,\n \tif (write_in_full(fd_out, req_buf.buf, req_buf.len) < 0)\n \t\tdie_errno(_(\"unable to write request to remote\"));\n \n-\tstrvec_clear(&capabilities);\n \tstrbuf_release(&req_buf);\n \treturn done_sent;\n }\n@@ -1698,12 +1696,12 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,\n \tstruct string_list packfile_uris = STRING_LIST_INIT_DUP;\n \tint i;\n \tstruct strvec index_pack_args = STRVEC_INIT;\n-\tconst char *promisor_remote_config;\n+\tstruct strvec capabilities = STRVEC_INIT;\n \n \tfsck_options_init(&fsck_options, the_repository, FSCK_OPTIONS_MISSING_GITMODULES);\n \n-\tif (server_feature_v2(\"promisor-remote\", &promisor_remote_config))\n-\t\tpromisor_remote_reply(promisor_remote_config, NULL);\n+\tadd_server_options(&capabilities, args->server_options);\n+\tadd_promisor_remote_reply(&capabilities);\n \n \tif (args->filter_options.choice == LOFC_AUTO) {\n \t\tstruct strbuf errbuf = STRBUF_INIT;\n@@ -1781,7 +1779,8 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,\n \t\t\t\t\t       &haves_to_send, &in_vain,\n \t\t\t\t\t       reader.use_sideband,\n \t\t\t\t\t       seen_ack,\n-\t\t\t\t\t       &negotiation_include_oids)) {\n+\t\t\t\t\t       &negotiation_include_oids,\n+\t\t\t\t\t       &capabilities)) {\n \t\t\t\ttrace2_region_leave_printf(\"negotiation_v2\", \"round\",\n \t\t\t\t\t\t\t   the_repository, \"%d\",\n \t\t\t\t\t\t\t   negotiation_round);\n@@ -1924,6 +1923,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,\n \n \tstring_list_clear(&packfile_uris, 0);\n \tstrvec_clear(&index_pack_args);\n+\tstrvec_clear(&capabilities);\n \n \tif (fsck_finish(&fsck_options))\n \t\tdie(\"fsck failed\");\ndiff --git a/t/meson.build b/t/meson.build\nindex 1cf1d95f70..84644703f1 100644\n--- a/t/meson.build\n+++ b/t/meson.build\n@@ -766,6 +766,7 @@ integration_tests = [\n   't5704-protocol-violations.sh',\n   't5705-session-id-in-capabilities.sh',\n   't5710-promisor-remote-capability.sh',\n+  't5711-promisor-remote-capability-http.sh',\n   't5730-protocol-v2-bundle-uri-file.sh',\n   't5731-protocol-v2-bundle-uri-git.sh',\n   't5732-protocol-v2-bundle-uri-http.sh',\ndiff --git a/t/t5710-promisor-remote-capability.sh b/t/t5710-promisor-remote-capability.sh\nindex 463e9e00b0..e5d6f9d1c6 100755\n--- a/t/t5710-promisor-remote-capability.sh\n+++ b/t/t5710-promisor-remote-capability.sh\n@@ -999,6 +999,46 @@ test_expect_success \"clone and fetch with --filter=auto\" '\n \tcheck_missing_objects server 1 \"$oid\"\n '\n \n+test_expect_success \"clone sends the promisor-remote reply with fetch\" '\n+\tgit -C server config promisor.advertise true &&\n+\ttest_when_finished \"rm -rf client trace\" &&\n+\n+\tGIT_TRACE_PACKET=\"$(pwd)/trace\" git clone \\\n+\t\t-c remote.lop.promisor=true \\\n+\t\t-c remote.lop.url=\"$TRASH_DIRECTORY_URL/lop\" \\\n+\t\t-c promisor.acceptfromserver=All \\\n+\t\t--no-local --filter=\"blob:limit=5k\" server client &&\n+\n+\t# Check that the reply is part of the fetch request\n+\tsed -n \"/clone> command=fetch/,/clone> 0001/p\" trace >request &&\n+\ttest_grep \"clone> promisor-remote=lop\" request &&\n+\n+\t# Check that the largest object is still missing on the server\n+\tcheck_missing_objects server 1 \"$oid\"\n+'\n+\n+test_expect_success \"fetch by object ID sends the promisor-remote reply\" '\n+\tgit -C server config promisor.advertise true &&\n+\ttest_when_finished \"rm -rf client trace\" &&\n+\n+\tgit init client &&\n+\tgit -C client remote add origin \"$TRASH_DIRECTORY_URL/server\" &&\n+\tgit -C client config remote.lop.promisor true &&\n+\tgit -C client config remote.lop.url \"$TRASH_DIRECTORY_URL/lop\" &&\n+\tgit -C client config promisor.acceptfromserver All &&\n+\n+\t# Fetching only an object ID skips the \"ls-refs\" command, so the\n+\t# reply can only be sent with \"fetch\"\n+\thead=$(git -C server rev-parse HEAD) &&\n+\tGIT_TRACE_PACKET=\"$(pwd)/trace\" git -C client fetch --no-tags \\\n+\t\t--filter=\"blob:limit=5k\" origin \"$head\" &&\n+\ttest_grep ! \"fetch> command=ls-refs\" trace &&\n+\ttest_grep \"fetch> promisor-remote=lop\" trace &&\n+\n+\t# Check that the largest object is still missing on the server\n+\tcheck_missing_objects server 1 \"$oid\"\n+'\n+\n test_expect_success \"clone with promisor.advertise set to 'true' but don't delete the client\" '\n \tgit -C server config promisor.advertise true &&\n \ndiff --git a/t/t5711-promisor-remote-capability-http.sh b/t/t5711-promisor-remote-capability-http.sh\nnew file mode 100755\nindex 0000000000..c08cca3e51\n--- /dev/null\n+++ b/t/t5711-promisor-remote-capability-http.sh\n@@ -0,0 +1,126 @@\n+#!/bin/sh\n+\n+test_description='handling of promisor remote advertisement over HTTP'\n+\n+. ./test-lib.sh\n+\n+if ! test_have_prereq PERL_TEST_HELPERS\n+then\n+\tskip_all='skipping promisor remote capabilities tests; Perl not available'\n+\ttest_done\n+fi\n+\n+. \"$TEST_DIRECTORY\"/lib-httpd.sh\n+start_httpd\n+\n+GIT_TEST_MULTI_PACK_INDEX=0\n+GIT_TEST_MULTI_PACK_INDEX_WRITE_INCREMENTAL=0\n+\n+# The setup and helpers below are copied from t5710, except that the\n+# server repository is in the HTTP document root.\n+\n+SERVER=\"$HTTPD_DOCUMENT_ROOT_PATH/server.git\"\n+\n+check_missing_objects () {\n+\tgit -C \"$1\" rev-list --objects --all --missing=print > all.txt &&\n+\tperl -ne 'print if s/^[?]//' all.txt >missing.txt &&\n+\ttest_line_count = \"$2\" missing.txt &&\n+\ttest \"$3\" = \"$(cat missing.txt)\"\n+}\n+\n+initialize_server () {\n+\t# Repack everything first\n+\tgit -C \"$SERVER\" -c repack.writebitmaps=false repack -a -d &&\n+\n+\t# Repack without the largest object and create a promisor pack on server\n+\tgit -C \"$SERVER\" -c repack.writebitmaps=false repack -a -d \\\n+\t    --filter=blob:limit=5k --filter-to=\"$(pwd)/pack\" &&\n+\tpromisor_file=$(ls \"$SERVER\"/objects/pack/*.pack | sed \"s/\\.pack/.promisor/\") &&\n+\t>\"$promisor_file\" &&\n+\n+\t# Check objects missing on the server\n+\tcheck_missing_objects \"$SERVER\" 1 \"$1\"\n+}\n+\n+copy_to_lop () {\n+\toid_path=\"$(test_oid_to_path $1)\" &&\n+\tpath=\"$SERVER/objects/$oid_path\" &&\n+\tpath2=\"lop/objects/$oid_path\" &&\n+\tmkdir -p $(dirname \"$path2\") &&\n+\tcp \"$path\" \"$path2\"\n+}\n+\n+# On Windows, `pwd` returns a path like 'D:/foo/bar'. Prepend '/' to turn\n+# it into '/D:/foo/bar', which is what git expects in file:// URLs on Windows.\n+# On Unix, the path already starts with '/', so this is a no-op.\n+pwd_path=$(pwd)\n+case \"$pwd_path\" in\n+[a-zA-Z]:*) pwd_path=\"/$pwd_path\" ;;\n+esac\n+\n+TRASH_DIRECTORY_URL=\"file://$pwd_path\"\n+\n+test_expect_success 'setup: create \"template\" repository' '\n+\tgit init template &&\n+\ttest_commit -C template 1 &&\n+\ttest_commit -C template 2 &&\n+\ttest_commit -C template 3 &&\n+\ttest-tool genrandom foo 10k >template/foo &&\n+\tgit -C template add foo &&\n+\tgit -C template commit -m foo\n+'\n+\n+# A bare repo will act as a server repo with unpacked objects.\n+test_expect_success 'setup: create bare \"server\" repository' '\n+\tgit clone --bare --no-local template \"$SERVER\" &&\n+\tmv \"$SERVER\"/objects/pack/pack-* . &&\n+\tpackfile=$(ls pack-*.pack) &&\n+\tgit -C \"$SERVER\" unpack-objects --strict <\"$packfile\"\n+'\n+\n+test_expect_success \"setup for testing promisor remote advertisement\" '\n+\t# Create another bare repo called \"lop\" (for Large Object Promisor)\n+\tgit init --bare lop &&\n+\n+\t# Copy the largest object from server to lop\n+\tobj=\"HEAD:foo\" &&\n+\toid=\"$(git -C \"$SERVER\" rev-parse $obj)\" &&\n+\tcopy_to_lop \"$oid\" &&\n+\n+\tinitialize_server \"$oid\" &&\n+\n+\t# Configure lop as promisor remote for server\n+\tgit -C \"$SERVER\" remote add lop \"$TRASH_DIRECTORY_URL/lop\" &&\n+\tgit -C \"$SERVER\" config remote.lop.promisor true &&\n+\n+\tgit -C lop config uploadpack.allowFilter true &&\n+\tgit -C lop config uploadpack.allowAnySHA1InWant true &&\n+\tgit -C \"$SERVER\" config uploadpack.allowFilter true &&\n+\tgit -C \"$SERVER\" config uploadpack.allowAnySHA1InWant true &&\n+\tgit -C \"$SERVER\" config promisor.advertise true\n+'\n+\n+# Over HTTP, each request is handled by a separate upload-pack process,\n+# so the server knows that the client accepted \"lop\" only if the reply\n+# is sent with the \"fetch\" request itself.\n+test_expect_success \"clone over HTTP with an accepted promisor remote\" '\n+\ttest_when_finished \"rm -rf client trace\" &&\n+\n+\tGIT_TRACE_PACKET=\"$(pwd)/trace\" git -c protocol.version=2 clone \\\n+\t\t-c remote.lop.promisor=true \\\n+\t\t-c remote.lop.url=\"$TRASH_DIRECTORY_URL/lop\" \\\n+\t\t-c promisor.acceptfromserver=All \\\n+\t\t--filter=\"blob:limit=5k\" \"$HTTPD_URL/smart/server.git\" client &&\n+\n+\t# Check that the reply is part of the fetch request\n+\tsed -n \"/clone> command=fetch/,/clone> 0001/p\" trace >request &&\n+\ttest_grep \"clone> promisor-remote=lop\" request &&\n+\n+\t# Check that the largest object was lazily fetched from lop\n+\ttest_cmp template/foo client/foo &&\n+\n+\t# Check that the largest object is still missing on the server\n+\tcheck_missing_objects \"$SERVER\" 1 \"$oid\"\n+'\n+\n+test_done\n-- \n2.56.0\n\n\n"},{"id":"558972","messageId":"20261120164812.707946-18-christian.couder@gmail.com","threadId":"66840","inReplyTo":"20261120164812.707946-10-christian.couder@gmail.com","subject":"[PATCH v2 8/8] doc: gitprotocol-v2: send the promisor-remote reply with fetch","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2026-11-20T16:48:21Z","receivedAt":"2026-11-20T16:48:21Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Until a previous commit, a client sent its `promisor-remote=...` reply\nonly with the `ls-refs` and `bundle-uri` protocol commands.\n\nLet's clearly document that the client should send that reply with each\n`fetch` command request asking for a pack too, as protocol v2 is\nstateless.\n\nThe `fetch` requests sent only for negotiation, like with `git fetch\n--negotiate-only`, don't ask for a pack, so they don't need that reply.\n\nReported-by: Matt Cote <mcote@nvidia.com>\nSigned-off-by: Christian Couder <christian.couder@gmail.com>\n---\n Documentation/gitprotocol-v2.adoc | 7 +++++++\n 1 file changed, 7 insertions(+)\n\ndiff --git a/Documentation/gitprotocol-v2.adoc b/Documentation/gitprotocol-v2.adoc\nindex dd52fd8110..d70d7ab19b 100644\n--- a/Documentation/gitprotocol-v2.adoc\n+++ b/Documentation/gitprotocol-v2.adoc\n@@ -879,6 +879,13 @@ In this case, or if the client doesn't want to use any promisor remote\n the server advertised, the client shouldn't advertise the\n \"promisor-remote\" capability at all in its reply.\n \n+As protocol v2 is stateless (see the \"Capabilities\" section above),\n+the client should send this reply with each `fetch` command request\n+asking for a pack, even if it has already sent it with an earlier\n+command request, like `ls-refs` or `bundle-uri`. Note that when only\n+some object IDs are fetched, the client might not send any `ls-refs`\n+command request at all.\n+\n On the server side, the \"promisor.advertise\" and \"promisor.sendFields\"\n configuration options can be used to control what it advertises. On\n the client side, the \"promisor.acceptFromServer\" and\n-- \n2.56.0\n\n\n"},{"id":"558975","messageId":"CAP8UFD1ZDzDvYxF1TjTjBo0SFHfwPdpRrgixRQXN72RxpoJOxw@mail.gmail.com","threadId":"66840","inReplyTo":"xmqqh5hkbl6t.fsf@gitster.g","subject":"Re: [PATCH 1/3] connect: let write_command_and_capabilities() send a promisor-remote reply","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2026-11-20T16:57:43Z","receivedAt":"2026-11-20T16:57:43Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Fri, Nov 13, 2026 at 8:11 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Christian Couder <christian.couder@gmail.com> writes:\n>\n> > They duplicate code for sending \"server-option\", \"agent\" and\n> > \"object-format\", while each sends a different set of capabilities.\n>\n> That is all the more reason to clean them up before we pile more\n> stuff on top, no?\n>\n> I do not know if that deserves to be called \"significant\"\n> refactoring, though.  It would not take a series with 20 patches\n> each of which weigh more than 30 lines touched, no?\n\nAs you can see in the v2 I just sent, it took 6 refactoring patches\ninstead of 1.\n\nThe diffstat is now:\n\n Documentation/gitprotocol-v2.adoc          |   7 ++\n connect.c                                  | 128 ++++++++++++---------\n connect.h                                  |  30 ++++-\n fetch-object-info.c                        |   7 +-\n fetch-pack.c                               |  23 ++--\n t/meson.build                              |   1 +\n t/t5705-session-id-in-capabilities.sh      |  26 +++++\n t/t5710-promisor-remote-capability.sh      |  40 +++++++\n t/t5711-promisor-remote-capability-http.sh | 126 ++++++++++++++++++++\n 9 files changed, 322 insertions(+), 66 deletions(-)\n create mode 100755 t/t5711-promisor-remote-capability-http.sh\n\ninstead of:\n\n Documentation/gitprotocol-v2.adoc          |   6 +\n connect.c                                  |   6 +-\n connect.h                                  |   6 +-\n fetch-object-info.c                        |   3 +-\n fetch-pack.c                               |  17 ++-\n t/meson.build                              |   1 +\n t/t5710-promisor-remote-capability.sh      |  40 +++++++\n t/t5711-promisor-remote-capability-http.sh | 126 +++++++++++++++++++++\n 8 files changed, 196 insertions(+), 9 deletions(-)\n create mode 100755 t/t5711-promisor-remote-capability-http.sh\n\nThanks.\n\n"}]}