From: Patrick Steinhardt Date: Mon, 16 Nov 2026 13:07:43 GMT Subject: [PATCH 07/12] commit-graph: split out check whether writing commit graphs is allowed Message-ID: <20261116-pks-odb-pluggable-commit-graphs-v1-7-a83fc1ff0808@pks.im> In-Reply-To: <20261116-pks-odb-pluggable-commit-graphs-v1-0-a83fc1ff0808@pks.im> In a subsequent commit we're about to split out the logic to write a commit graph into the object database backends, which will need to determine whether writing a graph is enabled in the first place. There can be various reasons though why we cannot write a new graph, and we certainly don't want to repeat this logic across all potential writers. Extract the logic into a new function to prepare for this. Signed-off-by: Patrick Steinhardt --- commit-graph.c | 37 ++++++++++++++++++++++++------------- commit-graph.h | 3 +++ 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/commit-graph.c b/commit-graph.c index caf40fd6b01..c673c0424da 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -2539,6 +2539,29 @@ static void expire_commit_graphs(const char *dirpath, strbuf_release(&path); } +bool commit_graph_write_allowed(struct repository *r) +{ + prepare_repo_settings(r); + + if (!r->settings.core_commit_graph) { + warning(_("attempting to write a commit-graph, but 'core.commitGraph' is disabled")); + return false; + } + + if (!commit_graph_compatible(r)) + return false; + + if (r->settings.commit_graph_changed_paths_version < -1 || + r->settings.commit_graph_changed_paths_version > 2) { + warning(_("attempting to write a commit-graph, but " + "'commitGraph.changedPathsVersion' (%d) is not supported"), + r->settings.commit_graph_changed_paths_version); + return false; + } + + return true; +} + int commit_graph_write(struct repository *r, const char *dir, const struct commit_graph_write_options *opts) @@ -2562,20 +2585,8 @@ int commit_graph_write(struct repository *r, if (!!opts->pack_indexes + !!opts->commits + !!(opts->flags & COMMIT_GRAPH_WRITE_REACHABLE) > 1) BUG("attempting to write commit-graph with mutually incompatible options"); - prepare_repo_settings(r); - if (!r->settings.core_commit_graph) { - warning(_("attempting to write a commit-graph, but 'core.commitGraph' is disabled")); + if (!commit_graph_write_allowed(r)) return 0; - } - if (!commit_graph_compatible(r)) - return 0; - if (r->settings.commit_graph_changed_paths_version < -1 - || r->settings.commit_graph_changed_paths_version > 2) { - warning(_("attempting to write a commit-graph, but " - "'commitGraph.changedPathsVersion' (%d) is not supported"), - r->settings.commit_graph_changed_paths_version); - return 0; - } ctx.dir = absolute_pathdup(dir); diff --git a/commit-graph.h b/commit-graph.h index dc4f6194c72..e2fc0c8da4c 100644 --- a/commit-graph.h +++ b/commit-graph.h @@ -198,6 +198,9 @@ struct commit_graph_write_options { .max_new_filters = -1, \ } +/* Check whether the repository's configuration allows writing commit graphs. */ +bool commit_graph_write_allowed(struct repository *r); + /* * The commit_graph_write* methods return zero on success * and a negative value on failure. Note that if the repository -- 2.56.1.763.g16177fe143.dirty