Git development
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
	Justin Tobler <jltobler@gmail.com>,
	 Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Subject: [PATCH v3 2/9] t/helper: report number of layers in "read-graph"
Date: Fri, 04 Dec 2026 07:53:37 +0100	[thread overview]
Message-ID: <20261204-pks-odb-pluggable-commit-graphs-v3-2-85dafc8ce396@pks.im> (raw)
In-Reply-To: <20261204-pks-odb-pluggable-commit-graphs-v3-0-85dafc8ce396@pks.im>

We don't have an easy way to tell how many layers the loaded commit
graph has. While it would typically match exactly the number of layers
in the commit-graph-chain file, that's not always the case. For example,
when some of the layers are corrupt then we'd only load valid layers.

Extend `test-tool read-graph` to report on the number of loaded layers
so that we can test for this and expose this via `graph_read_expect ()`.
Note that this also requires us to report on the "base_graphs" chunk, as
otherwise the number of expected chunks would be off.

Adapt tests to use the helper.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 t/helper/test-read-graph.c    |  9 +++++++++
 t/lib-commit-graph.sh         | 17 ++++++++++++++---
 t/t5324-split-commit-graph.sh | 37 +++++--------------------------------
 3 files changed, 28 insertions(+), 35 deletions(-)

diff --git a/t/helper/test-read-graph.c b/t/helper/test-read-graph.c
index 9642e55b8c0..5c1fa9f5596 100644
--- a/t/helper/test-read-graph.c
+++ b/t/helper/test-read-graph.c
@@ -13,6 +13,12 @@
 
 static void dump_graph_info(struct commit_graph *graph)
 {
+	struct commit_graph *base;
+	size_t layers = 1;
+
+	for (base = graph->base_graph; base; base = base->base_graph)
+		layers++;
+
 	printf("header: %08x %d %d %d %d\n",
 		ntohl(*(uint32_t*)graph->data),
 		*(unsigned char*)(graph->data + 4),
@@ -20,6 +26,7 @@ static void dump_graph_info(struct commit_graph *graph)
 		*(unsigned char*)(graph->data + 6),
 		*(unsigned char*)(graph->data + 7));
 	printf("num_commits: %u\n", graph->num_commits);
+	printf("layers: %"PRIuMAX"\n", (uintmax_t)layers);
 	printf("chunks:");
 
 	if (graph->chunk_oid_fanout)
@@ -28,6 +35,8 @@ static void dump_graph_info(struct commit_graph *graph)
 		printf(" oid_lookup");
 	if (graph->chunk_commit_data)
 		printf(" commit_metadata");
+	if (graph->chunk_base_graphs)
+		printf(" base_graphs");
 	if (graph->chunk_generation_data)
 		printf(" generation_data");
 	if (graph->chunk_generation_data_overflow)
diff --git a/t/lib-commit-graph.sh b/t/lib-commit-graph.sh
index d3963dc89ca..dade9d3ce59 100755
--- a/t/lib-commit-graph.sh
+++ b/t/lib-commit-graph.sh
@@ -41,6 +41,7 @@ graph_read_expect() {
 	DIR="."
 	GENERATION_VERSION=2
 	OPTIONS=
+	LAYERS=1
 	COMMITS=$1
 	shift
 
@@ -52,8 +53,8 @@ graph_read_expect() {
 			shift
 			;;
 		-c)
-			OPTIONAL=" $2"
-			NUM_CHUNKS=$((3 + $(echo "$2" | wc -w)))
+			OPTIONAL="$OPTIONAL $2"
+			NUM_CHUNKS=$(($NUM_CHUNKS + $(echo "$2" | wc -w)))
 			shift
 			;;
 		-v)
@@ -64,6 +65,15 @@ graph_read_expect() {
 			OPTIONS=" $2"
 			shift
 			;;
+		-l)
+			LAYERS="$2"
+			if test "$2" -gt 1
+			then
+				OPTIONAL=" base_graphs$OPTIONAL"
+				NUM_CHUNKS=$(($NUM_CHUNKS + 1))
+			fi
+			shift
+			;;
 		*)
 			BUG "unknown argument for graph_read_expect: $1"
 			;;
