pack-bitmap: implement test helpers for pseudo-merge

Implement three new sub-commands for the "bitmap" test-helper:

  - t/helper test-tool bitmap dump-pseudo-merges
  - t/helper test-tool bitmap dump-pseudo-merge-commits <n>
  - t/helper test-tool bitmap dump-pseudo-merge-objects <n>

These three helpers dump the list of pseudo merges, the "parents" of the
nth pseudo-merges, and the set of objects reachable from those parents,
respectively.

These helpers will be useful in subsequent patches when we add test
coverage for pseudo-merge bitmaps.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Taylor Blau
2024-05-23 17:27:05 -04:00
committed by Junio C Hamano
parent 0481cbf912
commit 71eca9ab79
3 changed files with 156 additions and 7 deletions

View File

@ -2443,6 +2443,132 @@ cleanup:
return 0; return 0;
} }
static void bit_pos_to_object_id(struct bitmap_index *bitmap_git,
uint32_t bit_pos,
struct object_id *oid)
{
uint32_t index_pos;
if (bitmap_is_midx(bitmap_git))
index_pos = pack_pos_to_midx(bitmap_git->midx, bit_pos);
else
index_pos = pack_pos_to_index(bitmap_git->pack, bit_pos);
nth_bitmap_object_oid(bitmap_git, oid, index_pos);
}
int test_bitmap_pseudo_merges(struct repository *r)
{
struct bitmap_index *bitmap_git;
uint32_t i;
bitmap_git = prepare_bitmap_git(r);
if (!bitmap_git || !bitmap_git->pseudo_merges.nr)
goto cleanup;
for (i = 0; i < bitmap_git->pseudo_merges.nr; i++) {
struct pseudo_merge *merge;
struct ewah_bitmap *commits_bitmap, *merge_bitmap;
merge = use_pseudo_merge(&bitmap_git->pseudo_merges,
&bitmap_git->pseudo_merges.v[i]);
commits_bitmap = merge->commits;
merge_bitmap = pseudo_merge_bitmap(&bitmap_git->pseudo_merges,
merge);
printf("at=%"PRIuMAX", commits=%"PRIuMAX", objects=%"PRIuMAX"\n",
(uintmax_t)merge->at,
(uintmax_t)ewah_bitmap_popcount(commits_bitmap),
(uintmax_t)ewah_bitmap_popcount(merge_bitmap));
}
cleanup:
free_bitmap_index(bitmap_git);
return 0;
}
static void dump_ewah_object_ids(struct bitmap_index *bitmap_git,
struct ewah_bitmap *bitmap)
{
struct ewah_iterator it;
eword_t word;
uint32_t pos = 0;
ewah_iterator_init(&it, bitmap);
while (ewah_iterator_next(&word, &it)) {
struct object_id oid;
uint32_t offset;
for (offset = 0; offset < BITS_IN_EWORD; offset++) {
if (!(word >> offset))
break;
offset += ewah_bit_ctz64(word >> offset);
bit_pos_to_object_id(bitmap_git, pos + offset, &oid);
printf("%s\n", oid_to_hex(&oid));
}
pos += BITS_IN_EWORD;
}
}
int test_bitmap_pseudo_merge_commits(struct repository *r, uint32_t n)
{
struct bitmap_index *bitmap_git;
struct pseudo_merge *merge;
int ret = 0;
bitmap_git = prepare_bitmap_git(r);
if (!bitmap_git || !bitmap_git->pseudo_merges.nr)
goto cleanup;
if (n >= bitmap_git->pseudo_merges.nr) {
ret = error(_("pseudo-merge index out of range "
"(%"PRIu32" >= %"PRIuMAX")"),
n, (uintmax_t)bitmap_git->pseudo_merges.nr);
goto cleanup;
}
merge = use_pseudo_merge(&bitmap_git->pseudo_merges,
&bitmap_git->pseudo_merges.v[n]);
dump_ewah_object_ids(bitmap_git, merge->commits);
cleanup:
free_bitmap_index(bitmap_git);
return ret;
}
int test_bitmap_pseudo_merge_objects(struct repository *r, uint32_t n)
{
struct bitmap_index *bitmap_git;
struct pseudo_merge *merge;
int ret = 0;
bitmap_git = prepare_bitmap_git(r);
if (!bitmap_git || !bitmap_git->pseudo_merges.nr)
goto cleanup;
if (n >= bitmap_git->pseudo_merges.nr) {
ret = error(_("pseudo-merge index out of range "
"(%"PRIu32" >= %"PRIuMAX")"),
n, (uintmax_t)bitmap_git->pseudo_merges.nr);
goto cleanup;
}
merge = use_pseudo_merge(&bitmap_git->pseudo_merges,
&bitmap_git->pseudo_merges.v[n]);
dump_ewah_object_ids(bitmap_git,
pseudo_merge_bitmap(&bitmap_git->pseudo_merges,
merge));
cleanup:
free_bitmap_index(bitmap_git);
return ret;
}
int rebuild_bitmap(const uint32_t *reposition, int rebuild_bitmap(const uint32_t *reposition,
struct ewah_bitmap *source, struct ewah_bitmap *source,
struct bitmap *dest) struct bitmap *dest)

