[PATCH v2 2/8] connect: send session-id with ls-refs and bundle-uri
- From
Christian Couder <christian.couder@gmail.com>
- Date
- Nov 20, 2026, 16:48 UTC
- Message-ID
- <20261120164812.707946-12-christian.couder@gmail.com>
- In-Reply-To
- <20261120164812.707946-10-christian.couder@gmail.com>
1e905bbc00 (fetch-pack: advertise session ID in capabilities, 2020-11-11) only added session-id to fetch-pack and doesn't say why it was left out elsewhere. According to our "gitprotocol-v2.adoc" documentation, the goal of session IDs is to identify the process across multiple requests, so there is no reason to not send it with every request.
Let's then also send session-id in the `ls-refs` and `bundle-uri` requests which go through send_capabilities().
Note that this only changes behavior when `transfer.advertiseSID` is set, which is not the default.
Also note that over file:// and ssh:// one upload-pack process handles both `ls-refs` and `fetch`, so the server now logs the client's session-id twice per process, but this is harmless.
Let's add tests in t5705 to check that the server receives the client's session-id when only `ls-refs` is sent (with `git ls-remote`) and when only `bundle-uri` is sent (with `test-tool bundle-uri ls-remote`), as the existing tests there only use `fetch`, which already sent it.
Signed-off-by: Christian Couder <christian.couder@gmail.com> --- connect.c | 6 ++++++ t/t5705-session-id-in-capabilities.sh | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+)
diff --git a/connect.c b/connect.c index 5f73fd9e7e..40cd279290 100644 --- a/connect.c +++ b/connect.c @@ -505,10 +505,16 @@ static void send_capabilities(int fd_out, struct packet_reader *reader) { const char *hash_name; const char *promisor_remote_info; + int advertise_sid = 0; + + repo_config_get_bool(the_repository, "transfer.advertisesid", &advertise_sid); if (server_supports_v2("agent")) packet_write_fmt(fd_out, "agent=%s", git_user_agent_sanitized()); + if (advertise_sid && server_supports_v2("session-id")) + packet_write_fmt(fd_out, "session-id=%s", trace2_session_id()); + if (server_feature_v2("object-format", &hash_name)) { int hash_algo = hash_algo_by_name(hash_name); if (hash_algo == GIT_HASH_UNKNOWN) diff --git a/t/t5705-session-id-in-capabilities.sh b/t/t5705-session-id-in-capabilities.sh index ef0db57d1f..9b35c62629 100755 --- a/t/t5705-session-id-in-capabilities.sh +++ b/t/t5705-session-id-in-capabilities.sh @@ -84,4 +84,30 @@ do ' done +test_expect_success 'session IDs advertised (ls-remote v2)' ' + test_when_finished "rm -rf local tr2-server-events" && + cp -r "$LOCAL_PRISTINE" local && + git -c protocol.version=2 -C local ls-remote \ + --upload-pack "GIT_TRACE2_EVENT=\"$(pwd)/tr2-server-events\" git-upload-pack" \ + origin && + test_grep \"key\":\"client-sid\" tr2-server-events +' + +test_expect_success 'session IDs advertised (bundle-uri v2)' ' + test_when_finished "rm -f trace tr2-events" && + test_config -C "$REPO" uploadpack.advertiseBundleURIs true && + test_config_global transfer.advertiseSID true && + test_config_global transfer.bundleURI true && + + # Only the server logs "client-sid", so the client and the + # server can share the same trace2 event file. + GIT_TRACE_PACKET="$(pwd)/trace" GIT_TRACE2_EVENT="$(pwd)/tr2-events" \ + test-tool bundle-uri ls-remote "file://$REPO" && + + # Only the "bundle-uri" command is sent + test_grep "> command=bundle-uri" trace && + test_grep ! "> command=ls-refs" trace && + test_grep \"key\":\"client-sid\" tr2-events +' + test_done
-- 2.56.0