{"thread":{"id":"66885","subject":"[PATCH] connect: clear v2 server capabilities on handshake","startedAt":"2026-11-19T19:22:57Z","lastAt":"2026-11-19T19:22:57Z","messageCount":1,"participants":["Dominik Maier"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"558878","messageId":"20261119192257.2679418-1-dmnk@google.com","threadId":"66885","inReplyTo":null,"subject":"[PATCH] connect: clear v2 server capabilities on handshake","fromName":"Dominik Maier","fromEmail":"dmnk@google.com","sentAt":"2026-11-19T19:22:57Z","receivedAt":"2026-11-19T19:22:57Z","isPatch":true,"sender":{"key":"dmnk@google.com","avatar":null},"body":"process_capabilities_v2() appends capability lines onto the file-static\nserver_capabilities_v2 vector without clearing entries recorded during\nearlier handshakes in the same process. Because server_feature_v2() and\nserver_supports_feature() return the first matching entry in\nserver_capabilities_v2, capabilities advertised by an earlier remote\nbleed into subsequent connections (including v0/v1 handshakes that skip\nprocess_capabilities_v2() before callers such as get_bundle_uri() query\nserver_supports_v2(\"bundle-uri\")).\n\nFor example, running \"git remote show r1 r2\" when r1 uses SHA-256 and r2\nuses SHA-1 causes the second handshake to read r1's stale\n\"object-format=sha256\" capability and fail with \"mismatched object\nformat\", and a stale \"session-id\" from r1 is logged again for r2 even\nwhen r2 disables transfer.advertiseSID.\n\nClear server_capabilities_v2 in discover_version() and\nprocess_capabilities_v2().\n\nSigned-off-by: Dominik Maier <dmnk@google.com>\n---\n connect.c              |  3 +++\n t/t5702-protocol-v2.sh | 23 +++++++++++++++++++++++\n 2 files changed, 26 insertions(+)\n\ndiff --git a/connect.c b/connect.c\nindex 87d2e8bccd..b620cf2286 100644\n--- a/connect.c\n+++ b/connect.c\n@@ -133,6 +133,7 @@ int server_supports_feature(const char *c, const char *feature,\n \n static void process_capabilities_v2(struct packet_reader *reader)\n {\n+\tstrvec_clear(&server_capabilities_v2);\n \twhile (packet_reader_read(reader) == PACKET_READ_NORMAL)\n \t\tstrvec_push(&server_capabilities_v2, reader->line);\n \n@@ -144,6 +145,8 @@ enum protocol_version discover_version(struct packet_reader *reader)\n {\n \tenum protocol_version version = protocol_unknown_version;\n \n+\tstrvec_clear(&server_capabilities_v2);\n+\n \t/*\n \t * Peek the first line of the server's response to\n \t * determine the protocol version the server is speaking.\ndiff --git a/t/t5702-protocol-v2.sh b/t/t5702-protocol-v2.sh\nindex e5e73eb407..3716e43bb1 100755\n--- a/t/t5702-protocol-v2.sh\n+++ b/t/t5702-protocol-v2.sh\n@@ -548,6 +548,29 @@ test_expect_success 'invalid server-option configuration' '\n \ttest_grep \"error: missing value for '\\''remote.origin.serveroption'\\''\" err\n '\n \n+test_expect_success 'v2 server capabilities do not bleed across in-process handshakes' '\n+\ttest_when_finished \"rm -rf cap_r1 cap_r2 cap_client trace2_caps\" &&\n+\tgit init --object-format=sha256 cap_r1 &&\n+\ttest_commit -C cap_r1 one &&\n+\tgit -C cap_r1 config transfer.advertiseSID true &&\n+\n+\tgit init --object-format=sha1 cap_r2 &&\n+\ttest_commit -C cap_r2 two &&\n+\tgit -C cap_r2 config transfer.advertiseSID false &&\n+\n+\tgit init --object-format=sha1 cap_client &&\n+\tgit -C cap_client remote add r1 \"file://$(pwd)/cap_r1\" &&\n+\tgit -C cap_client remote add r2 \"file://$(pwd)/cap_r2\" &&\n+\n+\tGIT_TRACE2_EVENT=\"$(pwd)/trace2_caps\" \\\n+\t\tgit -C cap_client -c protocol.version=2 -c transfer.advertiseSID=true \\\n+\t\tremote show r1 r2 >out &&\n+\ttest_grep \"\\* remote r2\" out &&\n+\tgrep \"\\\"category\\\":\\\"transfer\\\",\\\"key\\\":\\\"server-sid\\\"\" trace2_caps >sids &&\n+\t# Only r1 advertised session-id; r2 must not inherit it\n+\ttest_line_count = 1 sids\n+'\n+\n test_expect_success 'upload-pack respects config using protocol v2' '\n \tgit init server &&\n \twrite_script server/.git/hook <<-\\EOF &&\n-- \n2.56.1.750.gf70dc682cf-goog\n\n\n"}]}