[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