View File

@ -73,6 +73,9 @@ void traverse_bitmap_commit_list(struct bitmap_index *,
void test_bitmap_walk(struct rev_info *revs); void test_bitmap_walk(struct rev_info *revs);
int test_bitmap_commits(struct repository *r); int test_bitmap_commits(struct repository *r);
int test_bitmap_hashes(struct repository *r); int test_bitmap_hashes(struct repository *r);
int test_bitmap_pseudo_merges(struct repository *r);
int test_bitmap_pseudo_merge_commits(struct repository *r, uint32_t n);
int test_bitmap_pseudo_merge_objects(struct repository *r, uint32_t n);
#define GIT_TEST_PACK_USE_BITMAP_BOUNDARY_TRAVERSAL \ #define GIT_TEST_PACK_USE_BITMAP_BOUNDARY_TRAVERSAL \
"GIT_TEST_PACK_USE_BITMAP_BOUNDARY_TRAVERSAL" "GIT_TEST_PACK_USE_BITMAP_BOUNDARY_TRAVERSAL"

View File

@ -13,21 +13,41 @@ static int bitmap_dump_hashes(void)
return test_bitmap_hashes(the_repository); return test_bitmap_hashes(the_repository);
} }
static int bitmap_dump_pseudo_merges(void)
{
return test_bitmap_pseudo_merges(the_repository);
}
static int bitmap_dump_pseudo_merge_commits(uint32_t n)
{
return test_bitmap_pseudo_merge_commits(the_repository, n);
}
static int bitmap_dump_pseudo_merge_objects(uint32_t n)
{
return test_bitmap_pseudo_merge_objects(the_repository, n);
}
int cmd__bitmap(int argc, const char **argv) int cmd__bitmap(int argc, const char **argv)
{ {
setup_git_directory(); setup_git_directory();
if (argc != 2) if (argc == 2 && !strcmp(argv[1], "list-commits"))
goto usage;
if (!strcmp(argv[1], "list-commits"))
return bitmap_list_commits(); return bitmap_list_commits();
if (!strcmp(argv[1], "dump-hashes")) if (argc == 2 && !strcmp(argv[1], "dump-hashes"))
return bitmap_dump_hashes(); return bitmap_dump_hashes();
if (argc == 2 && !strcmp(argv[1], "dump-pseudo-merges"))
return bitmap_dump_pseudo_merges();
if (argc == 3 && !strcmp(argv[1], "dump-pseudo-merge-commits"))
return bitmap_dump_pseudo_merge_commits(atoi(argv[2]));
if (argc == 3 && !strcmp(argv[1], "dump-pseudo-merge-objects"))
return bitmap_dump_pseudo_merge_objects(atoi(argv[2]));
usage:
usage("\ttest-tool bitmap list-commits\n" usage("\ttest-tool bitmap list-commits\n"
"\ttest-tool bitmap dump-hashes"); "\ttest-tool bitmap dump-hashes\n"
"\ttest-tool bitmap dump-pseudo-merges\n"
"\ttest-tool bitmap dump-pseudo-merge-commits <n>\n"
"\ttest-tool bitmap dump-pseudo-merge-objects <n>");
return -1; return -1;
} }