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 <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Derrick Stolee committed
Sep 13, 2018 at 11:02 UTC
66ec0390e75406aa9f9295577052b9ec06d3a169
2 files changed
+30
-1
builtin/fsck.c
+18
@@ -848,5 +848,23 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
848
}
849
}
850
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
+
869
return errors_found;
870
}
t/t5319-multi-pack-index.sh
+12
-1
@@ -160,12 +160,17 @@ corrupt_midx_and_verify() {
160
DATA="${2:-\0}" &&
161
OBJDIR=$3 &&
162
GREPSTR="$4" &&
163
+ COMMAND="$5" &&
164
+ if test -z "$COMMAND"
165
+ then
166
+ COMMAND="git multi-pack-index verify --object-dir=$OBJDIR"
167
+ fi &&
168
FILE=$OBJDIR/pack/multi-pack-index &&
169
chmod a+w $FILE &&
170
test_when_finished mv midx-backup $FILE &&
171
cp $FILE midx-backup &&
172
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 &&
174
grep -v "^+" test_err >err &&
175
test_i18ngrep "$GREPSTR" err
176
}
@@ -258,6 +263,12 @@ test_expect_success 'verify incorrect offset' '
263
"incorrect object offset"
264
'
265
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
+
272
test_expect_success 'repack removes multi-pack-index' '
273
test_path_is_file $objdir/pack/multi-pack-index &&
274
git repack -adf &&