diff --git a/builtin/gc.c b/builtin/gc.c index 090959350e..12ddb68bba 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -737,9 +737,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) { diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh index 53c883531e..ee1f4a7ae4 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -52,6 +52,35 @@ test_expect_success 'run --task=' ' test_subcommand git commit-graph write --split --reachable --no-progress err && test_i18ngrep "is not a valid task" err