Skip to content

Commit

Permalink
pack-bitmap.c: keep track of each layer's type bitmaps
Browse files Browse the repository at this point in the history
Prepare for reading the type-level bitmaps from previous bitmap layers
by maintaining an array for each type, where each element in that type's
array corresponds to one layer's bitmap for that type.

These fields will be used in a later commit to instantiate the 'struct
ewah_or_iterator' for each type.

Signed-off-by: Taylor Blau <[email protected]>
  • Loading branch information
ttaylorr committed Nov 19, 2024
1 parent e1b5f61 commit 9ab8fb4
Showing 1 changed file with 51 additions and 4 deletions.
55 changes: 51 additions & 4 deletions pack-bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,24 @@ struct bitmap_index {
struct ewah_bitmap *blobs;
struct ewah_bitmap *tags;

/*
* Type index arrays when this bitmap is associated with an
* incremental multi-pack index chain.
*
* If n is the number of unique layers in the MIDX chain, then
* commits_all[n-1] is this structs 'commits' field,
* commits_all[n-2] is the commits field of this bitmap's
* 'base', and so on.
*
* When either associated either with a non-incremental MIDX, or
* a single packfile, these arrays each contain a single
* element.
*/
struct ewah_bitmap **commits_all;
struct ewah_bitmap **trees_all;
struct ewah_bitmap **blobs_all;
struct ewah_bitmap **tags_all;

/* Map from object ID -> `stored_bitmap` for all the bitmapped commits */
kh_oid_map_t *bitmaps;

Expand Down Expand Up @@ -586,7 +604,29 @@ static int load_reverse_index(struct repository *r, struct bitmap_index *bitmap_
return load_pack_revindex(r, bitmap_git->pack);
}

static int load_bitmap(struct repository *r, struct bitmap_index *bitmap_git)
static void load_all_type_bitmaps(struct bitmap_index *bitmap_git)
{
struct bitmap_index *curr = bitmap_git;
size_t i = bitmap_git->base_nr - 1;

ALLOC_ARRAY(bitmap_git->commits_all, bitmap_git->base_nr);
ALLOC_ARRAY(bitmap_git->trees_all, bitmap_git->base_nr);
ALLOC_ARRAY(bitmap_git->blobs_all, bitmap_git->base_nr);
ALLOC_ARRAY(bitmap_git->tags_all, bitmap_git->base_nr);

while (curr) {
bitmap_git->commits_all[i] = curr->commits;
bitmap_git->trees_all[i] = curr->trees;
bitmap_git->blobs_all[i] = curr->blobs;
bitmap_git->tags_all[i] = curr->tags;

curr = curr->base;
i -= 1;
}
}

static int load_bitmap(struct repository *r, struct bitmap_index *bitmap_git,
int recursing)
{
assert(bitmap_git->map);

Expand All @@ -608,10 +648,13 @@ static int load_bitmap(struct repository *r, struct bitmap_index *bitmap_git)
if (bitmap_git->base) {
if (!bitmap_is_midx(bitmap_git))
BUG("non-MIDX bitmap has non-NULL base bitmap index");
if (load_bitmap(r, bitmap_git->base) < 0)
if (load_bitmap(r, bitmap_git->base, 1) < 0)
goto failed;
}

if (!recursing)
load_all_type_bitmaps(bitmap_git);

return 0;

failed:
Expand Down Expand Up @@ -687,7 +730,7 @@ struct bitmap_index *prepare_bitmap_git(struct repository *r)
{
struct bitmap_index *bitmap_git = xcalloc(1, sizeof(*bitmap_git));

if (!open_bitmap(r, bitmap_git) && !load_bitmap(r, bitmap_git))
if (!open_bitmap(r, bitmap_git) && !load_bitmap(r, bitmap_git, 0))
return bitmap_git;

free_bitmap_index(bitmap_git);
Expand Down Expand Up @@ -2042,7 +2085,7 @@ struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs,
* from disk. this is the point of no return; after this the rev_list
* becomes invalidated and we must perform the revwalk through bitmaps
*/
if (load_bitmap(revs->repo, bitmap_git) < 0)
if (load_bitmap(revs->repo, bitmap_git, 0) < 0)
goto cleanup;

if (!use_boundary_traversal)
Expand Down Expand Up @@ -2961,6 +3004,10 @@ void free_bitmap_index(struct bitmap_index *b)
ewah_pool_free(b->trees);
ewah_pool_free(b->blobs);
ewah_pool_free(b->tags);
free(b->commits_all);
free(b->trees_all);
free(b->blobs_all);
free(b->tags_all);
if (b->bitmaps) {
struct stored_bitmap *sb;
kh_foreach_value(b->bitmaps, sb, {
Expand Down

0 comments on commit 9ab8fb4

Please sign in to comment.