Skip to content

Commit 9b7e531

Browse files
committed
Merge branch 'tb/midx-no-bitmap-for-no-objects'
When there is no object to write .bitmap file for, "git multi-pack-index" triggered an error, instead of just skipping, which has been corrected. * tb/midx-no-bitmap-for-no-objects: midx: prevent writing a .bitmap without any objects
2 parents 18636af + eb57277 commit 9b7e531

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

midx.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,9 @@ static int write_midx_bitmap(char *midx_name, unsigned char *midx_hash,
10771077
char *bitmap_name = xstrfmt("%s-%s.bitmap", midx_name, hash_to_hex(midx_hash));
10781078
int ret;
10791079

1080+
if (!ctx->entries_nr)
1081+
BUG("cannot write a bitmap without any objects");
1082+
10801083
if (flags & MIDX_WRITE_BITMAP_HASH_CACHE)
10811084
options |= BITMAP_OPT_HASH_CACHE;
10821085

@@ -1401,6 +1404,12 @@ static int write_midx_internal(const char *object_dir,
14011404
goto cleanup;
14021405
}
14031406

1407+
if (!ctx.entries_nr) {
1408+
if (flags & MIDX_WRITE_BITMAP)
1409+
warning(_("refusing to write multi-pack .bitmap without any objects"));
1410+
flags &= ~(MIDX_WRITE_REV_INDEX | MIDX_WRITE_BITMAP);
1411+
}
1412+
14041413
cf = init_chunkfile(f);
14051414

14061415
add_chunk(cf, MIDX_CHUNKID_PACKNAMES, pack_name_concat_len,

t/t5326-multi-pack-bitmaps.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,28 @@ test_expect_success 'hash-cache values are propagated from pack bitmaps' '
266266
)
267267
'
268268

269+
test_expect_success 'no .bitmap is written without any objects' '
270+
rm -fr repo &&
271+
git init repo &&
272+
test_when_finished "rm -fr repo" &&
273+
(
274+
cd repo &&
275+
276+
empty="$(git pack-objects $objdir/pack/pack </dev/null)" &&
277+
cat >packs <<-EOF &&
278+
pack-$empty.idx
279+
EOF
280+
281+
git multi-pack-index write --bitmap --stdin-packs \
282+
<packs 2>err &&
283+
284+
grep "bitmap without any objects" err &&
285+
286+
test_path_is_file $midx &&
287+
test_path_is_missing $midx-$(midx_checksum $objdir).bitmap
288+
)
289+
'
290+
269291
test_expect_success 'graceful fallback when missing reverse index' '
270292
rm -fr repo &&
271293
git init repo &&

0 commit comments

Comments
 (0)