@@ -77,8 +87,9 @@ graph_read_expect() {
 	fi
 
 	cat >"$DIR/expect" <<-EOF
-	header: 43475048 1 $(test_oid oid_version) $NUM_CHUNKS 0
+	header: 43475048 1 $(test_oid oid_version) $NUM_CHUNKS $(($LAYERS - 1))
 	num_commits: $COMMITS
+	layers: $LAYERS
 	chunks: oid_fanout oid_lookup commit_metadata$OPTIONAL
 	options:$OPTIONS
 	EOF
diff --git a/t/t5324-split-commit-graph.sh b/t/t5324-split-commit-graph.sh
index 84ae9a202aa..ac614b5e878 100755
--- a/t/t5324-split-commit-graph.sh
+++ b/t/t5324-split-commit-graph.sh
@@ -559,14 +559,7 @@ test_expect_success 'setup repo for mixed generation commit-graph-chain' '
 		done &&
 		git -c commitGraph.generationVersion=1 commit-graph write --reachable --split=no-merge &&
 		test_line_count = 2 $graphdir/commit-graph-chain &&
-		test-tool read-graph >output &&
-		cat >expect <<-EOF &&
-		header: 43475048 1 $(test_oid oid_version) 4 1
-		num_commits: $NUM_SECOND_LAYER_COMMITS
-		chunks: oid_fanout oid_lookup commit_metadata
-		options:
-		EOF
-		test_cmp expect output &&
+		graph_read_expect $NUM_SECOND_LAYER_COMMITS -v 1 -l 2 &&
 		git commit-graph verify &&
 		cat $graphdir/commit-graph-chain
 	)
@@ -592,14 +585,7 @@ test_expect_success 'do not write generation data chunk if not present on existi
 		done &&
 		git commit-graph write --reachable --split=no-merge &&
 		test_line_count = 3 $graphdir/commit-graph-chain &&
-		test-tool read-graph >output &&
-		cat >expect <<-EOF &&
-		header: 43475048 1 $(test_oid oid_version) 4 2
-		num_commits: $NUM_THIRD_LAYER_COMMITS
-		chunks: oid_fanout oid_lookup commit_metadata
-		options:
-		EOF
-		test_cmp expect output &&
+		graph_read_expect $NUM_THIRD_LAYER_COMMITS -v 1 -l 3 &&
 		git commit-graph verify
 	)
 '
@@ -634,14 +620,7 @@ test_expect_success 'do not write generation data chunk if the topmost remaining
 		done &&
 		git commit-graph write --reachable --split --size-multiple 1 &&
 		test_line_count = 3 $graphdir/commit-graph-chain &&
-		test-tool read-graph >output &&
-		cat >expect <<-EOF &&
-		header: 43475048 1 $(test_oid oid_version) 4 2
-		num_commits: $(($NUM_THIRD_LAYER_COMMITS + $NUM_FOURTH_LAYER_COMMITS))
-		chunks: oid_fanout oid_lookup commit_metadata
-		options:
-		EOF
-		test_cmp expect output &&
+		graph_read_expect $(($NUM_THIRD_LAYER_COMMITS + $NUM_FOURTH_LAYER_COMMITS)) -v 1 -l 3 &&
 		git commit-graph verify
 	)
 '
@@ -674,14 +653,8 @@ test_expect_success 'write generation data chunk if topmost remaining layer has
 		done &&
 		git commit-graph write --reachable --split --size-multiple 1 &&
 		test_line_count = 2 $graphdir/commit-graph-chain &&
-		test-tool read-graph >output &&
-		cat >expect <<-EOF &&
-		header: 43475048 1 $(test_oid oid_version) 5 1
-		num_commits: $(($NUM_SECOND_LAYER_COMMITS + $NUM_THIRD_LAYER_COMMITS + $NUM_FOURTH_LAYER_COMMITS + $NUM_FIFTH_LAYER_COMMITS))
-		chunks: oid_fanout oid_lookup commit_metadata generation_data
-		options: read_generation_data
-		EOF
-		test_cmp expect output
+		NUM_COMMITS=$(($NUM_SECOND_LAYER_COMMITS + $NUM_THIRD_LAYER_COMMITS + $NUM_FOURTH_LAYER_COMMITS + $NUM_FIFTH_LAYER_COMMITS)) &&
+		graph_read_expect "$NUM_COMMITS" -l 2 -c generation_data
 	)
 '
 

