Skip to content

Commit ea5ae6c

Browse files
derrickstoleegitster
authored andcommitted
fsck: verify multi-pack-index
When core.multiPackIndex is true, we may have a multi-pack-index in our object directory. Add calls to 'git multi-pack-index verify' at the end of 'git fsck' if so. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6614413 commit ea5ae6c

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

builtin/fsck.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,5 +848,23 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
848848
}
849849
}
850850

851+
if (!git_config_get_bool("core.multipackindex", &i) && i) {
852+
struct child_process midx_verify = CHILD_PROCESS_INIT;
853+
const char *midx_argv[] = { "multi-pack-index", "verify", NULL, NULL, NULL };
854+
855+
midx_verify.argv = midx_argv;
856+
midx_verify.git_cmd = 1;
857+
if (run_command(&midx_verify))
858+
errors_found |= ERROR_COMMIT_GRAPH;
859+
860+
prepare_alt_odb(the_repository);
861+
for (alt = the_repository->objects->alt_odb_list; alt; alt = alt->next) {
862+
midx_argv[2] = "--object-dir";
863+
midx_argv[3] = alt->path;
864+
if (run_command(&midx_verify))
865+
errors_found |= ERROR_COMMIT_GRAPH;
866+
}
867+
}
868+
851869
return errors_found;
852870
}

t/t5319-multi-pack-index.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,17 @@ corrupt_midx_and_verify() {
160160
DATA="${2:-\0}" &&
161161
OBJDIR=$3 &&
162162
GREPSTR="$4" &&
163+
COMMAND="$5" &&
164+
if test -z "$COMMAND"
165+
then
166+
COMMAND="git multi-pack-index verify --object-dir=$OBJDIR"
167+
fi &&
163168
FILE=$OBJDIR/pack/multi-pack-index &&
164169
chmod a+w $FILE &&
165170
test_when_finished mv midx-backup $FILE &&
166171
cp $FILE midx-backup &&
167172
printf "$DATA" | dd of="$FILE" bs=1 seek="$POS" conv=notrunc &&
168-
test_must_fail git multi-pack-index verify --object-dir=$OBJDIR 2>test_err &&
173+
test_must_fail $COMMAND 2>test_err &&
169174
grep -v "^+" test_err >err &&
170175
test_i18ngrep "$GREPSTR" err
171176
}
@@ -258,6 +263,12 @@ test_expect_success 'verify incorrect offset' '
258263
"incorrect object offset"
259264
'
260265

266+
test_expect_success 'git-fsck incorrect offset' '
267+
corrupt_midx_and_verify $MIDX_BYTE_OFFSET "\07" $objdir \
268+
"incorrect object offset" \
269+
"git -c core.multipackindex=true fsck"
270+
'
271+
261272
test_expect_success 'repack removes multi-pack-index' '
262273
test_path_is_file $objdir/pack/multi-pack-index &&
263274
git repack -adf &&

0 commit comments

Comments
 (0)