[PATCH v3 1/2] test-tool read-graph: add commit-info subcommand
- From
Kristofer Karlsson via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Oct 7, 2026, 14:22 UTC
- Message-ID
- <36cc3ff3b329375d9d87d7ffbaf33b019f91b4b0.1791382977.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.2239.v3.git.1791382977.gitgitgadget@gmail.com>
From: Kristofer Karlsson <krka@spotify.com>
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 <krka@spotify.com> --- 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; }
-- gitgitgadget