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

[PATCH 06/10] commit-graph: move remaining write parameters into options

From
Patrick Steinhardt <ps@pks.im>
Date
Nov 4, 2026, 15:57 UTC
Message-ID
<20261104-pks-commit-graph-write-refactorings-v1-6-d013d9401a59@pks.im>
In-Reply-To
<20261104-pks-commit-graph-write-refactorings-v1-0-d013d9401a59@pks.im>

Move the remaining optional parameters that can be passed to `write_commit_graph()` into its options structure to simplify the function's calling convention.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/commit-graph.c |  7 +++----
 builtin/fetch.c        | 15 +++++----------
 builtin/gc.c           |  2 +-
 commit-graph.c         | 14 ++++++--------
 commit-graph.h         |  4 ++--
 5 files changed, 17 insertions(+), 25 deletions(-)
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index 644f7736c91..f2c374d0176 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -319,6 +319,7 @@ static int cmd_commit_graph_write(int argc,
 			string_list_append(&pack_indexes, packname.buf);
 		}
 
+		write_opts.pack_indexes = &pack_indexes;
 		strbuf_release(&packname);
 	} else if (opts.stdin_commits) {
 		oidset_init(&commits, 0);
@@ -335,13 +336,11 @@ static int cmd_commit_graph_write(int argc,
 			}
 		}
 
+		write_opts.commits = &commits;
 		stop_progress(&progress);
 	}
 
-	if (write_commit_graph(repo, dir->abspath,
-			       opts.stdin_packs ? &pack_indexes : NULL,
-			       opts.stdin_commits ? &commits : NULL,
-			       &write_opts))
+	if (write_commit_graph(repo, dir->abspath, &write_opts))
 		result = 1;
 
 cleanup:
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 637d7ddaa06..7278cee8ca7 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -2943,20 +2943,15 @@ int cmd_fetch(int argc,
 			write_opts.flags |= COMMIT_GRAPH_WRITE_PROGRESS;
 		if (graph_write_mode != GRAPH_WRITE_TIPS)
 			write_opts.flags |= COMMIT_GRAPH_WRITE_REACHABLE;
+		else
+			write_opts.commits = &updated_tips;
 
 		if (graph_write_mode != GRAPH_WRITE_SKIP) {
 			trace2_region_enter("fetch", "write-commit-graph",
 					    the_repository);
-			if (graph_write_mode == GRAPH_WRITE_TIPS)
-				write_commit_graph(
-					the_repository,
-					the_repository->objects->source->path,
-					NULL, &updated_tips, &write_opts);
-			else
-				write_commit_graph(
-					the_repository,
-					the_repository->objects->source->path,
-					NULL, NULL, &write_opts);
+			write_commit_graph(the_repository,
+					   the_repository->objects->source->path,
+					   &write_opts);
 			trace2_region_leave("fetch", "write-commit-graph",
 					    the_repository);
 		}
diff --git a/builtin/gc.c b/builtin/gc.c
index 709789dbf2c..7bf88861df0 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -742,7 +742,7 @@ int cmd_gc(int argc,
 			write_opts.flags |= COMMIT_GRAPH_WRITE_PROGRESS;
 
 		write_commit_graph(the_repository, the_repository->objects->source->path,
-				   NULL, NULL, &write_opts);
+				   &write_opts);
 	}
 
 	if (!daemonized) {
diff --git a/commit-graph.c b/commit-graph.c
index 97be0f71484..077213b5336 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -41,7 +41,7 @@ void git_test_write_commit_graph_or_die(struct repository *repo)
 	if (git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS, 0))
 		opts.flags |= COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
 
-	if (write_commit_graph(repo, repo->objects->source->path, NULL, NULL, &opts))
+	if (write_commit_graph(repo, repo->objects->source->path, &opts))
 		die("failed to write commit-graph under GIT_TEST_COMMIT_GRAPH");
 }
 
