[PATCH v3 09/11] pack-bitmap: introduce function to check whether a pack is bitmapped
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Apr 2, 2025, 11:13 UTC
- Message-ID
- <20250402-pks-cat-file-object-type-filter-v3-9-4da6bb21871c@pks.im>
- In-Reply-To
- <20250402-pks-cat-file-object-type-filter-v3-0-4da6bb21871c@pks.im>
Introduce a function that allows us to verify whether a pack is bitmapped or not. This functionality will be used in a subsequent commit.
Helped-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Patrick Steinhardt <ps@pks.im> --- pack-bitmap.c | 15 +++++++++++++++ pack-bitmap.h | 7 +++++++ 2 files changed, 22 insertions(+)
diff --git a/pack-bitmap.c b/pack-bitmap.c index 6adb8aaa1c2..edc8f42122d 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -745,6 +745,21 @@ struct bitmap_index *prepare_midx_bitmap_git(struct multi_pack_index *midx) return NULL; } +int bitmap_index_contains_pack(struct bitmap_index *bitmap, struct packed_git *pack) +{ + for (; bitmap; bitmap = bitmap->base) { + if (bitmap_is_midx(bitmap)) { + for (size_t i = 0; i < bitmap->midx->num_packs; i++) + if (bitmap->midx->packs[i] == pack) + return 1; + } else if (bitmap->pack == pack) { + return 1; + } + } + + return 0; +} + struct include_data { struct bitmap_index *bitmap_git; struct bitmap *base; diff --git a/pack-bitmap.h b/pack-bitmap.h index 079bae32466..55df1b3af5a 100644 --- a/pack-bitmap.h +++ b/pack-bitmap.h @@ -67,6 +67,13 @@ struct bitmapped_pack { struct bitmap_index *prepare_bitmap_git(struct repository *r); struct bitmap_index *prepare_midx_bitmap_git(struct multi_pack_index *midx); + +/* + * Given a bitmap index, determine whether it contains the pack either directly + * or via the multi-pack-index. + */ +int bitmap_index_contains_pack(struct bitmap_index *bitmap, struct packed_git *pack); + void count_bitmap_commit_list(struct bitmap_index *, uint32_t *commits, uint32_t *trees, uint32_t *blobs, uint32_t *tags); void traverse_bitmap_commit_list(struct bitmap_index *,
-- 2.49.0.604.gff1f9ca942.dirty