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

[PATCH 4/7] builtin/commit-graph: drop global "--object-dir=" switch

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

When invoking git-commit-graph(1) it is possible for the user to pass the "--object-dir=" switch either before or after the subcommand: both "git commit-graph --object-dir= write" and "git commit-graph write --object-dir=" do the same thing. This calling convention is very atypical in Git, we don't document this and none of our tests even use the former syntax.

Furthermore, this requires us to keep track of the object directory via global state as we don't have an easy way to pass the parsed option down to the individual subcommands. We _could_ of course adapt the logic and prepend the object directory to the `argv` we end up passing down. But that feels rather pointless.

Adapt the code to only allow the "--object-dir=" option for subcommands. This brings the command in line with how Git typically handles options, and it avoids adding complexity in subsequent commits where we're about to remove all global state in "builtin/commit-graph.c".

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 builtin/commit-graph.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c
index f8825980f40..7140433a39a 100644
--- a/builtin/commit-graph.c
+++ b/builtin/commit-graph.c
@@ -365,12 +365,11 @@ int cmd_commit_graph(int argc,
 		     struct repository *repo)
 {
 	parse_opt_subcommand_fn *fn = NULL;
-	struct option builtin_commit_graph_options[] = {
+	struct option options[] = {
 		OPT_SUBCOMMAND("verify", &fn, cmd_commit_graph_verify),
 		OPT_SUBCOMMAND("write", &fn, cmd_commit_graph_write),
 		OPT_END(),
 	};
-	struct option *options = parse_options_concat(builtin_commit_graph_options, common_opts);
 
 	repo_config(repo, git_default_config, NULL);
 
@@ -379,7 +378,6 @@ int cmd_commit_graph(int argc,
 
 	argc = parse_options(argc, argv, prefix, options,
 			     builtin_commit_graph_usage, 0);
-	FREE_AND_NULL(options);
 
 	return fn(argc, argv, prefix, repo);
 }
-- 
2.56.0.341.g393f52fd96.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 5 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.