t/helper/test-bitmap.c: add 'dump-hashes' mode

The pack-bitmap writer code is about to learn how to propagate values from an existing hash-cache. To prepare, teach the test-bitmap helper to dump the values from a bitmap's hash-cache extension in order to test those changes. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Sep 14, 2021 at 18:06 UTC a05f02b1d9a1253e11a327c95cd47cbd24317ba6
3 files changed +37 -1
pack-bitmap.c
+27
@@ -1742,6 +1742,33 @@ int test_bitmap_commits(struct repository *r)
1742 return 0;
1743 }
1744
1745 +int test_bitmap_hashes(struct repository *r)
1746 +{
1747 + struct bitmap_index *bitmap_git = prepare_bitmap_git(r);
1748 + struct object_id oid;
1749 + uint32_t i, index_pos;
1750 +
1751 + if (!bitmap_git->hashes)
1752 + goto cleanup;
1753 +
1754 + for (i = 0; i < bitmap_num_objects(bitmap_git); i++) {
1755 + if (bitmap_is_midx(bitmap_git))
1756 + index_pos = pack_pos_to_midx(bitmap_git->midx, i);
1757 + else
1758 + index_pos = pack_pos_to_index(bitmap_git->pack, i);
1759 +
1760 + nth_bitmap_object_oid(bitmap_git, &oid, index_pos);
1761 +
1762 + printf("%s %"PRIu32"\n",
1763 + oid_to_hex(&oid), get_be32(bitmap_git->hashes + index_pos));
1764 + }
1765 +
1766 +cleanup:
1767 + free_bitmap_index(bitmap_git);
1768 +
1769 + return 0;
1770 +}
1771 +
1772 int rebuild_bitmap(const uint32_t *reposition,
1773 struct ewah_bitmap *source,
1774 struct bitmap *dest)
pack-bitmap.h
+1
@@ -52,6 +52,7 @@ void traverse_bitmap_commit_list(struct bitmap_index *,
52 show_reachable_fn show_reachable);
53 void test_bitmap_walk(struct rev_info *revs);
54 int test_bitmap_commits(struct repository *r);
55 +int test_bitmap_hashes(struct repository *r);
56 struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs,
57 struct list_objects_filter_options *filter,
58 int filter_provided_objects);
t/helper/test-bitmap.c
+9 -1
@@ -7,6 +7,11 @@ static int bitmap_list_commits(void)
7 return test_bitmap_commits(the_repository);
8 }
9
10 +static int bitmap_dump_hashes(void)
11 +{
12 + return test_bitmap_hashes(the_repository);
13 +}
14 +
15 int cmd__bitmap(int argc, const char **argv)
16 {
17 setup_git_directory();
@@ -16,9 +21,12 @@ int cmd__bitmap(int argc, const char **argv)
21
22 if (!strcmp(argv[1], "list-commits"))
23 return bitmap_list_commits();
24 + if (!strcmp(argv[1], "dump-hashes"))
25 + return bitmap_dump_hashes();
26
27 usage:
21 - usage("\ttest-tool bitmap list-commits");
28 + usage("\ttest-tool bitmap list-commits\n"
29 + "\ttest-tool bitmap dump-hashes");
30
31 return -1;
32 }