pack-bitmap: factor out 'bitmap_for_commit()'
A couple of callers within pack-bitmap.c duplicate logic to lookup a given object id in the bitamps khash. Factor this out into a new function, 'bitmap_for_commit()' to reduce some code duplication. Make this new function non-static, since it will be used in later commits from outside of pack-bitmap.c. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Taylor Blau committed
Dec 8, 2020 at 17:05 UTC
98c31f366a1770fb7ea04125ff2d8b1ea1f7d0d7
2 files changed
+21
-14
pack-bitmap.c
+19
-14
@@ -380,6 +380,16 @@ struct include_data {
380
struct bitmap *seen;
381
};
382
383
+struct ewah_bitmap *bitmap_for_commit(struct bitmap_index *bitmap_git,
384
+ struct commit *commit)
385
+{
386
+ khiter_t hash_pos = kh_get_oid_map(bitmap_git->bitmaps,
387
+ commit->object.oid);
388
+ if (hash_pos >= kh_end(bitmap_git->bitmaps))
389
+ return NULL;
390
+ return lookup_stored_bitmap(kh_value(bitmap_git->bitmaps, hash_pos));
391
+}
392
+
393
static inline int bitmap_position_extended(struct bitmap_index *bitmap_git,
394
const struct object_id *oid)
395
{
@@ -465,10 +475,10 @@ static void show_commit(struct commit *commit, void *data)
475
476
static int add_to_include_set(struct bitmap_index *bitmap_git,
477
struct include_data *data,
468
- const struct object_id *oid,
478
+ struct commit *commit,
479
int bitmap_pos)
480
{
471
- khiter_t hash_pos;
481
+ struct ewah_bitmap *partial;
482
483
if (data->seen && bitmap_get(data->seen, bitmap_pos))
484
return 0;
@@ -476,10 +486,9 @@ static int add_to_include_set(struct bitmap_index *bitmap_git,
486
if (bitmap_get(data->base, bitmap_pos))
487
return 0;
488
479
- hash_pos = kh_get_oid_map(bitmap_git->bitmaps, *oid);
480
- if (hash_pos < kh_end(bitmap_git->bitmaps)) {
481
- struct stored_bitmap *st = kh_value(bitmap_git->bitmaps, hash_pos);
482
- bitmap_or_ewah(data->base, lookup_stored_bitmap(st));
489
+ partial = bitmap_for_commit(bitmap_git, commit);
490
+ if (partial) {
491
+ bitmap_or_ewah(data->base, partial);
492
return 0;
493
}
494
@@ -498,8 +507,7 @@ static int should_include(struct commit *commit, void *_data)
507
(struct object *)commit,
508
NULL);
509
501
- if (!add_to_include_set(data->bitmap_git, data, &commit->object.oid,
502
- bitmap_pos)) {
510
+ if (!add_to_include_set(data->bitmap_git, data, commit, bitmap_pos)) {
511
struct commit_list *parent = commit->parents;
512
513
while (parent) {
@@ -1282,10 +1290,10 @@ void test_bitmap_walk(struct rev_info *revs)
1290
{
1291
struct object *root;
1292
struct bitmap *result = NULL;
1285
- khiter_t pos;
1293
size_t result_popcnt;
1294
struct bitmap_test_data tdata;
1295
struct bitmap_index *bitmap_git;
1296
+ struct ewah_bitmap *bm;
1297
1298
if (!(bitmap_git = prepare_bitmap_git(revs->repo)))
1299
die("failed to load bitmap indexes");
@@ -1297,12 +1305,9 @@ void test_bitmap_walk(struct rev_info *revs)
1305
bitmap_git->version, bitmap_git->entry_count);
1306
1307
root = revs->pending.objects[0].item;
1300
- pos = kh_get_oid_map(bitmap_git->bitmaps, root->oid);
1301
-
1302
- if (pos < kh_end(bitmap_git->bitmaps)) {
1303
- struct stored_bitmap *st = kh_value(bitmap_git->bitmaps, pos);
1304
- struct ewah_bitmap *bm = lookup_stored_bitmap(st);
1308
+ bm = bitmap_for_commit(bitmap_git, (struct commit *)root);
1309
1310
+ if (bm) {
1311
fprintf(stderr, "Found bitmap for %s. %d bits / %08x checksum\n",
1312
oid_to_hex(&root->oid), (int)bm->bit_size, ewah_checksum(bm));
1313
pack-bitmap.h
+2
@@ -78,6 +78,8 @@ uint32_t *create_bitmap_mapping(struct bitmap_index *bitmap_git,
78
int rebuild_bitmap(const uint32_t *reposition,
79
struct ewah_bitmap *source,
80
struct bitmap *dest);
81
+struct ewah_bitmap *bitmap_for_commit(struct bitmap_index *bitmap_git,
82
+ struct commit *commit);
83
void bitmap_writer_select_commits(struct commit **indexed_commits,
84
unsigned int indexed_commits_nr, int max_bitmaps);
85
void bitmap_writer_build(struct packing_data *to_pack);