-- 
2.98.0.rc0.245.g55e557da3a.dirty


  parent reply	other threads:[~2026-12-04  6:53 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 13:07 [PATCH 00/12] Introduce pluggable commit graphs Patrick Steinhardt
2026-11-16 13:07 ` [PATCH 01/12] commit-graph: simplify linking commit graph chains Patrick Steinhardt
2026-11-16 20:53   ` Junio C Hamano
2026-11-20 11:15     ` Patrick Steinhardt
2026-11-16 13:07 ` [PATCH 02/12] commit-graph: simplify reading a single commit graph Patrick Steinhardt
2026-11-16 13:07 ` [PATCH 03/12] commit-graph: expose function to validate a commit graph chain Patrick Steinhardt
2026-11-16 13:07 ` [PATCH 04/12] commit-graph: decide mergeable and chainable layers by depth Patrick Steinhardt
2026-11-16 13:07 ` [PATCH 05/12] commit-graph: introduce common exit for `write_commit_graph_file()` Patrick Steinhardt
2026-11-16 13:07 ` [PATCH 06/12] commit-graph: derive layer infos from the passed-in chain Patrick Steinhardt
2026-11-16 13:07 ` [PATCH 07/12] commit-graph: split out check whether writing commit graphs is allowed Patrick Steinhardt
2026-11-16 13:07 ` [PATCH 08/12] commit-graph: split out logic to write a new commit graph layer Patrick Steinhardt
2026-11-16 13:07 ` [PATCH 09/12] commit-graph: mark incomplete commit graph chains Patrick Steinhardt
2026-11-16 13:07 ` [PATCH 10/12] odb/source: make commit graphs pluggable Patrick Steinhardt
2026-11-16 13:07 ` [PATCH 11/12] odb/source-files: move logic to derive commit graph paths Patrick Steinhardt
2026-11-16 13:07 ` [PATCH 12/12] odb/source-files: internalize " Patrick Steinhardt
2026-11-20 12:22 ` [PATCH v2 0/7] Introduce pluggable commit graphs (pt.1) Patrick Steinhardt
2026-11-20 12:22   ` [PATCH v2 1/7] commit-graph: verify all trailer hashes against the chain file Patrick Steinhardt
2026-12-02 22:29     ` Justin Tobler
2026-12-03  7:31       ` Patrick Steinhardt
2026-12-03  9:12         ` Patrick Steinhardt
2026-12-03  9:13     ` Kaartic Sivaraam
2026-12-03 13:18       ` Patrick Steinhardt
2026-11-20 12:22   ` [PATCH v2 2/7] commit-graph: simplify linking commit graph chains Patrick Steinhardt
2026-12-02 22:54     ` Justin Tobler
2026-12-03 10:03     ` Kaartic Sivaraam
2026-12-03 13:18       ` Patrick Steinhardt
2026-11-20 12:22   ` [PATCH v2 3/7] commit-graph: simplify reading a single commit graph Patrick Steinhardt
2026-12-03 10:37     ` Kaartic Sivaraam
2026-12-03 13:19       ` Patrick Steinhardt
2026-11-20 12:22   ` [PATCH v2 4/7] commit-graph: expose function to validate a commit graph chain Patrick Steinhardt
2026-12-03 11:01     ` Kaartic Sivaraam
2026-12-03 13:19       ` Patrick Steinhardt
2026-11-20 12:22   ` [PATCH v2 5/7] commit-graph: decide mergeable and chainable layers by depth Patrick Steinhardt
2026-12-02 23:38     ` Justin Tobler
2026-12-03  7:31       ` Patrick Steinhardt
2026-12-03 13:38     ` Kaartic Sivaraam
2026-12-03 17:16       ` Patrick Steinhardt
2026-11-20 12:22   ` [PATCH v2 6/7] commit-graph: introduce common exit for `write_commit_graph_file()` Patrick Steinhardt
2026-12-03 13:50     ` Kaartic Sivaraam
2026-12-03 17:16       ` Patrick Steinhardt
2026-11-20 12:22   ` [PATCH v2 7/7] commit-graph: derive layer infos from the passed-in chain Patrick Steinhardt
2026-12-04  6:53 ` [PATCH v3 0/9] Introduce pluggable commit graphs (pt.1) Patrick Steinhardt
2026-12-04  6:53   ` [PATCH v3 1/9] t: deduplicate `graph_read_expect()` implementations Patrick Steinhardt
2026-12-04  6:53   ` Patrick Steinhardt [this message]
2026-12-04  6:53   ` [PATCH v3 3/9] commit-graph: verify all trailer hashes against the chain file Patrick Steinhardt
2026-12-04  6:53   ` [PATCH v3 4/9] commit-graph: simplify linking commit graph chains Patrick Steinhardt
2026-12-04  6:53   ` [PATCH v3 5/9] commit-graph: simplify reading a single commit graph Patrick Steinhardt
2026-12-04  6:53   ` [PATCH v3 6/9] commit-graph: expose function to finalize a commit graph chain Patrick Steinhardt
2026-12-04  6:53   ` [PATCH v3 7/9] commit-graph: decide mergeable and chainable layers by depth Patrick Steinhardt
2026-12-04  6:53   ` [PATCH v3 8/9] commit-graph: introduce common exit for `write_commit_graph_file()` Patrick Steinhardt
2026-12-04  6:53   ` [PATCH v3 9/9] commit-graph: derive layer info from the passed-in chain Patrick Steinhardt

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=20261204-pks-odb-pluggable-commit-graphs-v3-2-85dafc8ce396@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jltobler@gmail.com \
    --cc=kaartic.sivaraam@gmail.com \
    /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