t/helper/test-read-graph: implement `bloom-filters` mode

Implement a mode of the "read-graph" test helper to dump out the hexadecimal contents of the Bloom filter(s) contained in a commit-graph. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Jun 25, 2024 at 13:39 UTC 57982b8f2af9563cb54aafbf46e21f2b744ab59e
1 file changed +37 -5
t/helper/test-read-graph.c
+37 -5
@@ -47,10 +47,32 @@ static void dump_graph_info(struct commit_graph *graph)
47 printf("\n");
48 }
49
50 -int cmd__read_graph(int argc UNUSED, const char **argv UNUSED)
50 +static void dump_graph_bloom_filters(struct commit_graph *graph)
51 +{
52 + uint32_t i;
53 +
54 + for (i = 0; i < graph->num_commits + graph->num_commits_in_base; i++) {
55 + struct bloom_filter filter = { 0 };
56 + size_t j;
57 +
58 + if (load_bloom_filter_from_graph(graph, &filter, i) < 0) {
59 + fprintf(stderr, "missing Bloom filter for graph "
60 + "position %"PRIu32"\n", i);
61 + continue;
62 + }
63 +
64 + for (j = 0; j < filter.len; j++)
65 + printf("%02x", filter.data[j]);
66 + if (filter.len)
67 + printf("\n");
68 + }
69 +}
70 +
71 +int cmd__read_graph(int argc, const char **argv)
72 {
73 struct commit_graph *graph = NULL;
74 struct object_directory *odb;
75 + int ret = 0;
76
77 setup_git_directory();
78 odb = the_repository->objects->odb;
@@ -58,12 +80,22 @@ int cmd__read_graph(int argc UNUSED, const char **argv UNUSED)
80 prepare_repo_settings(the_repository);
81
82 graph = read_commit_graph_one(the_repository, odb);
61 - if (!graph)
62 - return 1;
83 + if (!graph) {
84 + ret = 1;
85 + goto done;
86 + }
87
64 - dump_graph_info(graph);
88 + if (argc <= 1)
89 + dump_graph_info(graph);
90 + else if (!strcmp(argv[1], "bloom-filters"))
91 + dump_graph_bloom_filters(graph);
92 + else {
93 + fprintf(stderr, "unknown sub-command: '%s'\n", argv[1]);
94 + ret = 1;
95 + }
96
97 +done:
98 UNLEAK(graph);
99
68 - return 0;
100 + return ret;
101 }