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

[PATCH 02/10] commit-graph: pass writer flags via options

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

While we already accept an options structure when writing commit graphs, we expect the caller to also pass a couple of other optional parameters that control how exactly we perform the write. This mix is somewhat arbitrary though and makes for an awkward calling convention, where it is not immediately obvious which parameters are required and which are options.

As a first step, move flags into the options structure and adapt callers accordingly. The other parameters will follow in subsequent commits.

Note that with this change, passing the options structure now becomes mandatory. This isn't much of an issue though because all callers do in fact pass one now.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/commit-graph.c | 14 ++++++--------
 builtin/fetch.c        | 11 +++++------
 builtin/gc.c           | 12 ++++++++----
 commit-graph.c         | 24 +++++++++++-------------
 commit-graph.h         |  3 +--
 5 files changed, 31 insertions(+), 33 deletions(-)
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index 0445302ba8b..d49faf543b4 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -243,7 +243,6 @@ static int cmd_commit_graph_write(int argc,
 	struct oidset commits = OIDSET_INIT;
 	struct odb_files_dir *dir = NULL;
 	int result = 0;
-	enum commit_graph_write_flags flags = 0;
 	struct progress *progress = NULL;
 	struct option options[] = {
 		OPT_BOOL(0, "reachable", &opts.reachable,
@@ -290,23 +289,23 @@ static int cmd_commit_graph_write(int argc,
 	if (!opts.obj_dir)
 		opts.obj_dir = repo_get_object_directory(repo);
 	if (opts.append)
-		flags |= COMMIT_GRAPH_WRITE_APPEND;
+		write_opts.flags |= COMMIT_GRAPH_WRITE_APPEND;
 	if (opts.split)
-		flags |= COMMIT_GRAPH_WRITE_SPLIT;
+		write_opts.flags |= COMMIT_GRAPH_WRITE_SPLIT;
 	if (opts.progress)
-		flags |= COMMIT_GRAPH_WRITE_PROGRESS;
+		write_opts.flags |= COMMIT_GRAPH_WRITE_PROGRESS;
 	if (!opts.enable_changed_paths)
-		flags |= COMMIT_GRAPH_NO_WRITE_BLOOM_FILTERS;
+		write_opts.flags |= COMMIT_GRAPH_NO_WRITE_BLOOM_FILTERS;
 	if (opts.enable_changed_paths == 1 ||
 	    git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS, 0))
-		flags |= COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
+		write_opts.flags |= COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
 
 	dir = odb_source_files_find_dir(repo->objects, opts.obj_dir);
 	if (!dir)
 		die(_("could not find object directory matching %s"), opts.obj_dir);
 
 	if (opts.reachable) {
-		if (write_commit_graph_reachable(repo, dir->abspath, flags, &write_opts))
+		if (write_commit_graph_reachable(repo, dir->abspath, &write_opts))
 			result = 1;
 		goto cleanup;
 	}
@@ -346,7 +345,6 @@ static int cmd_commit_graph_write(int argc,
 	if (write_commit_graph(repo, dir->abspath,
 			       opts.stdin_packs ? &pack_indexes : NULL,
 			       opts.stdin_commits ? &commits : NULL,
-			       flags,
 			       &write_opts))
 		result = 1;
 
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 09966e5ce8d..b76e7725728 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -2936,10 +2936,11 @@ int cmd_fetch(int argc,
 	if (fetch_write_commit_graph > 0 ||
 	    (fetch_write_commit_graph < 0 &&
 	     the_repository->settings.fetch_write_commit_graph)) {
-		int commit_graph_flags = COMMIT_GRAPH_WRITE_SPLIT;
+		struct commit_graph_write_options write_opts = COMMIT_GRAPH_WRITE_OPTIONS_INIT;
 
+		write_opts.flags |= COMMIT_GRAPH_WRITE_SPLIT;
 		if (progress)
-			commit_graph_flags |= COMMIT_GRAPH_WRITE_PROGRESS;
+			write_opts.flags |= COMMIT_GRAPH_WRITE_PROGRESS;
 
 		if (graph_write_mode != GRAPH_WRITE_SKIP) {
 			trace2_region_enter("fetch", "write-commit-graph",
@@ -2948,13 +2949,11 @@ int cmd_fetch(int argc,
 				write_commit_graph(
 					the_repository,
 					the_repository->objects->source->path,
-					NULL, &updated_tips,
-					commit_graph_flags, NULL);
+					NULL, &updated_tips, &write_opts);
 			else
 				write_commit_graph_reachable(
 					the_repository,
-					the_repository->objects->source->path,
-					commit_graph_flags, NULL);
+					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 81cecf6b6c3..a157909ed54 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -734,11 +734,15 @@ int cmd_gc(int argc,
 		clean_pack_garbage();
 	}
 
-	if (the_repository->settings.gc_write_commit_graph == 1)
+	if (the_repository->settings.gc_write_commit_graph == 1) {
+		struct commit_graph_write_options write_opts = COMMIT_GRAPH_WRITE_OPTIONS_INIT;
+
+		if (!opts.quiet && !daemonized)
+			write_opts.flags |= COMMIT_GRAPH_WRITE_PROGRESS;
+
 		write_commit_graph_reachable(the_repository,
-					     the_repository->objects->source->path,
-					     !opts.quiet && !daemonized ? COMMIT_GRAPH_WRITE_PROGRESS : 0,
-					     NULL);
+					     the_repository->objects->source->path, &write_opts);
+	}
 
 	if (!daemonized) {
 		char *path = repo_git_path(the_repository, "gc.log");
diff --git a/commit-graph.c b/commit-graph.c
index 2f9bf7a44fd..9216d051c1f 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -32,14 +32,15 @@
 
 void git_test_write_commit_graph_or_die(struct repository *repo)
 {
-	int flags = 0;
+	struct commit_graph_write_options opts = COMMIT_GRAPH_WRITE_OPTIONS_INIT;
+
 	if (!git_env_bool(GIT_TEST_COMMIT_GRAPH, 0))
 		return;
 
 	if (git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS, 0))
-		flags = COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
+		opts.flags |= COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
 
-	if (write_commit_graph_reachable(repo, repo->objects->source->path, flags, NULL))
+	if (write_commit_graph_reachable(repo, repo->objects->source->path, &opts))
 		die("failed to write commit-graph under GIT_TEST_COMMIT_GRAPH");
 }
 
@@ -1915,7 +1916,6 @@ static int add_ref_to_set(const struct reference *ref, void *cb_data)
 
 int write_commit_graph_reachable(struct repository *repo,
 				 const char *dir,
-				 enum commit_graph_write_flags flags,
 				 const struct commit_graph_write_options *opts)
 {
 	struct oidset commits = OIDSET_INIT;
@@ -1926,7 +1926,7 @@ int write_commit_graph_reachable(struct repository *repo,
 	data.repo = repo;
 	data.commits = &commits;
 
-	if (flags & COMMIT_GRAPH_WRITE_PROGRESS)
+	if (opts->flags & COMMIT_GRAPH_WRITE_PROGRESS)
 		data.progress = start_delayed_progress(
 			repo,
 			_("Collecting referenced commits"), 0);
@@ -1936,8 +1936,7 @@ int write_commit_graph_reachable(struct repository *repo,
 
 	stop_progress(&data.progress);
 
-	result = write_commit_graph(repo, dir, NULL, &commits,
-				    flags, opts);
+	result = write_commit_graph(repo, dir, NULL, &commits, opts);
 
 	oidset_clear(&commits);
 	return result;
@@ -2564,14 +2563,13 @@ int write_commit_graph(struct repository *r,
 		       const char *dir,
 		       const struct string_list *const pack_indexes,
 		       struct oidset *commits,
-		       enum commit_graph_write_flags flags,
 		       const struct commit_graph_write_options *opts)
 {
 	struct write_commit_graph_context ctx = {
 		.r = r,
-		.append = flags & COMMIT_GRAPH_WRITE_APPEND ? 1 : 0,
-		.report_progress = flags & COMMIT_GRAPH_WRITE_PROGRESS ? 1 : 0,
-		.split = flags & COMMIT_GRAPH_WRITE_SPLIT ? 1 : 0,
+		.append = opts->flags & COMMIT_GRAPH_WRITE_APPEND ? 1 : 0,
+		.report_progress = opts->flags & COMMIT_GRAPH_WRITE_PROGRESS ? 1 : 0,
+		.split = opts->flags & COMMIT_GRAPH_WRITE_SPLIT ? 1 : 0,
 		.opts = opts,
 		.total_bloom_filter_data_size = 0,
 		.write_generation_data = (get_configured_generation_version(r) == 2),
@@ -2617,9 +2615,9 @@ int write_commit_graph(struct repository *r,
 	for (struct commit_graph *chain = g; chain; chain = chain->base_graph)
 		chain->topo_levels = &topo_levels;
 
-	if (flags & COMMIT_GRAPH_WRITE_BLOOM_FILTERS)
+	if (opts->flags & COMMIT_GRAPH_WRITE_BLOOM_FILTERS)
 		ctx.changed_paths = 1;
-	if (!(flags & COMMIT_GRAPH_NO_WRITE_BLOOM_FILTERS)) {
+	if (!(opts->flags & COMMIT_GRAPH_NO_WRITE_BLOOM_FILTERS)) {
 		/* We have changed-paths already. Keep them in the next graph */
 		if (g && g->bloom_filter_settings) {
 			ctx.changed_paths = 1;
diff --git a/commit-graph.h b/commit-graph.h
index 513713ecb62..7461093a990 100644
--- a/commit-graph.h
+++ b/commit-graph.h
@@ -169,6 +169,7 @@ enum commit_graph_split_flags {
 };
 
 struct commit_graph_write_options {
+	enum commit_graph_write_flags flags;
 	int size_multiple;
 	int max_commits;
 	timestamp_t expire_time;
@@ -193,13 +194,11 @@ struct commit_graph_write_options {
  */
 int write_commit_graph_reachable(struct repository *repo,
 				 const char *dir,
-				 enum commit_graph_write_flags flags,
 				 const struct commit_graph_write_options *opts);
 int write_commit_graph(struct repository *r,
 		       const char *dir,
 		       const struct string_list *pack_indexes,
 		       struct oidset *commits,
-		       enum commit_graph_write_flags flags,
 		       const struct commit_graph_write_options *opts);
 
 #define COMMIT_GRAPH_VERIFY_SHALLOW	(1 << 0)
-- 
2.56.0.500.g5d06dc02cd.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 3 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.