Skip to content

Commit 7afb458

Browse files
committed
Merge branch 'gc/use-repo-settings'
It is wrong to read some settings directly from the config subsystem, as things like feature.experimental can affect their default values. * gc/use-repo-settings: gc: perform incremental repack when implictly enabled fsck: verify multi-pack-index when implictly enabled fsck: verify commit graph when implicitly enabled
2 parents b82299e + a897ab7 commit 7afb458

File tree

6 files changed

+60
-12
lines changed

6 files changed

+60
-12
lines changed

builtin/fsck.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
835835
fsck_enable_object_names(&fsck_walk_options);
836836

837837
git_config(git_fsck_config, &fsck_obj_options);
838+
prepare_repo_settings(the_repository);
838839

839840
if (connectivity_only) {
840841
for_each_loose_object(mark_loose_for_connectivity, NULL, 0);
@@ -940,7 +941,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
940941

941942
check_connectivity();
942943

943-
if (!git_config_get_bool("core.commitgraph", &i) && i) {
944+
if (the_repository->settings.core_commit_graph) {
944945
struct child_process commit_graph_verify = CHILD_PROCESS_INIT;
945946
const char *verify_argv[] = { "commit-graph", "verify", NULL, NULL, NULL };
946947

@@ -956,7 +957,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
956957
}
957958
}
958959

959-
if (!git_config_get_bool("core.multipackindex", &i) && i) {
960+
if (the_repository->settings.core_multi_pack_index) {
960961
struct child_process midx_verify = CHILD_PROCESS_INIT;
961962
const char *midx_argv[] = { "multi-pack-index", "verify", NULL, NULL, NULL };
962963

builtin/gc.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,12 +1049,11 @@ static int maintenance_task_loose_objects(struct maintenance_run_opts *opts)
10491049
static int incremental_repack_auto_condition(void)
10501050
{
10511051
struct packed_git *p;
1052-
int enabled;
10531052
int incremental_repack_auto_limit = 10;
10541053
int count = 0;
10551054

1056-
if (git_config_get_bool("core.multiPackIndex", &enabled) ||
1057-
!enabled)
1055+
prepare_repo_settings(the_repository);
1056+
if (!the_repository->settings.core_multi_pack_index)
10581057
return 0;
10591058

10601059
git_config_get_int("maintenance.incremental-repack.auto",

t/t0410-partial-clone.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ test_description='partial clone'
66

77
# missing promisor objects cause repacks which write bitmaps to fail
88
GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP=0
9+
# When enabled, some commands will write commit-graphs. This causes fsck
10+
# to fail when delete_object() is called because fsck will attempt to
11+
# verify the out-of-sync commit graph.
12+
GIT_TEST_COMMIT_GRAPH=0
913

1014
delete_object () {
1115
rm $1/.git/objects/$(echo $2 | sed -e 's|^..|&/|')
@@ -322,7 +326,7 @@ test_expect_success 'rev-list stops traversal at missing and promised commit' '
322326
323327
git -C repo config core.repositoryformatversion 1 &&
324328
git -C repo config extensions.partialclone "arbitrary string" &&
325-
GIT_TEST_COMMIT_GRAPH=0 git -C repo -c core.commitGraph=false rev-list --exclude-promisor-objects --objects bar >out &&
329+
git -C repo rev-list --exclude-promisor-objects --objects bar >out &&
326330
grep $(git -C repo rev-parse bar) out &&
327331
! grep $FOO out
328332
'

t/t5318-commit-graph.sh

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,12 +694,33 @@ test_expect_success 'detect incorrect chunk count' '
694694
$GRAPH_CHUNK_LOOKUP_OFFSET
695695
'
696696

697-
test_expect_success 'git fsck (checks commit-graph)' '
697+
test_expect_success 'git fsck (checks commit-graph when config set to true)' '
698698
cd "$TRASH_DIRECTORY/full" &&
699699
git fsck &&
700700
corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \
701701
"incorrect checksum" &&
702702
cp commit-graph-pre-write-test $objdir/info/commit-graph &&
703+
test_must_fail git -c core.commitGraph=true fsck
704+
'
705+
706+
test_expect_success 'git fsck (ignores commit-graph when config set to false)' '
707+
cd "$TRASH_DIRECTORY/full" &&
708+
git fsck &&
709+
corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \
710+
"incorrect checksum" &&
711+
cp commit-graph-pre-write-test $objdir/info/commit-graph &&
712+
git -c core.commitGraph=false fsck
713+
'
714+
715+
test_expect_success 'git fsck (checks commit-graph when config unset)' '
716+
cd "$TRASH_DIRECTORY/full" &&
717+
test_when_finished "git config core.commitGraph true" &&
718+
719+
git fsck &&
720+
corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \
721+
"incorrect checksum" &&
722+
test_unconfig core.commitGraph &&
723+
cp commit-graph-pre-write-test $objdir/info/commit-graph &&
703724
test_must_fail git fsck
704725
'
705726

t/t5319-multi-pack-index.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,10 @@ test_expect_success 'verify incorrect offset' '
467467
test_expect_success 'git-fsck incorrect offset' '
468468
corrupt_midx_and_verify $MIDX_BYTE_OFFSET "\377" $objdir \
469469
"incorrect object offset" \
470-
"git -c core.multipackindex=true fsck"
470+
"git -c core.multiPackIndex=true fsck" &&
471+
test_unconfig core.multiPackIndex &&
472+
test_must_fail git fsck &&
473+
git -c core.multiPackIndex=false fsck
471474
'
472475

473476
test_expect_success 'corrupt MIDX is not reused' '

t/t7900-maintenance.sh

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,15 +336,15 @@ test_expect_success EXPENSIVE 'incremental-repack 2g limit' '
336336
--no-progress --batch-size=2147483647 <run-2g.txt
337337
'
338338

339-
test_expect_success 'maintenance.incremental-repack.auto' '
339+
run_incremental_repack_and_verify () {
340+
test_commit A &&
340341
git repack -adk &&
341-
git config core.multiPackIndex true &&
342342
git multi-pack-index write &&
343343
GIT_TRACE2_EVENT="$(pwd)/midx-init.txt" git \
344344
-c maintenance.incremental-repack.auto=1 \
345345
maintenance run --auto --task=incremental-repack 2>/dev/null &&
346346
test_subcommand ! git multi-pack-index write --no-progress <midx-init.txt &&
347-
test_commit A &&
347+
test_commit B &&
348348
git pack-objects --revs .git/objects/pack/pack <<-\EOF &&
349349
HEAD
350350
^HEAD~1
@@ -353,7 +353,7 @@ test_expect_success 'maintenance.incremental-repack.auto' '
353353
-c maintenance.incremental-repack.auto=2 \
354354
maintenance run --auto --task=incremental-repack 2>/dev/null &&
355355
test_subcommand ! git multi-pack-index write --no-progress <trace-A &&
356-
test_commit B &&
356+
test_commit C &&
357357
git pack-objects --revs .git/objects/pack/pack <<-\EOF &&
358358
HEAD
359359
^HEAD~1
@@ -362,6 +362,26 @@ test_expect_success 'maintenance.incremental-repack.auto' '
362362
-c maintenance.incremental-repack.auto=2 \
363363
maintenance run --auto --task=incremental-repack 2>/dev/null &&
364364
test_subcommand git multi-pack-index write --no-progress <trace-B
365+
}
366+
367+
test_expect_success 'maintenance.incremental-repack.auto' '
368+
rm -rf incremental-repack-true &&
369+
git init incremental-repack-true &&
370+
(
371+
cd incremental-repack-true &&
372+
git config core.multiPackIndex true &&
373+
run_incremental_repack_and_verify
374+
)
375+
'
376+
377+
test_expect_success 'maintenance.incremental-repack.auto (when config is unset)' '
378+
rm -rf incremental-repack-unset &&
379+
git init incremental-repack-unset &&
380+
(
381+
cd incremental-repack-unset &&
382+
test_unconfig core.multiPackIndex &&
383+
run_incremental_repack_and_verify
384+
)
365385
'
366386

367387
test_expect_success 'pack-refs task' '

0 commit comments

Comments
 (0)