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

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

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

The commit graph write options are stored as a global variable even though they're really only required by `graph_write()` in the first place. The only other function that needs access to it is our config parser, but we can trivially pass it through to it via the callback data.

Refactor the code accordingly. Note that as part of this refactoring we introduce a struct dedicated to parsing the configuration, and that struct only contains the write options. It's thus a bit heavy handed right now, but we're about to add a second member in the next commit.

Note that this requires us to drop the `static` modifier for our options array as it now references a local variable.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/commit-graph.c | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index 165dfcb827f..2126619ad3e 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -138,7 +138,9 @@ static int cmd_commit_graph_verify(int argc,
 	return ret;
 }
 
-static struct commit_graph_opts write_opts;
+struct commit_graph_write_config_data {
+	struct commit_graph_opts *write_opts;
+};
 
 static int write_option_parse_split(const struct option *opt, const char *arg,
 				    int unset)
@@ -204,10 +206,12 @@ static int write_option_max_new_filters(const struct option *opt,
 
 static int git_commit_graph_write_config(const char *var, const char *value,
 					 const struct config_context *ctx,
-					 void *cb UNUSED)
+					 void *cb_data)
 {
+	struct commit_graph_write_config_data *data = cb_data;
+
 	if (!strcmp(var, "commitgraph.maxnewfilters"))
-		write_opts.max_new_filters = git_config_int(var, value, ctx->kvi);
+		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;
 	/*
@@ -222,6 +226,13 @@ static int cmd_commit_graph_write(int argc,
 				  const char *prefix,
 				  struct repository *repo)
 {
+	struct commit_graph_opts write_opts = {
+		.size_multiple = 2,
+		.max_new_filters = -1,
+	};
+	struct commit_graph_write_config_data config_data = {
+		.write_opts = &write_opts,
+	};
 	struct string_list pack_indexes = STRING_LIST_INIT_DUP;
 	struct strbuf buf = STRBUF_INIT;
 	struct oidset commits = OIDSET_INIT;
@@ -229,7 +240,7 @@ static int cmd_commit_graph_write(int argc,
 	int result = 0;
 	enum commit_graph_write_flags flags = 0;
 	struct progress *progress = NULL;
-	static struct option options[] = {
+	struct option options[] = {
 		OPT_BOOL(0, "reachable", &opts.reachable,
 			N_("start walk at all refs")),
 		OPT_BOOL(0, "stdin-packs", &opts.stdin_packs,
@@ -261,14 +272,10 @@ static int cmd_commit_graph_write(int argc,
 
 	opts.progress = isatty(2);
 	opts.enable_changed_paths = -1;
-	write_opts.size_multiple = 2;
-	write_opts.max_commits = 0;
-	write_opts.expire_time = 0;
-	write_opts.max_new_filters = -1;
 
 	trace2_cmd_mode("write");
 
-	repo_config(repo, git_commit_graph_write_config, &opts);
+	repo_config(repo, git_commit_graph_write_config, &config_data);
 
 	argc = parse_options(argc, argv, prefix,
 			     options,
-- 
2.56.0.341.g393f52fd96.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 7 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.