Commit

426d291b6095a51ee249b70a088f99cd67d4bb27

builtin/fsck: move reverse index verification into the packed source

The checks for reverse indexes live in `check_pack_rev_indexes()`, which
is hosted in "builtin/fsck.c". These checks are obviously specific to
the "packed" backend.

Move the logic into `odb_source_packed_fsck()`. As in the preceding
commit, drop the dedicated `ERROR_PACK_REV_INDEX` bit and instead use
the generic `ERROR_OBJECT` bit.

Note that this changes behaviour in two ways:

  - The checks are now skipped when "--connectivity-only" was passed.
    This is because we don't even run `odb_fsck()` at all when that
    flag has been passed by the user, and not verifying data structures
    of the object database matches the documented intent of that flag,
    which is to only check the connectivity of reachable objects.

  - The checks are now skipped for non-local sources when "--no-full"
    was passed. This is, again, in line with the documented intent of
    that flag.

Add a test to cast these semantics into stone.

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
3 files changed, +47 −37
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-revindex.h"
27 26 #include "pack-bitmap.h"
28 27
29 28 #define REACHABLE 0x0001
@@ -51,7 +50,6 @@ static timestamp_t now;
51 50 #define ERROR_REFS 010
52 51 #define ERROR_COMMIT_GRAPH 020
53 52 #define ERROR_MULTI_PACK_INDEX 040
54 - #define ERROR_PACK_REV_INDEX 0100
55 53 #define ERROR_BITMAP 0200
56 54
57 55 static const char *describe_object(const struct object_id *oid)
@@ -890,40 +888,6 @@ static int mark_object_for_connectivity(const struct object_id *oid,
890 888 return 0;
891 889 }
892 890
893 - static int check_pack_rev_indexes(struct repository *r, int show_progress)
894 - {
895 - struct progress *progress = NULL;
896 - struct packed_git *p;
897 - uint32_t pack_count = 0;
898 - int res = 0;
899 -
900 - if (show_progress) {
901 - repo_for_each_pack(r, p)
902 - pack_count++;
903 - progress = start_delayed_progress(r,
904 - "Verifying reverse pack-indexes", pack_count);
905 - pack_count = 0;
906 - }
907 -
908 - repo_for_each_pack(r, p) {
909 - int load_error = load_pack_revindex_from_disk(p);
910 -
911 - if (load_error < 0) {
912 - error(_("unable to load rev-index for pack '%s'"), p->pack_name);
913 - res = ERROR_PACK_REV_INDEX;
914 - } else if (!load_error &&
915 - !load_pack_revindex(r, p) &&
916 - verify_pack_revindex(p)) {
917 - error(_("invalid rev-index for pack '%s'"), p->pack_name);
918 - res = ERROR_PACK_REV_INDEX;
919 - }
920 - display_progress(progress, ++pack_count);
921 - }
922 - stop_progress(&progress);
923 -
924 - return res;
925 - }
926 -
927 891 static void fsck_refs(struct repository *r)
928 892 {
929 893 struct child_process refs_verify = CHILD_PROCESS_INIT;
@@ -1104,7 +1068,6 @@ int cmd_fsck(int argc,
1104 1068 free_worktrees(worktrees);
1105 1069 }
1106 1070
1107 - errors_found |= check_pack_rev_indexes(repo, show_progress);
1108 1071 if (verify_bitmap_files(repo))
1109 1072 errors_found |= ERROR_BITMAP;
1110 1073
modified odb/source-packed.c
@@ -10,6 +10,7 @@
10 10 #include "odb/source-packed.h"
11 11 #include "odb/streaming.h"
12 12 #include "pack.h"
13 + #include "pack-revindex.h"
13 14 #include "packfile.h"
14 15 #include "pack-bitmap.h"
15 16 #include "progress.h"
@@ -861,6 +862,41 @@ static int verify_packs(struct odb_source_packed *source,
861 862 return ret;
862 863 }
863 864
865 + static int verify_reverse_indices(struct odb_source_packed *source,
866 + struct odb_fsck_options *opts)
867 + {
868 + struct progress *progress = NULL;
869 + struct packfile_list_entry *e;
870 + uint32_t pack_count = 0;
871 + int res = 0;
872 +
873 + if (opts->flags & ODB_FSCK_PROGRESS) {
874 + for (e = packfile_store_get_packs(source); e; e = e->next)
875 + pack_count++;
876 + progress = start_delayed_progress(source->base.odb->repo,
877 + "Verifying reverse pack-indexes", pack_count);
878 + pack_count = 0;
879 + }
880 +
881 + for (e = packfile_store_get_packs(source); e; e = e->next) {
882 + int load_error = load_pack_revindex_from_disk(e->pack);
883 +
884 + if (load_error < 0) {
885 + error(_("unable to load rev-index for pack '%s'"), e->pack->pack_name);
886 + res = -1;
887 + } else if (!load_error &&
888 + !load_pack_revindex(source->base.odb->repo, e->pack) &&
889 + verify_pack_revindex(e->pack)) {
890 + error(_("invalid rev-index for pack '%s'"), e->pack->pack_name);
891 + res = -1;
892 + }
893 + display_progress(progress, ++pack_count);
894 + }
895 + stop_progress(&progress);
896 +
897 + return res;
898 + }
899 +
864 900 static int odb_source_packed_fsck(struct odb_source *source,
865 901 struct odb_fsck_options *opts)
866 902 {
@@ -870,6 +906,9 @@ static int odb_source_packed_fsck(struct odb_source *source,
870 906 if ((opts->flags & ODB_FSCK_FULL) && verify_packs(packed, opts) < 0)
871 907 ret = -1;
872 908
909 + if (verify_reverse_indices(packed, opts) < 0)
910 + ret = -1;
911 +
873 912 return ret;
874 913 }
875 914
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