]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t/helper/test-bitmap.c: add 'dump-hashes' mode
authorTaylor Blau <me@ttaylorr.com>
Tue, 14 Sep 2021 22:06:02 +0000 (18:06 -0400)
committerJunio C Hamano <gitster@pobox.com>
Tue, 14 Sep 2021 23:34:17 +0000 (16:34 -0700)
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>
pack-bitmap.c
pack-bitmap.h
t/helper/test-bitmap.c

index 8504110a4daa9013304bc545bc529d6f8c3a8446..04de3873183583e98d2f4ae92e7736a8cae464bc 100644 (file)
@@ -1742,6 +1742,33 @@ int test_bitmap_commits(struct repository *r)
        return 0;
 }
 
+int test_bitmap_hashes(struct repository *r)
+{
+       struct bitmap_index *bitmap_git = prepare_bitmap_git(r);
+       struct object_id oid;
+       uint32_t i, index_pos;
+
+       if (!bitmap_git->hashes)
+               goto cleanup;
+
+       for (i = 0; i < bitmap_num_objects(bitmap_git); i++) {
+               if (bitmap_is_midx(bitmap_git))
+                       index_pos = pack_pos_to_midx(bitmap_git->midx, i);
+               else
+                       index_pos = pack_pos_to_index(bitmap_git->pack, i);
+
+               nth_bitmap_object_oid(bitmap_git, &oid, index_pos);
+
+               printf("%s %"PRIu32"\n",
+                      oid_to_hex(&oid), get_be32(bitmap_git->hashes + index_pos));
+       }
+
+cleanup:
+       free_bitmap_index(bitmap_git);
+
+       return 0;
+}
+
 int rebuild_bitmap(const uint32_t *reposition,
                   struct ewah_bitmap *source,
                   struct bitmap *dest)
index 469090bad2cf170670edc7e6a9ea66a51cc25482..ed46d27077f7fb3dfd4f698da1c29f9e5748d665 100644 (file)
@@ -52,6 +52,7 @@ void traverse_bitmap_commit_list(struct bitmap_index *,
                                 show_reachable_fn show_reachable);
 void test_bitmap_walk(struct rev_info *revs);
 int test_bitmap_commits(struct repository *r);
+int test_bitmap_hashes(struct repository *r);
 struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs,
                                         struct list_objects_filter_options *filter,
                                         int filter_provided_objects);
index 134a1e9d762ced9955b42bafa9b0b8287ac68753..ff35f5999b367106f04743582ca9fb490b80501f 100644 (file)
@@ -7,6 +7,11 @@ static int bitmap_list_commits(void)
        return test_bitmap_commits(the_repository);
 }
 
+static int bitmap_dump_hashes(void)
+{
+       return test_bitmap_hashes(the_repository);
+}
+
 int cmd__bitmap(int argc, const char **argv)
 {
        setup_git_directory();
@@ -16,9 +21,12 @@ int cmd__bitmap(int argc, const char **argv)
 
        if (!strcmp(argv[1], "list-commits"))
                return bitmap_list_commits();
+       if (!strcmp(argv[1], "dump-hashes"))
+               return bitmap_dump_hashes();
 
 usage:
-       usage("\ttest-tool bitmap list-commits");
+       usage("\ttest-tool bitmap list-commits\n"
+             "\ttest-tool bitmap dump-hashes");
 
        return -1;
 }