git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 07/12] commit-graph: split out check whether writing commit graphs is allowed

From
Patrick Steinhardt <ps@pks.im>
Date
Nov 16, 2026, 13:07 UTC
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 <ps@pks.im>
---
 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
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 9 of 14 in “Introduce pluggable commit graphs”
  1. 00/12 Introduce pluggable commit graphsPatrick Steinhardt, Nov 16, 2026
  2. 01/12 commit-graph: simplify linking commit graph chainsPatrick Steinhardt, Nov 16, 2026
  3. Junio C HamanoNov 16, 2026
  4. 02/12 commit-graph: simplify reading a single commit graphPatrick Steinhardt, Nov 16, 2026
  5. 03/12 commit-graph: expose function to validate a commit graph chainPatrick Steinhardt, Nov 16, 2026
  6. 04/12 commit-graph: decide mergeable and chainable layers by depthPatrick Steinhardt, Nov 16, 2026
  7. 05/12 commit-graph: introduce common exit for `write_commit_graph_file()`Patrick Steinhardt, Nov 16, 2026
  8. 06/12 commit-graph: derive layer infos from the passed-in chainPatrick Steinhardt, Nov 16, 2026
  9. 07/12 commit-graph: split out check whether writing commit graphs is allowedPatrick Steinhardt, Nov 16, 2026
  10. 08/12 commit-graph: split out logic to write a new commit graph layerPatrick Steinhardt, Nov 16, 2026
  11. 09/12 commit-graph: mark incomplete commit graph chainsPatrick Steinhardt, Nov 16, 2026
  12. 10/12 odb/source: make commit graphs pluggablePatrick Steinhardt, Nov 16, 2026
  13. 11/12 odb/source-files: move logic to derive commit graph pathsPatrick Steinhardt, Nov 16, 2026
  14. 12/12 odb/source-files: internalize logic to derive commit graph pathsPatrick Steinhardt, Nov 16, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.