Commit
ae7a0ffc25df0103fe28c8504f8120e85edb9181
builtin/fsck: move multi-pack index verification into the packed source
The checks for multi-pack indexes are hosted in `cmd_fsck()` directly. 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_MULTI_PACK_INDEX` bit and instead use the generic `ERROR_OBJECT` bit. 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
3 files changed,
+40
−18
modified builtin/fsck.c
| @@ -48,7 +48,6 @@ static timestamp_t now; | |||
| 48 | 48 | #define ERROR_REACHABLE 02 | |
| 49 | 49 | #define ERROR_REFS 010 | |
| 50 | 50 | #define ERROR_COMMIT_GRAPH 020 | |
| 51 | - | #define ERROR_MULTI_PACK_INDEX 040 | |
| 52 | 51 | ||
| 53 | 52 | static const char *describe_object(const struct object_id *oid) | |
| 54 | 53 | { | |
| @@ -1085,23 +1084,6 @@ int cmd_fsck(int argc, | |||
| 1085 | 1084 | } | |
| 1086 | 1085 | } | |
| 1087 | 1086 | ||
| 1088 | - | if (repo->settings.core_multi_pack_index) { | |
| 1089 | - | struct child_process midx_verify = CHILD_PROCESS_INIT; | |
| 1090 | - | ||
| 1091 | - | for (source = repo->objects->sources; source; source = source->next) { | |
| 1092 | - | child_process_init(&midx_verify); | |
| 1093 | - | midx_verify.git_cmd = 1; | |
| 1094 | - | strvec_pushl(&midx_verify.args, "multi-pack-index", | |
| 1095 | - | "verify", "--object-dir", source->path, NULL); | |
| 1096 | - | if (show_progress) | |
| 1097 | - | strvec_push(&midx_verify.args, "--progress"); | |
| 1098 | - | else | |
| 1099 | - | strvec_push(&midx_verify.args, "--no-progress"); | |
| 1100 | - | if (run_command(&midx_verify)) | |
| 1101 | - | errors_found |= ERROR_MULTI_PACK_INDEX; | |
| 1102 | - | } | |
| 1103 | - | } | |
| 1104 | - | ||
| 1105 | 1087 | free_snapshot_refs(&snap); | |
| 1106 | 1088 | return errors_found; | |
| 1107 | 1089 | } | |
modified odb/source-packed.c
| @@ -14,6 +14,7 @@ | |||
| 14 | 14 | #include "packfile.h" | |
| 15 | 15 | #include "pack-bitmap.h" | |
| 16 | 16 | #include "progress.h" | |
| 17 | + | #include "run-command.h" | |
| 17 | 18 | ||
| 18 | 19 | static int find_pack_entry(struct odb_source_packed *store, | |
| 19 | 20 | const struct object_id *oid, | |
| @@ -897,6 +898,29 @@ static int verify_reverse_indices(struct odb_source_packed *source, | |||
| 897 | 898 | return res; | |
| 898 | 899 | } | |
| 899 | 900 | ||
| 901 | + | static int verify_midx(struct odb_source_packed *source, | |
| 902 | + | struct odb_fsck_options *opts) | |
| 903 | + | { | |
| 904 | + | struct child_process midx_verify = CHILD_PROCESS_INIT; | |
| 905 | + | ||
| 906 | + | prepare_repo_settings(source->base.odb->repo); | |
| 907 | + | if (!source->base.odb->repo->settings.core_multi_pack_index) | |
| 908 | + | return 0; | |
| 909 | + | ||
| 910 | + | child_process_init(&midx_verify); | |
| 911 | + | midx_verify.git_cmd = 1; | |
| 912 | + | strvec_pushl(&midx_verify.args, "multi-pack-index", | |
| 913 | + | "verify", "--object-dir", source->base.path, NULL); | |
| 914 | + | if (opts->flags & ODB_FSCK_PROGRESS) | |
| 915 | + | strvec_push(&midx_verify.args, "--progress"); | |
| 916 | + | else | |
| 917 | + | strvec_push(&midx_verify.args, "--no-progress"); | |
| 918 | + | if (run_command(&midx_verify)) | |
| 919 | + | return -1; | |
| 920 | + | ||
| 921 | + | return 0; | |
| 922 | + | } | |
| 923 | + | ||
| 900 | 924 | static int odb_source_packed_fsck(struct odb_source *source, | |
| 901 | 925 | struct odb_fsck_options *opts) | |
| 902 | 926 | { | |
| @@ -912,6 +936,9 @@ static int odb_source_packed_fsck(struct odb_source *source, | |||
| 912 | 936 | if (verify_bitmap_files(packed)) | |
| 913 | 937 | ret = -1; | |
| 914 | 938 | ||
| 939 | + | if (verify_midx(packed, opts) < 0) | |
| 940 | + | ret = -1; | |
| 941 | + | ||
| 915 | 942 | return ret; | |
| 916 | 943 | } | |
| 917 | 944 | ||
modified t/t5319-multi-pack-index.sh
| @@ -573,6 +573,19 @@ test_expect_success 'verify incorrect checksum' ' | |||
| 573 | 573 | $objdir "incorrect checksum" | |
| 574 | 574 | ' | |
| 575 | 575 | ||
| 576 | + | test_expect_success 'git fsck --no-full checks multi-pack-index, --connectivity-only does not' ' | |
| 577 | + | pos=$(($(wc -c <$objdir/pack/multi-pack-index) - 10)) && | |
| 578 | + | corrupt_midx_and_verify $pos \ | |
| 579 | + | "\377\377\377\377\377\377\377\377\377\377" \ | |
| 580 | + | $objdir "incorrect checksum" && | |
| 581 | + | ||
| 582 | + | test_must_fail git fsck --no-full 2>err && | |
| 583 | + | test_grep "incorrect checksum" err && | |
| 584 | + | ||
| 585 | + | git fsck --connectivity-only 2>err && | |
| 586 | + | test_grep ! "incorrect checksum" err | |
| 587 | + | ' | |
| 588 | + | ||
| 576 | 589 | test_expect_success 'setup for v1-specific fsck tests' ' | |
| 577 | 590 | git -c midx.version=1 multi-pack-index write | |
| 578 | 591 | ' | |