]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pack-bitmap.c: using error() instead of silently returning -1
authorTeng Long <dyroneteng@gmail.com>
Mon, 18 Jul 2022 16:46:04 +0000 (00:46 +0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 18 Jul 2022 18:20:52 +0000 (11:20 -0700)
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>
pack-bitmap.c

index da3df1cfec421ff0d95c6a0dfa9941dda28c9a40..6ff23f096ddb3b3dcd0e3b023a221c4ca482dc11 100644 (file)
@@ -326,6 +326,7 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
        free(bitmap_name);
 
        if (fstat(fd, &st)) {
+               error_errno(_("cannot fstat bitmap file"));
                close(fd);
                return -1;
        }
@@ -350,8 +351,10 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
        if (load_bitmap_header(bitmap_git) < 0)
                goto cleanup;
 
-       if (!hasheq(get_midx_checksum(bitmap_git->midx), bitmap_git->checksum))
+       if (!hasheq(get_midx_checksum(bitmap_git->midx), bitmap_git->checksum)) {
+               error(_("checksum doesn't match in MIDX and bitmap"));
                goto cleanup;
+       }
 
        if (load_midx_revindex(bitmap_git->midx) < 0) {
                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
        free(bitmap_name);
 
        if (fstat(fd, &st)) {
+               error_errno(_("cannot fstat bitmap file"));
                close(fd);
                return -1;
        }