pack-bitmap.c: using error() instead of silently returning -1

In "open_pack_bitmap_1()" and "open_midx_bitmap_1()", it's better to return error() instead of "-1" when some unexpected error occurs like "stat bitmap file failed", "bitmap header is invalid" or "checksum mismatch", etc. There are places where we do not replace, such as when the bitmap does not exist (no bitmap in repository is allowed) or when another bitmap has already been opened (in which case it should be a warning rather than an error). Signed-off-by: Teng Long <dyroneteng@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Teng Long committed Jul 19, 2022 at 00:46 UTC 9005eb021ad4defbb3635c2aa6049e9300a25798
1 file changed +5 -1
pack-bitmap.c
+5 -1
@@ -326,6 +326,7 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
326 free(bitmap_name);
327
328 if (fstat(fd, &st)) {
329 + error_errno(_("cannot fstat bitmap file"));
330 close(fd);
331 return -1;
332 }
@@ -350,8 +351,10 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
351 if (load_bitmap_header(bitmap_git) < 0)
352 goto cleanup;
353
353 - if (!hasheq(get_midx_checksum(bitmap_git->midx), bitmap_git->checksum))
354 + if (!hasheq(get_midx_checksum(bitmap_git->midx), bitmap_git->checksum)) {
355 + error(_("checksum doesn't match in MIDX and bitmap"));
356 goto cleanup;
357 + }
358
359 if (load_midx_revindex(bitmap_git->midx) < 0) {
360 warning(_("multi-pack bitmap is missing required reverse index"));
@@ -389,6 +392,7 @@ static int open_pack_bitmap_1(struct bitmap_index *bitmap_git, struct packed_git
392 free(bitmap_name);
393
394 if (fstat(fd, &st)) {
395 + error_errno(_("cannot fstat bitmap file"));
396 close(fd);
397 return -1;
398 }