Re: [PATCH 1/1] midx: prevent writing a .bitmap without any objects
- From
Derrick Stolee <stolee@gmail.com>
- Date
- Feb 10, 2022, 14:41 UTC
- Message-ID
- <748a2358-7bdf-5b28-09f9-5c4b266a3b52@gmail.com>
- In-Reply-To
- <abc67d757cb6b244cf54b7b030985180ce134724.1644434802.git.me@ttaylorr.com>
On 2/9/2022 2:26 PM, Taylor Blau wrote:
> When trying to write a MIDX, we already prevent the case where there > weren't any packs present, and thus we would have written an empty MIDX.
Show 24 quoted lines
> diff --git a/midx.c b/midx.c
> index 6e6cb0eb04..865170bad0 100644
> --- a/midx.c
> +++ b/midx.c
> @@ -1077,6 +1077,9 @@ static int write_midx_bitmap(char *midx_name, unsigned char *midx_hash,
> char *bitmap_name = xstrfmt("%s-%s.bitmap", midx_name, hash_to_hex(midx_hash));
> int ret;
>
> + if (!ctx->entries_nr)
> + BUG("cannot write a bitmap without any objects");
> +
> if (flags & MIDX_WRITE_BITMAP_HASH_CACHE)
> options |= BITMAP_OPT_HASH_CACHE;
>
> @@ -1401,6 +1404,12 @@ static int write_midx_internal(const char *object_dir,
> goto cleanup;
> }
>
> + if (!ctx.entries_nr) {
> + if (flags & MIDX_WRITE_BITMAP)
> + warning(_("refusing to write multi-pack .bitmap without any objects"));
> + flags &= ~(MIDX_WRITE_REV_INDEX | MIDX_WRITE_BITMAP);
> + }
> +This patch looks good to me. The code change is simple and the test is clear.
Thanks, -Stolee