Skip to content

Commit 9005eb0

Browse files
dyronegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6411cc0 commit 9005eb0

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

pack-bitmap.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
326326
free(bitmap_name);
327327

328328
if (fstat(fd, &st)) {
329+
error_errno(_("cannot fstat bitmap file"));
329330
close(fd);
330331
return -1;
331332
}
@@ -350,8 +351,10 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
350351
if (load_bitmap_header(bitmap_git) < 0)
351352
goto cleanup;
352353

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"));
354356
goto cleanup;
357+
}
355358

356359
if (load_midx_revindex(bitmap_git->midx) < 0) {
357360
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
389392
free(bitmap_name);
390393

391394
if (fstat(fd, &st)) {
395+
error_errno(_("cannot fstat bitmap file"));
392396
close(fd);
393397
return -1;
394398
}

0 commit comments

Comments
 (0)