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

[PATCH 08/10] builtin/commit-graph: set flags directly

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

We have a bit of an unnecessary indirection when parsing flags for both the "write" and "verify" subcommands: instead of setting the flags directly via a local flags variable, we instead populate them into a `struct opts_commit_graph` only to then set the flag. This is awkward and unnecessarily verbose.

Drop the separate flags in `struct opts_commit_graph` and set them directly via `OPT_BIT()` instead.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/commit-graph.c | 54 ++++++++++++++++++--------------------------------
 1 file changed, 19 insertions(+), 35 deletions(-)
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index 09b09d6ac5c..218c30ed3ed 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -42,13 +42,8 @@ static char const * const builtin_commit_graph_usage[] = {
 
 struct opts_commit_graph {
 	const char *obj_dir;
-	int reachable;
 	int stdin_packs;
 	int stdin_commits;
-	int append;
-	int split;
-	int shallow;
-	int progress;
 	int enable_changed_paths;
 };
 
@@ -62,24 +57,23 @@ static int cmd_commit_graph_verify(int argc,
 				   const char *prefix,
 				   struct repository *repo)
 {
-	struct opts_commit_graph opts = {
-		.progress = isatty(2),
-	};
+	struct opts_commit_graph opts = { 0 };
 	struct commit_graph *graph = NULL;
 	struct odb_files_dir *dir = NULL;
 	char *graph_name;
 	char *chain_name;
 	enum { OPENED_NONE, OPENED_GRAPH, OPENED_CHAIN } opened = OPENED_NONE;
-	enum commit_graph_verify_flags flags = 0;
+	enum commit_graph_verify_flags flags = isatty(2) ? COMMIT_GRAPH_VERIFY_PROGRESS : 0;
 	int fd;
 	struct stat st;
 	int incomplete_chain = 0;
 	int ret;
 	struct option options[] = {
-		OPT_BOOL(0, "shallow", &opts.shallow,
-			 N_("if the commit-graph is split, only verify the tip file")),
-		OPT_BOOL(0, "progress", &opts.progress,
-			 N_("force progress reporting")),
+		OPT_BIT(0, "shallow", &flags,
+			N_("if the commit-graph is split, only verify the tip file"),
+			COMMIT_GRAPH_VERIFY_SHALLOW),
+		OPT_BIT(0, "progress", &flags,
+			N_("force progress reporting"), COMMIT_GRAPH_VERIFY_PROGRESS),
 		COMMIT_GRAPH_COMMON_OPTIONS(&opts),
 		OPT_END(),
 	};
@@ -94,10 +88,6 @@ static int cmd_commit_graph_verify(int argc,
 
 	if (!opts.obj_dir)
 		opts.obj_dir = repo_get_object_directory(repo);
-	if (opts.shallow)
-		flags |= COMMIT_GRAPH_VERIFY_SHALLOW;
-	if (opts.progress)
-		flags |= COMMIT_GRAPH_VERIFY_PROGRESS;
 
 	dir = odb_source_files_find_dir(repo->objects, opts.obj_dir);
 	if (!dir)
@@ -152,7 +142,7 @@ static int write_option_parse_split(const struct option *opt, const char *arg,
 
 	BUG_ON_OPT_NEG(unset);
 
-	data->opts->split = 1;
+	data->write_opts->flags |= COMMIT_GRAPH_WRITE_SPLIT;
 	if (!arg)
 		return 0;
 
@@ -231,7 +221,6 @@ static int cmd_commit_graph_write(int argc,
 {
 	struct commit_graph_write_options write_opts = COMMIT_GRAPH_WRITE_OPTIONS_INIT;
 	struct opts_commit_graph opts = {
-		.progress = isatty(2),
 		.enable_changed_paths = -1,
 	};
 	struct commit_graph_write_config_data config_data = {
@@ -245,14 +234,15 @@ static int cmd_commit_graph_write(int argc,
 	int result = 0;
 	struct progress *progress = NULL;
 	struct option options[] = {
-		OPT_BOOL(0, "reachable", &opts.reachable,
-			N_("start walk at all refs")),
+		OPT_BIT(0, "reachable", &write_opts.flags,
+			N_("start walk at all refs"), COMMIT_GRAPH_WRITE_REACHABLE),
 		OPT_BOOL(0, "stdin-packs", &opts.stdin_packs,
 			N_("scan pack-indexes listed by stdin for commits")),
 		OPT_BOOL(0, "stdin-commits", &opts.stdin_commits,
 			N_("start walk at commits listed by stdin")),
-		OPT_BOOL(0, "append", &opts.append,
-			N_("include all commits already in the commit-graph file")),
+		OPT_BIT(0, "append", &write_opts.flags,
+			N_("include all commits already in the commit-graph file"),
+			COMMIT_GRAPH_WRITE_APPEND),
 		OPT_BOOL(0, "changed-paths", &opts.enable_changed_paths,
 			N_("enable computation for changed paths")),
 		OPT_CALLBACK_F(0, "split", &config_data, NULL,
@@ -268,14 +258,16 @@ static int cmd_commit_graph_write(int argc,
 		OPT_CALLBACK_F(0, "max-new-filters", &write_opts.max_new_filters,
 			NULL, N_("maximum number of changed-path Bloom filters to compute"),
 			0, write_option_max_new_filters),
-		OPT_BOOL(0, "progress", &opts.progress,
-			 N_("force progress reporting")),
+		OPT_BIT(0, "progress", &write_opts.flags,
+			N_("force progress reporting"), COMMIT_GRAPH_WRITE_PROGRESS),
 		COMMIT_GRAPH_COMMON_OPTIONS(&opts),
 		OPT_END(),
 	};
 
 	trace2_cmd_mode("write");
 
+	write_opts.flags |= isatty(2) ? COMMIT_GRAPH_WRITE_PROGRESS : 0;
+
 	repo_config(repo, git_commit_graph_write_config, &config_data);
 
 	argc = parse_options(argc, argv, prefix,
@@ -284,23 +276,15 @@ static int cmd_commit_graph_write(int argc,
 	if (argc)
 		usage_with_options(builtin_commit_graph_write_usage, options);
 
-	if (opts.reachable + opts.stdin_packs + opts.stdin_commits > 1)
+	if (!!(write_opts.flags & COMMIT_GRAPH_WRITE_REACHABLE) + opts.stdin_packs + opts.stdin_commits > 1)
 		die(_("use at most one of --reachable, --stdin-commits, or --stdin-packs"));
 	if (!opts.obj_dir)
 		opts.obj_dir = repo_get_object_directory(repo);
-	if (opts.append)
-		write_opts.flags |= COMMIT_GRAPH_WRITE_APPEND;
-	if (opts.split)
-		write_opts.flags |= COMMIT_GRAPH_WRITE_SPLIT;
-	if (opts.progress)
-		write_opts.flags |= COMMIT_GRAPH_WRITE_PROGRESS;
 	if (!opts.enable_changed_paths)
 		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))
 		write_opts.flags |= COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
-	if (opts.reachable)
-		write_opts.flags |= COMMIT_GRAPH_WRITE_REACHABLE;
 
 	dir = odb_source_files_find_dir(repo->objects, opts.obj_dir);
 	if (!dir)
@@ -323,7 +307,7 @@ static int cmd_commit_graph_write(int argc,
 		strbuf_release(&packname);
 	} else if (opts.stdin_commits) {
 		oidset_init(&commits, 0);
-		if (opts.progress)
+		if (write_opts.flags & COMMIT_GRAPH_WRITE_PROGRESS)
 			progress = start_delayed_progress(
 				repo,
 				_("Collecting commits from input"), 0);
-- 
2.56.0.500.g5d06dc02cd.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 15 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.