@@ -2544,8 +2544,6 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx)
 
 int write_commit_graph(struct repository *r,
 		       const char *dir,
-		       const struct string_list *const pack_indexes,
-		       struct oidset *commits,
 		       const struct commit_graph_write_options *opts)
 {
 	struct write_commit_graph_context ctx = {
@@ -2563,7 +2561,7 @@ int write_commit_graph(struct repository *r,
 	struct topo_level_slab topo_levels;
 	struct commit_graph *g;
 
-	if (!!pack_indexes + !!commits + !!(opts->flags & COMMIT_GRAPH_WRITE_REACHABLE) > 1)
+	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);
@@ -2644,12 +2642,12 @@ int write_commit_graph(struct repository *r,
 		}
 	}
 
-	if (pack_indexes) {
+	if (opts->pack_indexes) {
 		ctx.order_by_pack = 1;
-		if ((res = fill_oids_from_packs(&ctx, pack_indexes)))
+		if ((res = fill_oids_from_packs(&ctx, opts->pack_indexes)))
 			goto cleanup;
-	} else if (commits) {
-		if ((res = fill_oids_from_commits(&ctx, commits)))
+	} else if (opts->commits) {
+		if ((res = fill_oids_from_commits(&ctx, opts->commits)))
 			goto cleanup;
 	} else if (opts->flags & COMMIT_GRAPH_WRITE_REACHABLE) {
 		fill_oids_from_reachable(&ctx, &reachable_commits);
diff --git a/commit-graph.h b/commit-graph.h
index 4adbd5f18d9..0e03e82a04a 100644
--- a/commit-graph.h
+++ b/commit-graph.h
@@ -171,6 +171,8 @@ enum commit_graph_split_flags {
 
 struct commit_graph_write_options {
 	enum commit_graph_write_flags flags;
+	const struct string_list *pack_indexes;
+	struct oidset *commits;
 	int size_multiple;
 	int max_commits;
 	timestamp_t expire_time;
@@ -195,8 +197,6 @@ struct commit_graph_write_options {
  */
 int write_commit_graph(struct repository *r,
 		       const char *dir,
-		       const struct string_list *pack_indexes,
-		       struct oidset *commits,
 		       const struct commit_graph_write_options *opts);
 
 #define COMMIT_GRAPH_VERIFY_SHALLOW	(1 << 0)
-- 
2.56.0.500.g5d06dc02cd.dirty
Previous: Derrick StoleeNext: Derrick Stolee
Message 9 of 22 in “commit-graph: several refactorings for writing commit graphs”
  1. 00/10 commit-graph: several refactorings for writing commit graphsPatrick Steinhardt, Nov 4, 2026
  2. 01/10 commit-graph: rename `struct commit_graph_opts`Patrick Steinhardt, Nov 4, 2026
  3. 02/10 commit-graph: pass writer flags via optionsPatrick Steinhardt, Nov 4, 2026
  4. 03/10 commit-graph: drop `NULL` checks for write optionsPatrick Steinhardt, Nov 4, 2026
  5. 04/10 commit-graph: drop redundant flags in write contextPatrick Steinhardt, Nov 4, 2026
  6. Junio C HamanoNov 4, 2026
  7. 05/10 commit-graph: merge the two commit graph writersPatrick Steinhardt, Nov 4, 2026
  8. Derrick StoleeNov 4, 2026
  9. 06/10 commit-graph: move remaining write parameters into optionsPatrick Steinhardt, Nov 4, 2026
  10. Derrick StoleeNov 4, 2026
  11. Kristofer KarlssonNov 4, 2026
  12. Patrick SteinhardtNov 5, 2026
  13. Kristofer KarlssonNov 5, 2026
  14. 07/10 commit-graph: fix mixup of write/verify flagsPatrick Steinhardt, Nov 4, 2026
  15. 08/10 builtin/commit-graph: set flags directlyPatrick Steinhardt, Nov 4, 2026
  16. 09/10 odb/source-files: verify commit-graphs as part of fsckPatrick Steinhardt, Nov 4, 2026
  17. 10/10 commit-graph: modernize function namesPatrick Steinhardt, Nov 4, 2026
  18. Derrick StoleeNov 4, 2026
  19. Patrick SteinhardtNov 5, 2026
  20. Patrick SteinhardtNov 5, 2026
  21. Derrick StoleeNov 5, 2026
  22. Patrick SteinhardtNov 5, 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.