Skip to content

Commit 98c31f3

Browse files
ttaylorrgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 449fa5e commit 98c31f3

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

pack-bitmap.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,16 @@ struct include_data {
380380
struct bitmap *seen;
381381
};
382382

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+
383393
static inline int bitmap_position_extended(struct bitmap_index *bitmap_git,
384394
const struct object_id *oid)
385395
{
@@ -465,21 +475,20 @@ static void show_commit(struct commit *commit, void *data)
465475

466476
static int add_to_include_set(struct bitmap_index *bitmap_git,
467477
struct include_data *data,
468-
const struct object_id *oid,
478+
struct commit *commit,
469479
int bitmap_pos)
470480
{
471-
khiter_t hash_pos;
481+
struct ewah_bitmap *partial;
472482

473483
if (data->seen && bitmap_get(data->seen, bitmap_pos))
474484
return 0;
475485

476486
if (bitmap_get(data->base, bitmap_pos))
477487
return 0;
478488

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);
483492
return 0;
484493
}
485494

@@ -498,8 +507,7 @@ static int should_include(struct commit *commit, void *_data)
498507
(struct object *)commit,
499508
NULL);
500509

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)) {
503511
struct commit_list *parent = commit->parents;
504512

505513
while (parent) {
@@ -1282,10 +1290,10 @@ void test_bitmap_walk(struct rev_info *revs)
12821290
{
12831291
struct object *root;
12841292
struct bitmap *result = NULL;
1285-
khiter_t pos;
12861293
size_t result_popcnt;
12871294
struct bitmap_test_data tdata;
12881295
struct bitmap_index *bitmap_git;
1296+
struct ewah_bitmap *bm;
12891297

12901298
if (!(bitmap_git = prepare_bitmap_git(revs->repo)))
12911299
die("failed to load bitmap indexes");
@@ -1297,12 +1305,9 @@ void test_bitmap_walk(struct rev_info *revs)
12971305
bitmap_git->version, bitmap_git->entry_count);
12981306

12991307
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);
13051309

1310+
if (bm) {
13061311
fprintf(stderr, "Found bitmap for %s. %d bits / %08x checksum\n",
13071312
oid_to_hex(&root->oid), (int)bm->bit_size, ewah_checksum(bm));
13081313

pack-bitmap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ uint32_t *create_bitmap_mapping(struct bitmap_index *bitmap_git,
7878
int rebuild_bitmap(const uint32_t *reposition,
7979
struct ewah_bitmap *source,
8080
struct bitmap *dest);
81+
struct ewah_bitmap *bitmap_for_commit(struct bitmap_index *bitmap_git,
82+
struct commit *commit);
8183
void bitmap_writer_select_commits(struct commit **indexed_commits,
8284
unsigned int indexed_commits_nr, int max_bitmaps);
8385
void bitmap_writer_build(struct packing_data *to_pack);

0 commit comments

Comments
 (0)