Git development
 help / color / mirror / Atom feed
From: Christian Couder <christian.couder@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
	Patrick Steinhardt <ps@pks.im>, Matt Cote <mcote@nvidia.com>,
	Christian Couder <christian.couder@gmail.com>
Subject: [PATCH v2 2/8] connect: send session-id with ls-refs and bundle-uri
Date: Fri, 20 Nov 2026 17:48:15 +0100	[thread overview]
Message-ID: <20261120164812.707946-12-christian.couder@gmail.com> (raw)
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


  parent reply	other threads:[~2026-11-20 16:48 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 19:58 [PATCH 0/3] Fix promisor-remote reply missing from fetch Christian Couder
2026-11-12 19:59 ` [PATCH 1/3] connect: let write_command_and_capabilities() send a promisor-remote reply Christian Couder
2026-11-12 22:18   ` Junio C Hamano
2026-11-12 22:34     ` Junio C Hamano
2026-11-13 13:10       ` Christian Couder
2026-11-13 19:11         ` Junio C Hamano
2026-11-20 16:57           ` Christian Couder
2026-11-12 19:59 ` [PATCH 2/3] fetch-pack: ensure fetch sends " Christian Couder
2026-11-12 19:59 ` [PATCH 3/3] doc: gitprotocol-v2: send the promisor-remote reply with fetch Christian Couder
2026-11-20 16:48 ` [PATCH v2 0/8] Fix promisor-remote reply missing from fetch Christian Couder
2026-11-20 16:48   ` [PATCH v2 1/8] connect: pass capability lines to write_command_and_capabilities() Christian Couder
2026-11-20 16:48   ` Christian Couder [this message]
2026-11-20 16:48   ` [PATCH v2 3/8] connect: pass a reader " Christian Couder
2026-11-20 16:48   ` [PATCH v2 4/8] connect: buffer the ls-refs and bundle-uri requests Christian Couder
2026-11-20 16:48   ` [PATCH v2 5/8] connect: use write_command_and_capabilities() in get_remote_refs() Christian Couder
2026-11-20 16:48   ` [PATCH v2 6/8] connect: use write_command_and_capabilities() in get_remote_bundle_uri() Christian Couder
2026-11-20 16:48   ` [PATCH v2 7/8] fetch-pack: ensure fetch sends a promisor-remote reply Christian Couder
2026-11-20 16:48   ` [PATCH v2 8/8] doc: gitprotocol-v2: send the promisor-remote reply with fetch Christian Couder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261120164812.707946-12-christian.couder@gmail.com \
    --to=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=mcote@nvidia.com \
    --cc=ps@pks.im \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox