From 72e75ffee70f2e898ae687734aa109f559b39e5c Mon Sep 17 00:00:00 2001 From: Kristofer Karlsson Date: Wed, 7 Oct 2026 14:22:56 +0000 Subject: [PATCH] test-tool read-graph: add commit-info subcommand The test infrastructure has no way to check whether a specific commit is present in the commit-graph, making it hard to verify graph state after operations like fetch. Add a "commit-info" subcommand to test-tool read-graph that queries whether specific commits are present in the commit-graph and prints their generation numbers. Returns 1 if any commit is not found. Signed-off-by: Kristofer Karlsson Signed-off-by: Junio C Hamano --- t/helper/test-read-graph.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/t/helper/test-read-graph.c b/t/helper/test-read-graph.c index 9f07b9c25a..0ab9cf8f2b 100644 --- a/t/helper/test-read-graph.c +++ b/t/helper/test-read-graph.c @@ -2,6 +2,9 @@ #include "test-tool.h" #include "commit-graph.h" +#include "commit.h" +#include "hex.h" +#include "object-name.h" #include "repository.h" #include "odb.h" #include "bloom.h" @@ -91,7 +94,25 @@ int cmd__read_graph(int argc, const char **argv) dump_graph_info(graph); else if (!strcmp(argv[1], "bloom-filters")) dump_graph_bloom_filters(graph); - else { + else if (!strcmp(argv[1], "commit-info")) { + int i; + for (i = 2; i < argc; i++) { + struct object_id oid; + struct commit *c; + + if (repo_get_oid(the_repository, argv[i], &oid)) + die("not a valid object name: '%s'", argv[i]); + c = lookup_commit_in_graph(the_repository, &oid); + if (!c) { + fprintf(stderr, "%s: not in graph\n", argv[i]); + ret = 1; + continue; + } + printf("%s generation %"PRIuMAX"\n", + oid_to_hex(&oid), + (uintmax_t)commit_graph_generation(c)); + } + } else { fprintf(stderr, "unknown sub-command: '%s'\n", argv[1]); ret = 1; }