Compare

dbdea7a91889cf4bfc2e64f59e9889f71f3a258e..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

Browse files
14 files changed, +287 −131
modified builtin/fsck.c
@@ -7,7 +7,6 @@
7 7 #include "blob.h"
8 8 #include "tag.h"
9 9 #include "refs.h"
10 - #include "pack.h"
11 10 #include "cache-tree.h"
12 11 #include "fsck.h"
13 12 #include "parse-options.h"
@@ -24,8 +23,6 @@
24 23 #include "run-command.h"
25 24 #include "sparse-index.h"
26 25 #include "worktree.h"
27 - #include "pack-revindex.h"
28 - #include "pack-bitmap.h"
29 26
30 27 #define REACHABLE 0x0001
31 28 #define SEEN 0x0002
@@ -37,10 +34,8 @@ static int show_root;
37 34 static int show_tags;
38 35 static int show_unreachable;
39 36 static int include_reflogs = 1;
40 - static int check_full = 1;
41 37 static int connectivity_only;
42 38 static int check_strict;
43 - static int keep_cache_objects;
44 39 static struct fsck_options fsck_walk_options;
45 40 static struct fsck_options fsck_obj_options;
46 41 static int errors_found;
@@ -48,17 +43,11 @@ static int write_lost_and_found;
48 43 static int verbose;
49 44 static int show_progress = -1;
50 45 static int show_dangling = 1;
51 - static int name_objects;
52 - static int check_references = 1;
53 46 static timestamp_t now;
54 47 #define ERROR_OBJECT 01
55 48 #define ERROR_REACHABLE 02
56 - #define ERROR_PACK 04
57 49 #define ERROR_REFS 010
58 50 #define ERROR_COMMIT_GRAPH 020
59 - #define ERROR_MULTI_PACK_INDEX 040
60 - #define ERROR_PACK_REV_INDEX 0100
61 - #define ERROR_BITMAP 0200
62 51
63 52 static const char *describe_object(const struct object_id *oid)
64 53 {
@@ -896,40 +885,6 @@ static int mark_object_for_connectivity(const struct object_id *oid,
896 885 return 0;
897 886 }
898 887
899 - static int check_pack_rev_indexes(struct repository *r, int show_progress)
900 - {
901 - struct progress *progress = NULL;
902 - struct packed_git *p;
903 - uint32_t pack_count = 0;
904 - int res = 0;
905 -
906 - if (show_progress) {
907 - repo_for_each_pack(r, p)
908 - pack_count++;
909 - progress = start_delayed_progress(r,
910 - "Verifying reverse pack-indexes", pack_count);
911 - pack_count = 0;
912 - }
913 -
914 - repo_for_each_pack(r, p) {
915 - int load_error = load_pack_revindex_from_disk(p);
916 -
917 - if (load_error < 0) {
918 - error(_("unable to load rev-index for pack '%s'"), p->pack_name);
919 - res = ERROR_PACK_REV_INDEX;
920 - } else if (!load_error &&
921 - !load_pack_revindex(r, p) &&
922 - verify_pack_revindex(p)) {
923 - error(_("invalid rev-index for pack '%s'"), p->pack_name);
924 - res = ERROR_PACK_REV_INDEX;
925 - }
926 - display_progress(progress, ++pack_count);
927 - }
928 - stop_progress(&progress);
929 -
930 - return res;
931 - }
932 -
933 888 static void fsck_refs(struct repository *r)
934 889 {
935 890 struct child_process refs_verify = CHILD_PROCESS_INIT;
@@ -964,30 +919,38 @@ static char const * const fsck_usage[] = {
964 919 NULL
965 920 };
966 921
967 - static struct option fsck_opts[] = {
968 - OPT__VERBOSE(&verbose, N_("be verbose")),
969 - OPT_BOOL(0, "unreachable", &show_unreachable, N_("show unreachable objects")),
970 - OPT_BOOL(0, "dangling", &show_dangling, N_("show dangling objects")),
971 - OPT_BOOL(0, "tags", &show_tags, N_("report tags")),
972 - OPT_BOOL(0, "root", &show_root, N_("report root nodes")),
973 - OPT_BOOL(0, "cache", &keep_cache_objects, N_("make index objects head nodes")),
974 - OPT_BOOL(0, "reflogs", &include_reflogs, N_("make reflogs head nodes (default)")),
975 - OPT_BOOL(0, "full", &check_full, N_("also consider packs and alternate objects")),
976 - OPT_BOOL(0, "connectivity-only", &connectivity_only, N_("check only connectivity")),
977 - OPT_BOOL(0, "strict", &check_strict, N_("enable more strict checking")),
978 - OPT_BOOL(0, "lost-found", &write_lost_and_found,
979 - N_("write dangling objects in .git/lost-found")),
980 - OPT_BOOL(0, "progress", &show_progress, N_("show progress")),
981 - OPT_BOOL(0, "name-objects", &name_objects, N_("show verbose names for reachable objects")),
982 - OPT_BOOL(0, "references", &check_references, N_("check reference database consistency")),
983 - OPT_END(),
984 - };
985 -
986 922 int cmd_fsck(int argc,
987 923 const char **argv,
988 924 const char *prefix,
989 925 struct repository *repo)
990 926 {
927 + struct odb_fsck_options odb_fsck_opts = {
928 + .flags = ODB_FSCK_FULL,
929 + .object_cb = fsck_obj_buffer,
930 + .object_payload = repo,
931 + };
932 + int keep_cache_objects = 0;
933 + int name_objects = 0;
934 + int check_references = 1;
935 + struct option fsck_opts[] = {
936 + OPT__VERBOSE(&verbose, N_("be verbose")),
937 + OPT_BOOL(0, "unreachable", &show_unreachable, N_("show unreachable objects")),
938 + OPT_BOOL(0, "dangling", &show_dangling, N_("show dangling objects")),
939 + OPT_BOOL(0, "tags", &show_tags, N_("report tags")),
940 + OPT_BOOL(0, "root", &show_root, N_("report root nodes")),
941 + OPT_BOOL(0, "cache", &keep_cache_objects, N_("make index objects head nodes")),
942 + OPT_BOOL(0, "reflogs", &include_reflogs, N_("make reflogs head nodes (default)")),
943 + OPT_BIT(0, "full", &odb_fsck_opts.flags,
944 + N_("also consider packs and alternate objects"), ODB_FSCK_FULL),
945 + OPT_BOOL(0, "connectivity-only", &connectivity_only, N_("check only connectivity")),
946 + OPT_BOOL(0, "strict", &check_strict, N_("enable more strict checking")),
947 + OPT_BOOL(0, "lost-found", &write_lost_and_found,
948 + N_("write dangling objects in .git/lost-found")),
949 + OPT_BOOL(0, "progress", &show_progress, N_("show progress")),
950 + OPT_BOOL(0, "name-objects", &name_objects, N_("show verbose names for reachable objects")),
951 + OPT_BOOL(0, "references", &check_references, N_("check reference database consistency")),
952 + OPT_END(),
953 + };
991 954 struct odb_source *source;
992 955 struct snapshot snap = {
993 956 .nr = 0,
@@ -1017,9 +980,11 @@ int cmd_fsck(int argc,
1017 980 show_progress = isatty(2);
1018 981 if (verbose)
1019 982 show_progress = 0;
983 + if (show_progress)
984 + odb_fsck_opts.flags |= ODB_FSCK_PROGRESS;
1020 985
1021 986 if (write_lost_and_found) {
1022 - check_full = 1;
987 + odb_fsck_opts.flags |= ODB_FSCK_FULL;
1023 988 include_reflogs = 0;
1024 989 }
1025 990
@@ -1048,34 +1013,11 @@ int cmd_fsck(int argc,
1048 1013 mark_object_for_connectivity, repo, 0);
1049 1014 } else {
1050 1015 for (source = repo->objects->sources; source; source = source->next)
1051 - fsck_source(repo, source);
1052 -
1053 - if (check_full) {
1054 - struct packed_git *p;
1055 - uint32_t total = 0, count = 0;
1056 - struct progress *progress = NULL;
1057 -
1058 - if (show_progress) {
1059 - repo_for_each_pack(repo, p) {
1060 - if (open_pack_index(p))
1061 - continue;
1062 - total += p->num_objects;
1063 - }
1064 -
1065 - progress = start_progress(repo,
1066 - _("Checking objects"), total);
1067 - }
1016 + if ((odb_fsck_opts.flags & ODB_FSCK_FULL) || source->local)
1017 + fsck_source(repo, source);
1068 1018
1069 - repo_for_each_pack(repo, p) {
1070 - /* verify gives error messages itself */
1071 - if (verify_pack(repo,
1072 - p, fsck_obj_buffer, repo,
1073 - progress, count))
1074 - errors_found |= ERROR_PACK;
1075 - count += p->num_objects;
1076 - }
1077 - stop_progress(&progress);
1078 - }
1019 + if (odb_fsck(repo->objects, &odb_fsck_opts) < 0)
1020 + errors_found |= ERROR_OBJECT;
1079 1021
1080 1022 if (fsck_finish(&fsck_obj_options))
1081 1023 errors_found |= ERROR_OBJECT;
@@ -1123,10 +1065,6 @@ int cmd_fsck(int argc,
1123 1065 free_worktrees(worktrees);
1124 1066 }
1125 1067
1126 - errors_found |= check_pack_rev_indexes(repo, show_progress);
1127 - if (verify_bitmap_files(repo))
1128 - errors_found |= ERROR_BITMAP;
1129 -
1130 1068 check_connectivity(repo);
1131 1069
1132 1070 if (repo->settings.core_commit_graph) {
@@ -1146,23 +1084,6 @@ int cmd_fsck(int argc,
1146 1084 }
1147 1085 }
1148 1086
1149 - if (repo->settings.core_multi_pack_index) {
1150 - struct child_process midx_verify = CHILD_PROCESS_INIT;
1151 -
1152 - for (source = repo->objects->sources; source; source = source->next) {
1153 - child_process_init(&midx_verify);
1154 - midx_verify.git_cmd = 1;
1155 - strvec_pushl(&midx_verify.args, "multi-pack-index",
1156 - "verify", "--object-dir", source->path, NULL);
1157 - if (show_progress)
1158 - strvec_push(&midx_verify.args, "--progress");
1159 - else
1160 - strvec_push(&midx_verify.args, "--no-progress");
1161 - if (run_command(&midx_verify))
1162 - errors_found |= ERROR_MULTI_PACK_INDEX;
1163 - }
1164 - }
1165 -
1166 1087 free_snapshot_refs(&snap);
1167 1088 return errors_found;
1168 1089 }
modified odb.c
@@ -1177,3 +1177,11 @@ void odb_reprepare(struct object_database *o)
1177 1177 {
1178 1178 odb_prepare(o, ODB_PREPARE_FLUSH_CACHES);
1179 1179 }
1180 +
1181 + int odb_fsck(struct object_database *odb, struct odb_fsck_options *options)
1182 + {
1183 + int ret = 0;
1184 + for (struct odb_source *source = odb->sources; source; source = source->next)
1185 + ret |= odb_source_fsck(source, options);
1186 + return ret;
1187 + }
modified odb.h
@@ -206,6 +206,36 @@ void odb_prepare(struct object_database *o, enum odb_prepare_flags flags);
206 206 /* Equivalent to `odb_prepare(o, ODB_PREPARE_FLUSH_CACHES)`. */
207 207 void odb_reprepare(struct object_database *o);
208 208
209 + enum odb_fsck_flags {
210 + /*
211 + * If set, perform a full consistency check for the full object
212 + * database, including all of its sources and the contents of their
213 + * optimized formats. Otherwise, only check the local source, and
214 + * restrict checks of its optimized formats to cheap structural
215 + * verification of their metadata.
216 + */
217 + ODB_FSCK_FULL = (1 << 0),
218 +
219 + /* Display a progress meter, if sensible. */
220 + ODB_FSCK_PROGRESS = (1 << 1),
221 + };
222 +
223 + /* Options that shall be passed to `odb_fsck()`. */
224 + struct odb_fsck_options {
225 + enum odb_fsck_flags flags;
226 +
227 + int (*object_cb)(const struct object_id *oid, enum object_type type,
228 + unsigned long size, void *buffer, int *eaten, void *cb_data);
229 + void *object_payload;
230 + };
231 +
232 + /*
233 + * Run backend-specific integrity checks on all object sources. Each source
234 + * performs the checks appropriate to its type. Returns 0 on success, a
235 + * negative error code otherwise.
236 + */
237 + int odb_fsck(struct object_database *odb, struct odb_fsck_options *opts);
238 +
209 239 /*
210 240 * Find source by its object directory path. Returns a `NULL` pointer in case
211 241 * the source could not be found.
modified odb/source-files.c
@@ -893,6 +893,21 @@ static int odb_source_files_generate_pack(struct odb_source *source UNUSED,
893 893 return 0;
894 894 }
895 895
896 + static int odb_source_files_fsck(struct odb_source *source,
897 + struct odb_fsck_options *opts)
898 + {
899 + struct odb_source_files *files = odb_source_files_downcast(source);
900 + int ret = 0;
901 +
902 + if (!(opts->flags & ODB_FSCK_FULL) && !source->local)
903 + return 0;
904 +
905 + ret |= odb_source_fsck(&files->loose->base, opts);
906 + ret |= odb_source_fsck(&files->packed->base, opts);
907 +
908 + return ret;
909 + }
910 +
896 911 struct odb_source_files *odb_source_files_new(struct object_database *odb,
897 912 const char *path,
898 913 bool local)
@@ -908,6 +923,7 @@ struct odb_source_files *odb_source_files_new(struct object_database *odb,
908 923 files->base.close = odb_source_files_close;
909 924 files->base.create_on_disk = odb_source_files_create_on_disk;
910 925 files->base.prepare = odb_source_files_prepare;
926 + files->base.fsck = odb_source_files_fsck;
911 927 files->base.read_object_info = odb_source_files_read_object_info;
912 928 files->base.read_object_stream = odb_source_files_read_object_stream;
913 929 files->base.for_each_object = odb_source_files_for_each_object;
modified odb/source-inmemory.c
@@ -1,6 +1,7 @@
1 1 #include "git-compat-util.h"
2 2 #include "object-file.h"
3 3 #include "odb.h"
4 + #include "fsck.h"
4 5 #include "odb/source-inmemory.h"
5 6 #include "odb/streaming.h"
6 7 #include "oidtree.h"
@@ -368,6 +369,12 @@ static void odb_source_inmemory_free(struct odb_source *source)
368 369 free(inmemory);
369 370 }
370 371
372 + static int odb_source_inmemory_fsck(struct odb_source *source UNUSED,
373 + struct odb_fsck_options *opts UNUSED)
374 + {
375 + return 0;
376 + }
377 +
371 378 struct odb_source_inmemory *odb_source_inmemory_new(struct object_database *odb)
372 379 {
373 380 struct odb_source_inmemory *source;
@@ -378,6 +385,7 @@ struct odb_source_inmemory *odb_source_inmemory_new(struct object_database *odb)
378 385 source->base.free = odb_source_inmemory_free;
379 386 source->base.close = odb_source_inmemory_close;
380 387 source->base.prepare = odb_source_inmemory_prepare;
388 + source->base.fsck = odb_source_inmemory_fsck;
381 389 source->base.read_object_info = odb_source_inmemory_read_object_info;
382 390 source->base.read_object_stream = odb_source_inmemory_read_object_stream;
383 391 source->base.for_each_object = odb_source_inmemory_for_each_object;
modified odb/source-loose.c
@@ -1031,6 +1031,12 @@ static void odb_source_loose_free(struct odb_source *source)
1031 1031 free(loose);
1032 1032 }
1033 1033
1034 + static int odb_source_loose_fsck(struct odb_source *source UNUSED,
1035 + struct odb_fsck_options *opts UNUSED)
1036 + {
1037 + return 0;
1038 + }
1039 +
1034 1040 struct odb_source_loose *odb_source_loose_new(struct object_database *odb,
1035 1041 const char *path,
1036 1042 bool local)
@@ -1043,6 +1049,7 @@ struct odb_source_loose *odb_source_loose_new(struct object_database *odb,
1043 1049 loose->base.free = odb_source_loose_free;
1044 1050 loose->base.close = odb_source_loose_close;
1045 1051 loose->base.prepare = odb_source_loose_prepare;
1052 + loose->base.fsck = odb_source_loose_fsck;
1046 1053 loose->base.read_object_info = odb_source_loose_read_object_info;
1047 1054 loose->base.read_object_stream = odb_source_loose_read_object_stream;
1048 1055 loose->base.for_each_object = odb_source_loose_for_each_object;
modified odb/source-packed.c
@@ -2,14 +2,19 @@
2 2 #include "abspath.h"
3 3 #include "chdir-notify.h"
4 4 #include "dir.h"
5 + #include "fsck.h"
5 6 #include "git-zlib.h"
6 7 #include "list-objects-filter-options.h"
7 8 #include "mergesort.h"
8 9 #include "midx.h"
9 10 #include "odb/source-packed.h"
10 11 #include "odb/streaming.h"
12 + #include "pack.h"
13 + #include "pack-revindex.h"
11 14 #include "packfile.h"
12 15 #include "pack-bitmap.h"
16 + #include "progress.h"
17 + #include "run-command.h"
13 18
14 19 static int find_pack_entry(struct odb_source_packed *store,
15 20 const struct object_id *oid,
@@ -826,6 +831,117 @@ static void odb_source_packed_free(struct odb_source *source)
826 831 free(packed);
827 832 }
828 833
834 + static int verify_packs(struct odb_source_packed *source,
835 + struct odb_fsck_options *opts)
836 + {
837 + struct progress *progress = NULL;
838 + struct packfile_list_entry *e;
839 + uint32_t total = 0, count = 0;
840 + int ret = 0;
841 +
842 + if (opts->flags & ODB_FSCK_PROGRESS) {
843 + for (e = packfile_store_get_packs(source); e; e = e->next) {
844 + if (open_pack_index(e->pack))
845 + continue;
846 + total += e->pack->num_objects;
847 + }
848 +
849 + progress = start_progress(source->base.odb->repo,
850 + _("Checking objects"), total);
851 + }
852 +
853 + for (e = packfile_store_get_packs(source); e; e = e->next) {
854 + /* verify gives error messages itself */
855 + if (verify_pack(source->base.odb->repo, e->pack,
856 + opts->object_cb, opts->object_payload,
857 + progress, count))
858 + ret = -1;
859 + count += e->pack->num_objects;
860 + }
861 + stop_progress(&progress);
862 +
863 + return ret;
864 + }
865 +
866 + static int verify_reverse_indices(struct odb_source_packed *source,
867 + struct odb_fsck_options *opts)
868 + {
869 + struct progress *progress = NULL;
870 + struct packfile_list_entry *e;
871 + uint32_t pack_count = 0;
872 + int res = 0;
873 +
874 + if (opts->flags & ODB_FSCK_PROGRESS) {
875 + for (e = packfile_store_get_packs(source); e; e = e->next)
876 + pack_count++;
877 + progress = start_delayed_progress(source->base.odb->repo,
878 + "Verifying reverse pack-indexes", pack_count);
879 + pack_count = 0;
880 + }
881 +
882 + for (e = packfile_store_get_packs(source); e; e = e->next) {
883 + int load_error = load_pack_revindex_from_disk(e->pack);
884 +
885 + if (load_error < 0) {
886 + error(_("unable to load rev-index for pack '%s'"), e->pack->pack_name);
887 + res = -1;
888 + } else if (!load_error &&
889 + !load_pack_revindex(source->base.odb->repo, e->pack) &&
890 + verify_pack_revindex(e->pack)) {
891 + error(_("invalid rev-index for pack '%s'"), e->pack->pack_name);
892 + res = -1;
893 + }
894 + display_progress(progress, ++pack_count);
895 + }
896 + stop_progress(&progress);
897 +
898 + return res;
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 +
924 + static int odb_source_packed_fsck(struct odb_source *source,
925 + struct odb_fsck_options *opts)
926 + {
927 + struct odb_source_packed *packed = odb_source_packed_downcast(source);
928 + int ret = 0;
929 +
930 + if ((opts->flags & ODB_FSCK_FULL) && verify_packs(packed, opts) < 0)
931 + ret = -1;
932 +
933 + if (verify_reverse_indices(packed, opts) < 0)
934 + ret = -1;
935 +
936 + if (verify_bitmap_files(packed))
937 + ret = -1;
938 +
939 + if (verify_midx(packed, opts) < 0)
940 + ret = -1;
941 +
942 + return ret;
943 + }
944 +
829 945 struct odb_source_packed *odb_source_packed_new(struct object_database *odb,
830 946 const char *path,
831 947 bool local)
@@ -839,6 +955,7 @@ struct odb_source_packed *odb_source_packed_new(struct object_database *odb,
839 955 packed->base.free = odb_source_packed_free;
840 956 packed->base.close = odb_source_packed_close;
841 957 packed->base.prepare = odb_source_packed_prepare;
958 + packed->base.fsck = odb_source_packed_fsck;
842 959 packed->base.read_object_info = odb_source_packed_read_object_info;
843 960 packed->base.read_object_stream = odb_source_packed_read_object_stream;
844 961 packed->base.for_each_object = odb_source_packed_for_each_object;
modified odb/source.h
@@ -320,6 +320,17 @@ struct odb_source {
320 320 int (*generate_pack)(struct odb_source *source,
321 321 struct odb_pack_generator **out,
322 322 const struct odb_generate_pack_options *opts);
323 +
324 + /*
325 + * This callback is expected to check the integrity of the object source
326 + * and report any errors found via the fsck options. The checks performed
327 + * are backend-specific.
328 + *
329 + * The callback is expected to return 0 on success, a negative error
330 + * code otherwise.
331 + */
332 + int (*fsck)(struct odb_source *source,
333 + struct odb_fsck_options *options);
323 334 };
324 335
325 336 /*
@@ -588,4 +599,14 @@ static inline int odb_source_generate_pack(struct odb_source *source,
588 599 return source->generate_pack(source, out, opts);
589 600 }
590 601
602 + /*
603 + * Check the integrity of the object database source. The checks performed
604 + * are backend-specific. Returns 0 on success, a negative error code otherwise.
605 + */
606 + static inline int odb_source_fsck(struct odb_source *source,
607 + struct odb_fsck_options *opts)
608 + {
609 + return source->fsck(source, opts);
610 + }
611 +
591 612 #endif
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/t1450-fsck.sh
@@ -844,6 +844,11 @@ test_expect_success 'alternate objects are correctly blamed' '
844 844 echo "../../alt.git/objects" >.git/objects/info/alternates &&
845 845 mkdir alt.git/objects/$(dirname $path) &&
846 846 >alt.git/objects/$(dirname $path)/$(basename $path) &&
847 +
848 + # Without "--full", only the local object source is checked.
849 + git fsck --no-full >out 2>&1 &&
850 + test_must_be_empty out &&
851 +
847 852 test_must_fail git fsck >out 2>&1 &&
848 853 test_grep alt.git out
849 854 '
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 '
modified t/t5325-reverse-index.sh
@@ -204,4 +204,12 @@ test_expect_success 'fsck catches invalid header: hash function' '
204 204 "reverse-index file .* has unsupported hash id"
205 205 '
206 206
207 + test_expect_success 'fsck --no-full checks rev-index, --connectivity-only does not' '
208 + test_must_fail git -C corrupt fsck --no-full 2>err &&
209 + test_grep "has unsupported hash id" err &&
210 +
211 + git -C corrupt fsck --connectivity-only 2>err &&
212 + test_grep ! "has unsupported hash id" err
213 + '
214 +
207 215 test_done
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' '