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

[PATCH 7/7] builtin/commit-graph: de-globalize options handling

From
Patrick Steinhardt <ps@pks.im>
Date
Oct 28, 2026, 11:57 UTC
Message-ID
<20261028-pks-commit-graph-cleanups-v1-7-c549344c363f@pks.im>
In-Reply-To
<20261028-pks-commit-graph-cleanups-v1-0-c549344c363f@pks.im>

Same as in the preceding commit, de-globalize handling of options that are common to both the "verify" and "write" subcommands. With this change we don't have any global state in "builtin/commit-graph.c" anymore.

Same as in the preceding commit, this requires us to drop the `static` modifier for the options array as it references a local variable now.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/commit-graph.c | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index 2126619ad3e..4d28a9d51ec 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -40,7 +40,7 @@ static char const * const builtin_commit_graph_usage[] = {
 	NULL,
 };
 
-static struct opts_commit_graph {
+struct opts_commit_graph {
 	const char *obj_dir;
 	int reachable;
 	int stdin_packs;
@@ -50,7 +50,7 @@ static struct opts_commit_graph {
 	int shallow;
 	int progress;
 	int enable_changed_paths;
-} opts;
+};
 
 #define COMMIT_GRAPH_COMMON_OPTIONS(opts) \
 	OPT_STRING(0, "object-dir", &(opts)->obj_dir, \
@@ -62,6 +62,9 @@ static int cmd_commit_graph_verify(int argc,
 				   const char *prefix,
 				   struct repository *repo)
 {
+	struct opts_commit_graph opts = {
+		.progress = isatty(2),
+	};
 	struct commit_graph *graph = NULL;
 	struct odb_files_dir *dir = NULL;
 	char *graph_name;
@@ -72,7 +75,7 @@ static int cmd_commit_graph_verify(int argc,
 	int flags = 0;
 	int incomplete_chain = 0;
 	int ret;
-	static struct option options[] = {
+	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,
@@ -83,7 +86,6 @@ static int cmd_commit_graph_verify(int argc,
 
 	trace2_cmd_mode("verify");
 
-	opts.progress = isatty(2);
 	argc = parse_options(argc, argv, prefix,
 			     options,
 			     builtin_commit_graph_verify_usage, 0);
@@ -140,23 +142,24 @@ static int cmd_commit_graph_verify(int argc,
 
 struct commit_graph_write_config_data {
 	struct commit_graph_opts *write_opts;
+	struct opts_commit_graph *opts;
 };
 
 static int write_option_parse_split(const struct option *opt, const char *arg,
 				    int unset)
 {
-	enum commit_graph_split_flags *flags = opt->value;
+	struct commit_graph_write_config_data *data = opt->value;
 
 	BUG_ON_OPT_NEG(unset);
 
-	opts.split = 1;
+	data->opts->split = 1;
 	if (!arg)
 		return 0;
 
 	if (!strcmp(arg, "no-merge"))
-		*flags = COMMIT_GRAPH_SPLIT_MERGE_PROHIBITED;
+		data->write_opts->split_flags = COMMIT_GRAPH_SPLIT_MERGE_PROHIBITED;
 	else if (!strcmp(arg, "replace"))
-		*flags = COMMIT_GRAPH_SPLIT_REPLACE;
+		data->write_opts->split_flags = COMMIT_GRAPH_SPLIT_REPLACE;
 	else
 		die(_("unrecognized --split argument, %s"), arg);
 
@@ -213,7 +216,7 @@ static int git_commit_graph_write_config(const char *var, const char *value,
 	if (!strcmp(var, "commitgraph.maxnewfilters"))
 		data->write_opts->max_new_filters = git_config_int(var, value, ctx->kvi);
 	else if (!strcmp(var, "commitgraph.changedpaths"))
-		opts.enable_changed_paths = git_config_bool(var, value) ? 1 : -1;
+		data->opts->enable_changed_paths = git_config_bool(var, value) ? 1 : -1;
 	/*
 	 * No need to fall-back to 'git_default_config', since this was already
 	 * called in 'cmd_commit_graph()'.
@@ -230,8 +233,13 @@ static int cmd_commit_graph_write(int argc,
 		.size_multiple = 2,
 		.max_new_filters = -1,
 	};
+	struct opts_commit_graph opts = {
+		.progress = isatty(2),
+		.enable_changed_paths = -1,
+	};
 	struct commit_graph_write_config_data config_data = {
 		.write_opts = &write_opts,
+		.opts = &opts,
 	};
 	struct string_list pack_indexes = STRING_LIST_INIT_DUP;
 	struct strbuf buf = STRBUF_INIT;
@@ -251,7 +259,7 @@ static int cmd_commit_graph_write(int argc,
 			N_("include all commits already in the commit-graph file")),
 		OPT_BOOL(0, "changed-paths", &opts.enable_changed_paths,
 			N_("enable computation for changed paths")),
-		OPT_CALLBACK_F(0, "split", &write_opts.split_flags, NULL,
+		OPT_CALLBACK_F(0, "split", &config_data, NULL,
 			N_("allow writing an incremental commit-graph file"),
 			PARSE_OPT_OPTARG | PARSE_OPT_NONEG,
 			write_option_parse_split),
@@ -270,9 +278,6 @@ static int cmd_commit_graph_write(int argc,
 		OPT_END(),
 	};
 
-	opts.progress = isatty(2);
-	opts.enable_changed_paths = -1;
-
 	trace2_cmd_mode("write");
 
 	repo_config(repo, git_commit_graph_write_config, &config_data);
-- 
2.56.0.341.g393f52fd96.dirty
Previous: Patrick SteinhardtNext: Mark C. Chu-Carroll
Message 8 of 12 in “builtin/commit-graph: some small cleanups”
  1. 0/7 builtin/commit-graph: some small cleanupsPatrick Steinhardt, Oct 28, 2026
  2. 1/7 builtin/commit-graph: rename subcommand functionsPatrick Steinhardt, Oct 28, 2026
  3. 2/7 builtin/commit-graph: drop declaration for `read_replace_refs`Patrick Steinhardt, Oct 28, 2026
  4. 3/7 builtin/commit-graph: get rid of `the_repository`Patrick Steinhardt, Oct 28, 2026
  5. 4/7 builtin/commit-graph: drop global "--object-dir=" switchPatrick Steinhardt, Oct 28, 2026
  6. 5/7 builtin/commit-graph: simplify how we wire up common optionsPatrick Steinhardt, Oct 28, 2026
  7. 6/7 builtin/commit-graph: de-globalize write options handlingPatrick Steinhardt, Oct 28, 2026
  8. 7/7 builtin/commit-graph: de-globalize options handlingPatrick Steinhardt, Oct 28, 2026
  9. Mark C. Chu-CarrollOct 28, 2026
  10. Junio C HamanoOct 28, 2026
  11. Junio C HamanoOct 28, 2026
  12. Karthik NayakOct 29, 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.