]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'ds/maintenance-commit-graph-auto-fix'
authorJunio C Hamano <gitster@pobox.com>
Mon, 2 Nov 2020 21:17:39 +0000 (13:17 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 2 Nov 2020 21:17:39 +0000 (13:17 -0800)
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

builtin/gc.c
t/t7900-maintenance.sh

index 2b99596ec850155eb5fa06729a959b4b57c0fe96..3629a82299fb77adb9708de18a447a4dbf3ed3a6 100644 (file)
@@ -739,9 +739,15 @@ static int dfs_on_ref(const char *refname,
        commit = lookup_commit(the_repository, oid);
        if (!commit)
                return 0;
-       if (parse_commit(commit))
+       if (parse_commit(commit) ||
+           commit_graph_position(commit) != COMMIT_NOT_FROM_GRAPH)
                return 0;
 
+       data->num_not_in_graph++;
+
+       if (data->num_not_in_graph >= data->limit)
+               return 1;
+
        commit_list_append(commit, &stack);
 
        while (!result && stack) {
@@ -809,6 +815,10 @@ static int run_write_commit_graph(struct maintenance_run_opts *opts)
 
 static int maintenance_task_commit_graph(struct maintenance_run_opts *opts)
 {
+       prepare_repo_settings(the_repository);
+       if (!the_repository->settings.core_commit_graph)
+               return 0;
+
        close_object_store(the_repository->objects);
        if (run_write_commit_graph(opts)) {
                error(_("failed to write commit-graph"));
index 55116c2f041e31a8d8e219ab9a81cb2b0d44cea7..b2def8bb1600de5b9459328667f4ded635fdf9f7 100755 (executable)
@@ -53,6 +53,43 @@ test_expect_success 'run --task=<task>' '
        test_subcommand git commit-graph write --split --reachable --no-progress <run-both.txt
 '
 
+test_expect_success 'core.commitGraph=false prevents write process' '
+       GIT_TRACE2_EVENT="$(pwd)/no-commit-graph.txt" \
+               git -c core.commitGraph=false maintenance run \
+               --task=commit-graph 2>/dev/null &&
+       test_subcommand ! git commit-graph write --split --reachable --no-progress \
+               <no-commit-graph.txt
+'
+
+test_expect_success 'commit-graph auto condition' '
+       COMMAND="maintenance run --task=commit-graph --auto --quiet" &&
+
+       GIT_TRACE2_EVENT="$(pwd)/cg-no.txt" \
+               git -c maintenance.commit-graph.auto=1 $COMMAND &&
+       GIT_TRACE2_EVENT="$(pwd)/cg-negative-means-yes.txt" \
+               git -c maintenance.commit-graph.auto="-1" $COMMAND &&
+
+       test_commit first &&
+
+       GIT_TRACE2_EVENT="$(pwd)/cg-zero-means-no.txt" \
+               git -c maintenance.commit-graph.auto=0 $COMMAND &&
+       GIT_TRACE2_EVENT="$(pwd)/cg-one-satisfied.txt" \
+               git -c maintenance.commit-graph.auto=1 $COMMAND &&
+
+       git commit --allow-empty -m "second" &&
+       git commit --allow-empty -m "third" &&
+
+       GIT_TRACE2_EVENT="$(pwd)/cg-two-satisfied.txt" \
+               git -c maintenance.commit-graph.auto=2 $COMMAND &&
+
+       COMMIT_GRAPH_WRITE="git commit-graph write --split --reachable --no-progress" &&
+       test_subcommand ! $COMMIT_GRAPH_WRITE <cg-no.txt &&
+       test_subcommand $COMMIT_GRAPH_WRITE <cg-negative-means-yes.txt &&
+       test_subcommand ! $COMMIT_GRAPH_WRITE <cg-zero-means-no.txt &&
+       test_subcommand $COMMIT_GRAPH_WRITE <cg-one-satisfied.txt &&
+       test_subcommand $COMMIT_GRAPH_WRITE <cg-two-satisfied.txt
+'
+
 test_expect_success 'run --task=bogus' '
        test_must_fail git maintenance run --task=bogus 2>err &&
        test_i18ngrep "is not a valid task" err