Skip to content

Commit 57982b8

Browse files
ttaylorrgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]> Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a09858d commit 57982b8

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

t/helper/test-read-graph.c

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,55 @@ static void dump_graph_info(struct commit_graph *graph)
4747
printf("\n");
4848
}
4949

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)
5172
{
5273
struct commit_graph *graph = NULL;
5374
struct object_directory *odb;
75+
int ret = 0;
5476

5577
setup_git_directory();
5678
odb = the_repository->objects->odb;
5779

5880
prepare_repo_settings(the_repository);
5981

6082
graph = read_commit_graph_one(the_repository, odb);
61-
if (!graph)
62-
return 1;
83+
if (!graph) {
84+
ret = 1;
85+
goto done;
86+
}
6387

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+
}
6596

97+
done:
6698
UNLEAK(graph);
6799

68-
return 0;
100+
return ret;
69101
}

0 commit comments

Comments
 (0)