Skip to content

Commit 0be2d65

Browse files
committed
Merge branch 'ds/maintenance-commit-graph-auto-fix'
Test-coverage enhancement of running commit-graph task "git maintenance" as needed led to discovery and fix of a bug. * ds/maintenance-commit-graph-auto-fix: maintenance: core.commitGraph=false prevents writes maintenance: test commit-graph auto condition
2 parents 307a53d + d334107 commit 0be2d65

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

builtin/gc.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,9 +739,15 @@ static int dfs_on_ref(const char *refname,
739739
commit = lookup_commit(the_repository, oid);
740740
if (!commit)
741741
return 0;
742-
if (parse_commit(commit))
742+
if (parse_commit(commit) ||
743+
commit_graph_position(commit) != COMMIT_NOT_FROM_GRAPH)
743744
return 0;
744745

746+
data->num_not_in_graph++;
747+
748+
if (data->num_not_in_graph >= data->limit)
749+
return 1;
750+
745751
commit_list_append(commit, &stack);
746752

747753
while (!result && stack) {
@@ -809,6 +815,10 @@ static int run_write_commit_graph(struct maintenance_run_opts *opts)
809815

810816
static int maintenance_task_commit_graph(struct maintenance_run_opts *opts)
811817
{
818+
prepare_repo_settings(the_repository);
819+
if (!the_repository->settings.core_commit_graph)
820+
return 0;
821+
812822
close_object_store(the_repository->objects);
813823
if (run_write_commit_graph(opts)) {
814824
error(_("failed to write commit-graph"));

t/t7900-maintenance.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,43 @@ test_expect_success 'run --task=<task>' '
5353
test_subcommand git commit-graph write --split --reachable --no-progress <run-both.txt
5454
'
5555

56+
test_expect_success 'core.commitGraph=false prevents write process' '
57+
GIT_TRACE2_EVENT="$(pwd)/no-commit-graph.txt" \
58+
git -c core.commitGraph=false maintenance run \
59+
--task=commit-graph 2>/dev/null &&
60+
test_subcommand ! git commit-graph write --split --reachable --no-progress \
61+
<no-commit-graph.txt
62+
'
63+
64+
test_expect_success 'commit-graph auto condition' '
65+
COMMAND="maintenance run --task=commit-graph --auto --quiet" &&
66+
67+
GIT_TRACE2_EVENT="$(pwd)/cg-no.txt" \
68+
git -c maintenance.commit-graph.auto=1 $COMMAND &&
69+
GIT_TRACE2_EVENT="$(pwd)/cg-negative-means-yes.txt" \
70+
git -c maintenance.commit-graph.auto="-1" $COMMAND &&
71+
72+
test_commit first &&
73+
74+
GIT_TRACE2_EVENT="$(pwd)/cg-zero-means-no.txt" \
75+
git -c maintenance.commit-graph.auto=0 $COMMAND &&
76+
GIT_TRACE2_EVENT="$(pwd)/cg-one-satisfied.txt" \
77+
git -c maintenance.commit-graph.auto=1 $COMMAND &&
78+
79+
git commit --allow-empty -m "second" &&
80+
git commit --allow-empty -m "third" &&
81+
82+
GIT_TRACE2_EVENT="$(pwd)/cg-two-satisfied.txt" \
83+
git -c maintenance.commit-graph.auto=2 $COMMAND &&
84+
85+
COMMIT_GRAPH_WRITE="git commit-graph write --split --reachable --no-progress" &&
86+
test_subcommand ! $COMMIT_GRAPH_WRITE <cg-no.txt &&
87+
test_subcommand $COMMIT_GRAPH_WRITE <cg-negative-means-yes.txt &&
88+
test_subcommand ! $COMMIT_GRAPH_WRITE <cg-zero-means-no.txt &&
89+
test_subcommand $COMMIT_GRAPH_WRITE <cg-one-satisfied.txt &&
90+
test_subcommand $COMMIT_GRAPH_WRITE <cg-two-satisfied.txt
91+
'
92+
5693
test_expect_success 'run --task=bogus' '
5794
test_must_fail git maintenance run --task=bogus 2>err &&
5895
test_i18ngrep "is not a valid task" err

0 commit comments

Comments
 (0)