Subject: Re: [PATCH v2 08/10] pack-bitmap: introduce function to check whether a pack is bitmapped

From: Toon Claes <[email-masked]>
Date: Tue, 01 Apr 2025 13:46:09 +0200

Patrick Steinhardt <[email-masked]> writes:

> 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 <[email-masked]>
> Signed-off-by: Patrick Steinhardt <[email-masked]>
> ---
>  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) {

Here, and two lines above, we compare packs by their pointer address,
this doesn't seem to be common practice to me. Or is it in the Git
codebase? Do we expect any problems with this, for example when we stop
using `the_repository`?

-- 
Toon