Re: [PATCH 1/1] midx: prevent writing a .bitmap without any objects
From: Derrick Stolee <hidden>
Date: 2022-02-10 14:42:01
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.
quoted hunk ↗ jump to hunk
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