Commit
1bbb92d54019be5317e39182c6b2696f4abd0755
builtin/fsck: move bitmap verification into the packed source
The checks for bitmaps live in `verify_bitmap_files()`, which is called by "builtin/fsck.c". These checks are obviously specific to the "packed" backend. Move the logic into `odb_source_packed_fsck()`. As in preceding commits, this means that we now properly honor both "--connectivity-only" and "--no-full". Furthermore, we drop the dedicated `ERROR_BITMAP` bit and instead use the generic `ERROR_OBJECT` bit. Note that this change also adapts `verify_bitmap_files()` to be focused on a single "packed" source instead of verifying bitmaps from all sources. This change is required as we already know to loop around the sources in `odb_fsck()` itself. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt <ps@pks.im> · 2026-09-11 13:27 UTC · committed by Junio C Hamano
5 files changed,
+23
−23
modified builtin/fsck.c
| @@ -23,7 +23,6 @@ | |||
| 23 | 23 | #include "run-command.h" | |
| 24 | 24 | #include "sparse-index.h" | |
| 25 | 25 | #include "worktree.h" | |
| 26 | - | #include "pack-bitmap.h" | |
| 27 | 26 | ||
| 28 | 27 | #define REACHABLE 0x0001 | |
| 29 | 28 | #define SEEN 0x0002 | |
| @@ -50,7 +49,6 @@ static timestamp_t now; | |||
| 50 | 49 | #define ERROR_REFS 010 | |
| 51 | 50 | #define ERROR_COMMIT_GRAPH 020 | |
| 52 | 51 | #define ERROR_MULTI_PACK_INDEX 040 | |
| 53 | - | #define ERROR_BITMAP 0200 | |
| 54 | 52 | ||
| 55 | 53 | static const char *describe_object(const struct object_id *oid) | |
| 56 | 54 | { | |
| @@ -1068,9 +1066,6 @@ int cmd_fsck(int argc, | |||
| 1068 | 1066 | free_worktrees(worktrees); | |
| 1069 | 1067 | } | |
| 1070 | 1068 | ||
| 1071 | - | if (verify_bitmap_files(repo)) | |
| 1072 | - | errors_found |= ERROR_BITMAP; | |
| 1073 | - | ||
| 1074 | 1069 | check_connectivity(repo); | |
| 1075 | 1070 | ||
| 1076 | 1071 | if (repo->settings.core_commit_graph) { | |
modified odb/source-packed.c
| @@ -909,6 +909,9 @@ static int odb_source_packed_fsck(struct odb_source *source, | |||
| 909 | 909 | if (verify_reverse_indices(packed, opts) < 0) | |
| 910 | 910 | ret = -1; | |
| 911 | 911 | ||
| 912 | + | if (verify_bitmap_files(packed)) | |
| 913 | + | ret = -1; | |
| 914 | + | ||
| 912 | 915 | return ret; | |
| 913 | 916 | } | |
| 914 | 917 | ||
modified pack-bitmap.c
| @@ -3410,28 +3410,22 @@ static int verify_bitmap_file(const struct git_hash_algo *algop, | |||
| 3410 | 3410 | return res; | |
| 3411 | 3411 | } | |
| 3412 | 3412 | ||
| 3413 | - | int verify_bitmap_files(struct repository *r) | |
| 3413 | + | int verify_bitmap_files(struct odb_source_packed *source) | |
| 3414 | 3414 | { | |
| 3415 | - | struct odb_source *source; | |
| 3416 | - | struct packed_git *p; | |
| 3415 | + | struct packfile_list_entry *e; | |
| 3416 | + | struct multi_pack_index *m; | |
| 3417 | 3417 | int res = 0; | |
| 3418 | 3418 | ||
| 3419 | - | for (source = r->objects->sources; source; source = source->next) { | |
| 3420 | - | struct odb_source_files *files = odb_source_files_downcast(source); | |
| 3421 | - | struct multi_pack_index *m = get_multi_pack_index(files->packed); | |
| 3422 | - | char *midx_bitmap_name; | |
| 3423 | - | ||
| 3424 | - | if (!m) | |
| 3425 | - | continue; | |
| 3426 | - | ||
| 3427 | - | midx_bitmap_name = midx_bitmap_filename(m); | |
| 3428 | - | res |= verify_bitmap_file(r->hash_algo, midx_bitmap_name); | |
| 3419 | + | m = get_multi_pack_index(source); | |
| 3420 | + | if (m) { | |
| 3421 | + | char *midx_bitmap_name = midx_bitmap_filename(m); | |
| 3422 | + | res |= verify_bitmap_file(source->base.odb->repo->hash_algo, midx_bitmap_name); | |
| 3429 | 3423 | free(midx_bitmap_name); | |
| 3430 | 3424 | } | |
| 3431 | 3425 | ||
| 3432 | - | repo_for_each_pack(r, p) { | |
| 3433 | - | char *pack_bitmap_name = pack_bitmap_filename(p); | |
| 3434 | - | res |= verify_bitmap_file(r->hash_algo, pack_bitmap_name); | |
| 3426 | + | for (e = packfile_store_get_packs(source); e; e = e->next) { | |
| 3427 | + | char *pack_bitmap_name = pack_bitmap_filename(e->pack); | |
| 3428 | + | res |= verify_bitmap_file(source->base.odb->repo->hash_algo, pack_bitmap_name); | |
| 3435 | 3429 | free(pack_bitmap_name); | |
| 3436 | 3430 | } | |
| 3437 | 3431 | ||
modified pack-bitmap.h
| @@ -205,7 +205,7 @@ int bitmap_is_midx(struct bitmap_index *bitmap_git); | |||
| 205 | 205 | ||
| 206 | 206 | int bitmap_is_preferred_refname(struct repository *r, const char *refname); | |
| 207 | 207 | ||
| 208 | - | int verify_bitmap_files(struct repository *r); | |
| 208 | + | int verify_bitmap_files(struct odb_source_packed *source); | |
| 209 | 209 | ||
| 210 | 210 | struct ewah_bitmap *read_bitmap(const unsigned char *map, | |
| 211 | 211 | size_t map_size, size_t *map_pos); | |
modified t/t5326-multi-pack-bitmaps.sh
| @@ -498,7 +498,15 @@ test_expect_success 'git fsck correctly identifies good and bad bitmaps' ' | |||
| 498 | 498 | corrupt_file "$packbitmap" && | |
| 499 | 499 | test_must_fail git fsck 2>err && | |
| 500 | 500 | test_grep "bitmap file '\''$midxbitmap'\'' has invalid checksum" err && | |
| 501 | - | test_grep "bitmap file '\''$packbitmap'\'' has invalid checksum" err | |
| 501 | + | test_grep "bitmap file '\''$packbitmap'\'' has invalid checksum" err && | |
| 502 | + | ||
| 503 | + | # The bitmap checks are performed with "--no-full", but not with | |
| 504 | + | # "--connectivity-only". | |
| 505 | + | test_must_fail git fsck --no-full 2>err && | |
| 506 | + | test_grep "bitmap file '\''$midxbitmap'\'' has invalid checksum" err && | |
| 507 | + | test_grep "bitmap file '\''$packbitmap'\'' has invalid checksum" err && | |
| 508 | + | git fsck --connectivity-only 2>err && | |
| 509 | + | test_grep ! "invalid checksum" err | |
| 502 | 510 | ' | |
| 503 | 511 | ||
| 504 | 512 | test_expect_success 'corrupt MIDX with bitmap causes fallback' ' | |