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>
jch
Patrick Steinhardt 2026-08-31 08:46:23 +02:00 committed by Junio C Hamano
parent b424879085
commit 31d10704d4
3 changed files with 40 additions and 18 deletions

View File

@ -48,7 +48,6 @@ static timestamp_t now;
#define ERROR_REACHABLE 02
#define ERROR_REFS 010
#define ERROR_COMMIT_GRAPH 020
#define ERROR_MULTI_PACK_INDEX 040

static const char *describe_object(const struct object_id *oid)
{
@ -1085,23 +1084,6 @@ int cmd_fsck(int argc,
}
}

if (repo->settings.core_multi_pack_index) {
struct child_process midx_verify = CHILD_PROCESS_INIT;

for (source = repo->objects->sources; source; source = source->next) {
child_process_init(&midx_verify);
midx_verify.git_cmd = 1;
strvec_pushl(&midx_verify.args, "multi-pack-index",
"verify", "--object-dir", source->path, NULL);
if (show_progress)
strvec_push(&midx_verify.args, "--progress");
else
strvec_push(&midx_verify.args, "--no-progress");
if (run_command(&midx_verify))
errors_found |= ERROR_MULTI_PACK_INDEX;
}
}

free_snapshot_refs(&snap);
return errors_found;
}

View File

@ -14,6 +14,7 @@
#include "packfile.h"
#include "pack-bitmap.h"
#include "progress.h"
#include "run-command.h"

static int find_pack_entry(struct odb_source_packed *store,
const struct object_id *oid,
@ -897,6 +898,29 @@ static int verify_reverse_indices(struct odb_source_packed *source,
return res;
}

static int verify_midx(struct odb_source_packed *source,
struct odb_fsck_options *opts)
{
struct child_process midx_verify = CHILD_PROCESS_INIT;
int ret = 0;

if (!source->base.odb->repo->settings.core_multi_pack_index)
return 0;

child_process_init(&midx_verify);
midx_verify.git_cmd = 1;
strvec_pushl(&midx_verify.args, "multi-pack-index",
"verify", "--object-dir", source->base.path, NULL);
if (opts->flags & ODB_FSCK_PROGRESS)
strvec_push(&midx_verify.args, "--progress");
else
strvec_push(&midx_verify.args, "--no-progress");
if (run_command(&midx_verify))
ret = -1;

return ret;
}

static int odb_source_packed_fsck(struct odb_source *source,
struct odb_fsck_options *opts)
{
@ -912,6 +936,9 @@ static int odb_source_packed_fsck(struct odb_source *source,
if (verify_bitmap_files(packed))
ret = -1;

if (verify_midx(packed, opts) < 0)
ret = -1;

return ret;
}


View File

@ -573,6 +573,19 @@ test_expect_success 'verify incorrect checksum' '
$objdir "incorrect checksum"
'

test_expect_success 'git fsck --no-full checks multi-pack-index, --connectivity-only does not' '
pos=$(($(wc -c <$objdir/pack/multi-pack-index) - 10)) &&
corrupt_midx_and_verify $pos \
"\377\377\377\377\377\377\377\377\377\377" \
$objdir "incorrect checksum" &&

test_must_fail git fsck --no-full 2>err &&
test_grep "incorrect checksum" err &&

git fsck --connectivity-only 2>err &&
test_grep ! "incorrect checksum" err
'

test_expect_success 'setup for v1-specific fsck tests' '
git -c midx.version=1 multi-pack-index write
'