{"thread":{"id":"66688","subject":"[PATCH 0/7] builtin/commit-graph: some small cleanups","startedAt":"2026-10-28T11:57:52Z","lastAt":"2026-10-29T12:55:15Z","messageCount":12,"participants":["Patrick Steinhardt","Mark C. Chu-Carroll","Junio C Hamano","Karthik Nayak"],"isPatch":true,"patchVersion":1,"patchTotal":7},"messages":[{"id":"556648","messageId":"20261028-pks-commit-graph-cleanups-v1-0-c549344c363f@pks.im","threadId":"66688","inReplyTo":null,"subject":"[PATCH 0/7] builtin/commit-graph: some small cleanups","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-28T11:57:52Z","receivedAt":"2026-10-28T11:57:52Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Hi,\n\nI'm working into the direction of making commit-graphs pluggable so that\nbackends can fully control where exactly commit-graphs are written to\nand read from. This patch series contains a couple of small preliminary\ncleanups.\n\nMost of the patches are rather uncontroversial, I'd assume. The only\none that might raise some eyebrows is where I \"fix\" git-commit-graph(1)\nto only accept \"--object-directory=\" for subcommands instead of both as\na command-global and subcommand option. I feel like this is quite a weird\noutlier, and it got in my way. In any case, I'd appreciate some extra\nthoughts on this.\n\nThanks!\n\nPatrick\n\n---\nPatrick Steinhardt (7):\n      builtin/commit-graph: rename subcommand functions\n      builtin/commit-graph: drop declaration for `read_replace_refs`\n      builtin/commit-graph: get rid of `the_repository`\n      builtin/commit-graph: drop global \"--object-dir=\" switch\n      builtin/commit-graph: simplify how we wire up common options\n      builtin/commit-graph: de-globalize write options handling\n      builtin/commit-graph: de-globalize options handling\n\n builtin/commit-graph.c | 131 +++++++++++++++++++++++++------------------------\n 1 file changed, 67 insertions(+), 64 deletions(-)\n\n\n---\nbase-commit: 37b3475fb530c14109211faca33716a173db61ed\nchange-id: 20261028-pks-commit-graph-cleanups-d1dc30f3e05a\n\n\n"},{"id":"556649","messageId":"20261028-pks-commit-graph-cleanups-v1-1-c549344c363f@pks.im","threadId":"66688","inReplyTo":"20261028-pks-commit-graph-cleanups-v1-0-c549344c363f@pks.im","subject":"[PATCH 1/7] builtin/commit-graph: rename subcommand functions","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-28T11:57:53Z","receivedAt":"2026-10-28T11:57:53Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Subcommands that we wire up via `OPT_SUBCOMMAND()` are typically called\n`cmd_<command>_<subcommand>()`, but we don't follow that pattern in\n\"builtin/commit-graph.c\". Rename the functions.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/commit-graph.c | 16 ++++++++++------\n 1 file changed, 10 insertions(+), 6 deletions(-)\n\ndiff --git a/builtin/commit-graph.c b/builtin/commit-graph.c\nindex ff244c866fe..415eb6afee9 100644\n--- a/builtin/commit-graph.c\n+++ b/builtin/commit-graph.c\n@@ -65,8 +65,10 @@ static struct option *add_common_options(struct option *to)\n \treturn parse_options_concat(common_opts, to);\n }\n \n-static int graph_verify(int argc, const char **argv, const char *prefix,\n-\t\t\tstruct repository *repo UNUSED)\n+static int cmd_commit_graph_verify(int argc,\n+\t\t\t\t   const char **argv,\n+\t\t\t\t   const char *prefix,\n+\t\t\t\t   struct repository *repo UNUSED)\n {\n \tstruct commit_graph *graph = NULL;\n \tstruct odb_files_dir *dir = NULL;\n@@ -224,8 +226,10 @@ static int git_commit_graph_write_config(const char *var, const char *value,\n \treturn 0;\n }\n \n-static int graph_write(int argc, const char **argv, const char *prefix,\n-\t\t       struct repository *repo UNUSED)\n+static int cmd_commit_graph_write(int argc,\n+\t\t\t\t  const char **argv,\n+\t\t\t\t  const char *prefix,\n+\t\t\t\t  struct repository *repo UNUSED)\n {\n \tstruct string_list pack_indexes = STRING_LIST_INIT_DUP;\n \tstruct strbuf buf = STRBUF_INIT;\n@@ -362,8 +366,8 @@ int cmd_commit_graph(int argc,\n {\n \tparse_opt_subcommand_fn *fn = NULL;\n \tstruct option builtin_commit_graph_options[] = {\n-\t\tOPT_SUBCOMMAND(\"verify\", &fn, graph_verify),\n-\t\tOPT_SUBCOMMAND(\"write\", &fn, graph_write),\n+\t\tOPT_SUBCOMMAND(\"verify\", &fn, cmd_commit_graph_verify),\n+\t\tOPT_SUBCOMMAND(\"write\", &fn, cmd_commit_graph_write),\n \t\tOPT_END(),\n \t};\n \tstruct option *options = parse_options_concat(builtin_commit_graph_options, common_opts);\n\n-- \n2.56.0.341.g393f52fd96.dirty\n\n\n"},{"id":"556650","messageId":"20261028-pks-commit-graph-cleanups-v1-2-c549344c363f@pks.im","threadId":"66688","inReplyTo":"20261028-pks-commit-graph-cleanups-v1-0-c549344c363f@pks.im","subject":"[PATCH 2/7] builtin/commit-graph: drop declaration for `read_replace_refs`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-28T11:57:54Z","receivedAt":"2026-10-28T11:57:54Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"We have an `extern int read_replace_refs`, but that variable is not used\nanymore since d24eda4e03c (repository: create disable_replace_refs(),\n2023-06-06). In fact, that variable has been converted into a file-local\nvariable, and users are expected to call `disable_replace_refs()` now.\n\nRemove the declaration.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/commit-graph.c | 1 -\n 1 file changed, 1 deletion(-)\n\ndiff --git a/builtin/commit-graph.c b/builtin/commit-graph.c\nindex 415eb6afee9..14f9db5456e 100644\n--- a/builtin/commit-graph.c\n+++ b/builtin/commit-graph.c\n@@ -148,7 +148,6 @@ static int cmd_commit_graph_verify(int argc,\n \treturn ret;\n }\n \n-extern int read_replace_refs;\n static struct commit_graph_opts write_opts;\n \n static int write_option_parse_split(const struct option *opt, const char *arg,\n\n-- \n2.56.0.341.g393f52fd96.dirty\n\n\n"},{"id":"556651","messageId":"20261028-pks-commit-graph-cleanups-v1-3-c549344c363f@pks.im","threadId":"66688","inReplyTo":"20261028-pks-commit-graph-cleanups-v1-0-c549344c363f@pks.im","subject":"[PATCH 3/7] builtin/commit-graph: get rid of `the_repository`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-28T11:57:55Z","receivedAt":"2026-10-28T11:57:55Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"There are a couple of references to `the_repository` in\ngit-commit-graph(1). As that command cannot run outside of a repository\nthese references can be trivially replaced by the repository that's\npassed in as parameter to `cmd_commit_graph()`.\n\nWe don't have to worry about the repository being `NULL` when called\nwith \"-h\", either: we do pass the repository to `repo_config()` before\ncalling `parse_options()`, but that function can handle a `NULL`\nrepository alright.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/commit-graph.c | 39 ++++++++++++++++++++-------------------\n 1 file changed, 20 insertions(+), 19 deletions(-)\n\ndiff --git a/builtin/commit-graph.c b/builtin/commit-graph.c\nindex 14f9db5456e..f8825980f40 100644\n--- a/builtin/commit-graph.c\n+++ b/builtin/commit-graph.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n #include \"builtin.h\"\n #include \"commit.h\"\n #include \"config.h\"\n@@ -68,7 +67,7 @@ static struct option *add_common_options(struct option *to)\n static int cmd_commit_graph_verify(int argc,\n \t\t\t\t   const char **argv,\n \t\t\t\t   const char *prefix,\n-\t\t\t\t   struct repository *repo UNUSED)\n+\t\t\t\t   struct repository *repo)\n {\n \tstruct commit_graph *graph = NULL;\n \tstruct odb_files_dir *dir = NULL;\n@@ -100,13 +99,13 @@ static int cmd_commit_graph_verify(int argc,\n \t\tusage_with_options(builtin_commit_graph_verify_usage, options);\n \n \tif (!opts.obj_dir)\n-\t\topts.obj_dir = repo_get_object_directory(the_repository);\n+\t\topts.obj_dir = repo_get_object_directory(repo);\n \tif (opts.shallow)\n \t\tflags |= COMMIT_GRAPH_VERIFY_SHALLOW;\n \tif (opts.progress)\n \t\tflags |= COMMIT_GRAPH_WRITE_PROGRESS;\n \n-\tdir = odb_source_files_find_dir(the_repository->objects, opts.obj_dir);\n+\tdir = odb_source_files_find_dir(repo->objects, opts.obj_dir);\n \tif (!dir)\n \t\tdie(_(\"could not find object directory matching %s\"), opts.obj_dir);\n \n@@ -117,7 +116,7 @@ static int cmd_commit_graph_verify(int argc,\n \telse if (errno != ENOENT)\n \t\tdie_errno(_(\"Could not open commit-graph '%s'\"), graph_name);\n \telse if (open_commit_graph_chain(chain_name, &fd, &st,\n-\t\t\t\t\t the_repository->hash_algo))\n+\t\t\t\t\t repo->hash_algo))\n \t\topened = OPENED_CHAIN;\n \telse if (errno != ENOENT)\n \t\tdie_errno(_(\"could not open commit-graph chain '%s'\"), chain_name);\n@@ -129,9 +128,9 @@ static int cmd_commit_graph_verify(int argc,\n \tif (opened == OPENED_NONE)\n \t\treturn 0;\n \telse if (opened == OPENED_GRAPH)\n-\t\tgraph = load_commit_graph_one_fd_st(the_repository, dir->abspath, fd, &st);\n+\t\tgraph = load_commit_graph_one_fd_st(repo, dir->abspath, fd, &st);\n \telse\n-\t\tgraph = load_commit_graph_chain_fd_st(the_repository->objects, fd, &st,\n+\t\tgraph = load_commit_graph_chain_fd_st(repo->objects, fd, &st,\n \t\t\t\t\t\t      &incomplete_chain);\n \n \tif (!graph)\n@@ -171,17 +170,19 @@ static int write_option_parse_split(const struct option *opt, const char *arg,\n \treturn 0;\n }\n \n-static int read_one_commit(struct oidset *commits, struct progress *progress,\n+static int read_one_commit(struct repository *repo,\n+\t\t\t   struct oidset *commits,\n+\t\t\t   struct progress *progress,\n \t\t\t   const char *hash)\n {\n \tstruct object *result;\n \tstruct object_id oid;\n \tconst char *end;\n \n-\tif (parse_oid_hex(hash, &oid, &end))\n+\tif (parse_oid_hex_algop(hash, &oid, &end, repo->hash_algo))\n \t\treturn error(_(\"unexpected non-hex object ID: %s\"), hash);\n \n-\tresult = deref_tag(the_repository, parse_object(the_repository, &oid),\n+\tresult = deref_tag(repo, parse_object(repo, &oid),\n \t\t\t   NULL, 0);\n \tif (!result)\n \t\treturn error(_(\"invalid object: %s\"), hash);\n@@ -228,7 +229,7 @@ static int git_commit_graph_write_config(const char *var, const char *value,\n static int cmd_commit_graph_write(int argc,\n \t\t\t\t  const char **argv,\n \t\t\t\t  const char *prefix,\n-\t\t\t\t  struct repository *repo UNUSED)\n+\t\t\t\t  struct repository *repo)\n {\n \tstruct string_list pack_indexes = STRING_LIST_INIT_DUP;\n \tstruct strbuf buf = STRBUF_INIT;\n@@ -277,7 +278,7 @@ static int cmd_commit_graph_write(int argc,\n \n \ttrace2_cmd_mode(\"write\");\n \n-\trepo_config(the_repository, git_commit_graph_write_config, &opts);\n+\trepo_config(repo, git_commit_graph_write_config, &opts);\n \n \targc = parse_options(argc, argv, prefix,\n \t\t\t     options,\n@@ -288,7 +289,7 @@ static int cmd_commit_graph_write(int argc,\n \tif (opts.reachable + opts.stdin_packs + opts.stdin_commits > 1)\n \t\tdie(_(\"use at most one of --reachable, --stdin-commits, or --stdin-packs\"));\n \tif (!opts.obj_dir)\n-\t\topts.obj_dir = repo_get_object_directory(the_repository);\n+\t\topts.obj_dir = repo_get_object_directory(repo);\n \tif (opts.append)\n \t\tflags |= COMMIT_GRAPH_WRITE_APPEND;\n \tif (opts.split)\n@@ -301,12 +302,12 @@ static int cmd_commit_graph_write(int argc,\n \t    git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS, 0))\n \t\tflags |= COMMIT_GRAPH_WRITE_BLOOM_FILTERS;\n \n-\tdir = odb_source_files_find_dir(the_repository->objects, opts.obj_dir);\n+\tdir = odb_source_files_find_dir(repo->objects, opts.obj_dir);\n \tif (!dir)\n \t\tdie(_(\"could not find object directory matching %s\"), opts.obj_dir);\n \n \tif (opts.reachable) {\n-\t\tif (write_commit_graph_reachable(the_repository, dir->abspath, flags, &write_opts))\n+\t\tif (write_commit_graph_reachable(repo, dir->abspath, flags, &write_opts))\n \t\t\tresult = 1;\n \t\tgoto cleanup;\n \t}\n@@ -329,11 +330,11 @@ static int cmd_commit_graph_write(int argc,\n \t\toidset_init(&commits, 0);\n \t\tif (opts.progress)\n \t\t\tprogress = start_delayed_progress(\n-\t\t\t\tthe_repository,\n+\t\t\t\trepo,\n \t\t\t\t_(\"Collecting commits from input\"), 0);\n \n \t\twhile (strbuf_getline(&buf, stdin) != EOF) {\n-\t\t\tif (read_one_commit(&commits, progress, buf.buf)) {\n+\t\t\tif (read_one_commit(repo, &commits, progress, buf.buf)) {\n \t\t\t\tresult = 1;\n \t\t\t\tstop_progress(&progress);\n \t\t\t\tgoto cleanup;\n@@ -343,7 +344,7 @@ static int cmd_commit_graph_write(int argc,\n \t\tstop_progress(&progress);\n \t}\n \n-\tif (write_commit_graph(the_repository, dir->abspath,\n+\tif (write_commit_graph(repo, dir->abspath,\n \t\t\t       opts.stdin_packs ? &pack_indexes : NULL,\n \t\t\t       opts.stdin_commits ? &commits : NULL,\n \t\t\t       flags,\n@@ -371,7 +372,7 @@ int cmd_commit_graph(int argc,\n \t};\n \tstruct option *options = parse_options_concat(builtin_commit_graph_options, common_opts);\n \n-\trepo_config(the_repository, git_default_config, NULL);\n+\trepo_config(repo, git_default_config, NULL);\n \n \tdisable_replace_refs();\n \tsave_commit_buffer = 0;\n\n-- \n2.56.0.341.g393f52fd96.dirty\n\n\n"},{"id":"556652","messageId":"20261028-pks-commit-graph-cleanups-v1-4-c549344c363f@pks.im","threadId":"66688","inReplyTo":"20261028-pks-commit-graph-cleanups-v1-0-c549344c363f@pks.im","subject":"[PATCH 4/7] builtin/commit-graph: drop global \"--object-dir=\" switch","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-28T11:57:56Z","receivedAt":"2026-10-28T11:57:56Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"When invoking git-commit-graph(1) it is possible for the user to pass\nthe \"--object-dir=\" switch either before or after the subcommand: both\n\"git commit-graph --object-dir= write\" and \"git commit-graph write\n--object-dir=\" do the same thing. This calling convention is very\natypical in Git, we don't document this and none of our tests even use\nthe former syntax.\n\nFurthermore, this requires us to keep track of the object directory via\nglobal state as we don't have an easy way to pass the parsed option down\nto the individual subcommands. We _could_ of course adapt the logic and\nprepend the object directory to the `argv` we end up passing down. But\nthat feels rather pointless.\n\nAdapt the code to only allow the \"--object-dir=\" option for subcommands.\nThis brings the command in line with how Git typically handles options,\nand it avoids adding complexity in subsequent commits where we're about\nto remove all global state in \"builtin/commit-graph.c\".\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/commit-graph.c | 4 +---\n 1 file changed, 1 insertion(+), 3 deletions(-)\n\ndiff --git a/builtin/commit-graph.c b/builtin/commit-graph.c\nindex f8825980f40..7140433a39a 100644\n--- a/builtin/commit-graph.c\n+++ b/builtin/commit-graph.c\n@@ -365,12 +365,11 @@ int cmd_commit_graph(int argc,\n \t\t     struct repository *repo)\n {\n \tparse_opt_subcommand_fn *fn = NULL;\n-\tstruct option builtin_commit_graph_options[] = {\n+\tstruct option options[] = {\n \t\tOPT_SUBCOMMAND(\"verify\", &fn, cmd_commit_graph_verify),\n \t\tOPT_SUBCOMMAND(\"write\", &fn, cmd_commit_graph_write),\n \t\tOPT_END(),\n \t};\n-\tstruct option *options = parse_options_concat(builtin_commit_graph_options, common_opts);\n \n \trepo_config(repo, git_default_config, NULL);\n \n@@ -379,7 +378,6 @@ int cmd_commit_graph(int argc,\n \n \targc = parse_options(argc, argv, prefix, options,\n \t\t\t     builtin_commit_graph_usage, 0);\n-\tFREE_AND_NULL(options);\n \n \treturn fn(argc, argv, prefix, repo);\n }\n\n-- \n2.56.0.341.g393f52fd96.dirty\n\n\n"},{"id":"556653","messageId":"20261028-pks-commit-graph-cleanups-v1-5-c549344c363f@pks.im","threadId":"66688","inReplyTo":"20261028-pks-commit-graph-cleanups-v1-0-c549344c363f@pks.im","subject":"[PATCH 5/7] builtin/commit-graph: simplify how we wire up common options","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-28T11:57:57Z","receivedAt":"2026-10-28T11:57:57Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"All of the git-commit-graph(1) subcommands accept the \"--object-dir=\"\noption. To avoid duplication we thus have a helper function that adds\nthis common option to our array of command-specific options. This works\nalright, but it feels rather awkward as this forces us to allocate and\nfree a secondary array of options.\n\nRefactor the code to instead have common options as a preprocessor\nmacro that we can add. This avoids the extra allocation and is overall a\nbit less verbose.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/commit-graph.c | 27 ++++++++-------------------\n 1 file changed, 8 insertions(+), 19 deletions(-)\n\ndiff --git a/builtin/commit-graph.c b/builtin/commit-graph.c\nindex 7140433a39a..165dfcb827f 100644\n--- a/builtin/commit-graph.c\n+++ b/builtin/commit-graph.c\n@@ -52,17 +52,10 @@ static struct opts_commit_graph {\n \tint enable_changed_paths;\n } opts;\n \n-static struct option common_opts[] = {\n-\tOPT_STRING(0, \"object-dir\", &opts.obj_dir,\n-\t\t   N_(\"dir\"),\n-\t\t   N_(\"the object directory to store the graph\")),\n-\tOPT_END()\n-};\n-\n-static struct option *add_common_options(struct option *to)\n-{\n-\treturn parse_options_concat(common_opts, to);\n-}\n+#define COMMIT_GRAPH_COMMON_OPTIONS(opts) \\\n+\tOPT_STRING(0, \"object-dir\", &(opts)->obj_dir, \\\n+\t\t   N_(\"dir\"), \\\n+\t\t   N_(\"the object directory to store the graph\"))\n \n static int cmd_commit_graph_verify(int argc,\n \t\t\t\t   const char **argv,\n@@ -79,15 +72,14 @@ static int cmd_commit_graph_verify(int argc,\n \tint flags = 0;\n \tint incomplete_chain = 0;\n \tint ret;\n-\n-\tstatic struct option builtin_commit_graph_verify_options[] = {\n+\tstatic struct option options[] = {\n \t\tOPT_BOOL(0, \"shallow\", &opts.shallow,\n \t\t\t N_(\"if the commit-graph is split, only verify the tip file\")),\n \t\tOPT_BOOL(0, \"progress\", &opts.progress,\n \t\t\t N_(\"force progress reporting\")),\n+\t\tCOMMIT_GRAPH_COMMON_OPTIONS(&opts),\n \t\tOPT_END(),\n \t};\n-\tstruct option *options = add_common_options(builtin_commit_graph_verify_options);\n \n \ttrace2_cmd_mode(\"verify\");\n \n@@ -123,7 +115,6 @@ static int cmd_commit_graph_verify(int argc,\n \n \tFREE_AND_NULL(graph_name);\n \tFREE_AND_NULL(chain_name);\n-\tFREE_AND_NULL(options);\n \n \tif (opened == OPENED_NONE)\n \t\treturn 0;\n@@ -238,8 +229,7 @@ static int cmd_commit_graph_write(int argc,\n \tint result = 0;\n \tenum commit_graph_write_flags flags = 0;\n \tstruct progress *progress = NULL;\n-\n-\tstatic struct option builtin_commit_graph_write_options[] = {\n+\tstatic struct option options[] = {\n \t\tOPT_BOOL(0, \"reachable\", &opts.reachable,\n \t\t\tN_(\"start walk at all refs\")),\n \t\tOPT_BOOL(0, \"stdin-packs\", &opts.stdin_packs,\n@@ -265,9 +255,9 @@ static int cmd_commit_graph_write(int argc,\n \t\t\t0, write_option_max_new_filters),\n \t\tOPT_BOOL(0, \"progress\", &opts.progress,\n \t\t\t N_(\"force progress reporting\")),\n+\t\tCOMMIT_GRAPH_COMMON_OPTIONS(&opts),\n \t\tOPT_END(),\n \t};\n-\tstruct option *options = add_common_options(builtin_commit_graph_write_options);\n \n \topts.progress = isatty(2);\n \topts.enable_changed_paths = -1;\n@@ -352,7 +342,6 @@ static int cmd_commit_graph_write(int argc,\n \t\tresult = 1;\n \n cleanup:\n-\tFREE_AND_NULL(options);\n \tstring_list_clear(&pack_indexes, 0);\n \tstrbuf_release(&buf);\n \toidset_clear(&commits);\n\n-- \n2.56.0.341.g393f52fd96.dirty\n\n\n"},{"id":"556654","messageId":"20261028-pks-commit-graph-cleanups-v1-6-c549344c363f@pks.im","threadId":"66688","inReplyTo":"20261028-pks-commit-graph-cleanups-v1-0-c549344c363f@pks.im","subject":"[PATCH 6/7] builtin/commit-graph: de-globalize write options handling","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-28T11:57:58Z","receivedAt":"2026-10-28T11:57:58Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"The commit graph write options are stored as a global variable even\nthough they're really only required by `graph_write()` in the first\nplace. The only other function that needs access to it is our config\nparser, but we can trivially pass it through to it via the callback\ndata.\n\nRefactor the code accordingly. Note that as part of this refactoring we\nintroduce a struct dedicated to parsing the configuration, and that\nstruct only contains the write options. It's thus a bit heavy handed\nright now, but we're about to add a second member in the next commit.\n\nNote that this requires us to drop the `static` modifier for our options\narray as it now references a local variable.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/commit-graph.c | 25 ++++++++++++++++---------\n 1 file changed, 16 insertions(+), 9 deletions(-)\n\ndiff --git a/builtin/commit-graph.c b/builtin/commit-graph.c\nindex 165dfcb827f..2126619ad3e 100644\n--- a/builtin/commit-graph.c\n+++ b/builtin/commit-graph.c\n@@ -138,7 +138,9 @@ static int cmd_commit_graph_verify(int argc,\n \treturn ret;\n }\n \n-static struct commit_graph_opts write_opts;\n+struct commit_graph_write_config_data {\n+\tstruct commit_graph_opts *write_opts;\n+};\n \n static int write_option_parse_split(const struct option *opt, const char *arg,\n \t\t\t\t    int unset)\n@@ -204,10 +206,12 @@ static int write_option_max_new_filters(const struct option *opt,\n \n static int git_commit_graph_write_config(const char *var, const char *value,\n \t\t\t\t\t const struct config_context *ctx,\n-\t\t\t\t\t void *cb UNUSED)\n+\t\t\t\t\t void *cb_data)\n {\n+\tstruct commit_graph_write_config_data *data = cb_data;\n+\n \tif (!strcmp(var, \"commitgraph.maxnewfilters\"))\n-\t\twrite_opts.max_new_filters = git_config_int(var, value, ctx->kvi);\n+\t\tdata->write_opts->max_new_filters = git_config_int(var, value, ctx->kvi);\n \telse if (!strcmp(var, \"commitgraph.changedpaths\"))\n \t\topts.enable_changed_paths = git_config_bool(var, value) ? 1 : -1;\n \t/*\n@@ -222,6 +226,13 @@ static int cmd_commit_graph_write(int argc,\n \t\t\t\t  const char *prefix,\n \t\t\t\t  struct repository *repo)\n {\n+\tstruct commit_graph_opts write_opts = {\n+\t\t.size_multiple = 2,\n+\t\t.max_new_filters = -1,\n+\t};\n+\tstruct commit_graph_write_config_data config_data = {\n+\t\t.write_opts = &write_opts,\n+\t};\n \tstruct string_list pack_indexes = STRING_LIST_INIT_DUP;\n \tstruct strbuf buf = STRBUF_INIT;\n \tstruct oidset commits = OIDSET_INIT;\n@@ -229,7 +240,7 @@ static int cmd_commit_graph_write(int argc,\n \tint result = 0;\n \tenum commit_graph_write_flags flags = 0;\n \tstruct progress *progress = NULL;\n-\tstatic struct option options[] = {\n+\tstruct option options[] = {\n \t\tOPT_BOOL(0, \"reachable\", &opts.reachable,\n \t\t\tN_(\"start walk at all refs\")),\n \t\tOPT_BOOL(0, \"stdin-packs\", &opts.stdin_packs,\n@@ -261,14 +272,10 @@ static int cmd_commit_graph_write(int argc,\n \n \topts.progress = isatty(2);\n \topts.enable_changed_paths = -1;\n-\twrite_opts.size_multiple = 2;\n-\twrite_opts.max_commits = 0;\n-\twrite_opts.expire_time = 0;\n-\twrite_opts.max_new_filters = -1;\n \n \ttrace2_cmd_mode(\"write\");\n \n-\trepo_config(repo, git_commit_graph_write_config, &opts);\n+\trepo_config(repo, git_commit_graph_write_config, &config_data);\n \n \targc = parse_options(argc, argv, prefix,\n \t\t\t     options,\n\n-- \n2.56.0.341.g393f52fd96.dirty\n\n\n"},{"id":"556655","messageId":"20261028-pks-commit-graph-cleanups-v1-7-c549344c363f@pks.im","threadId":"66688","inReplyTo":"20261028-pks-commit-graph-cleanups-v1-0-c549344c363f@pks.im","subject":"[PATCH 7/7] builtin/commit-graph: de-globalize options handling","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-28T11:57:59Z","receivedAt":"2026-10-28T11:57:59Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"Same as in the preceding commit, de-globalize handling of options that\nare common to both the \"verify\" and \"write\" subcommands. With this\nchange we don't have any global state in \"builtin/commit-graph.c\"\nanymore.\n\nSame as in the preceding commit, this requires us to drop the `static`\nmodifier for the options array as it references a local variable now.\n\nSigned-off-by: Patrick Steinhardt <ps@pks.im>\n---\n builtin/commit-graph.c | 31 ++++++++++++++++++-------------\n 1 file changed, 18 insertions(+), 13 deletions(-)\n\ndiff --git a/builtin/commit-graph.c b/builtin/commit-graph.c\nindex 2126619ad3e..4d28a9d51ec 100644\n--- a/builtin/commit-graph.c\n+++ b/builtin/commit-graph.c\n@@ -40,7 +40,7 @@ static char const * const builtin_commit_graph_usage[] = {\n \tNULL,\n };\n \n-static struct opts_commit_graph {\n+struct opts_commit_graph {\n \tconst char *obj_dir;\n \tint reachable;\n \tint stdin_packs;\n@@ -50,7 +50,7 @@ static struct opts_commit_graph {\n \tint shallow;\n \tint progress;\n \tint enable_changed_paths;\n-} opts;\n+};\n \n #define COMMIT_GRAPH_COMMON_OPTIONS(opts) \\\n \tOPT_STRING(0, \"object-dir\", &(opts)->obj_dir, \\\n@@ -62,6 +62,9 @@ static int cmd_commit_graph_verify(int argc,\n \t\t\t\t   const char *prefix,\n \t\t\t\t   struct repository *repo)\n {\n+\tstruct opts_commit_graph opts = {\n+\t\t.progress = isatty(2),\n+\t};\n \tstruct commit_graph *graph = NULL;\n \tstruct odb_files_dir *dir = NULL;\n \tchar *graph_name;\n@@ -72,7 +75,7 @@ static int cmd_commit_graph_verify(int argc,\n \tint flags = 0;\n \tint incomplete_chain = 0;\n \tint ret;\n-\tstatic struct option options[] = {\n+\tstruct option options[] = {\n \t\tOPT_BOOL(0, \"shallow\", &opts.shallow,\n \t\t\t N_(\"if the commit-graph is split, only verify the tip file\")),\n \t\tOPT_BOOL(0, \"progress\", &opts.progress,\n@@ -83,7 +86,6 @@ static int cmd_commit_graph_verify(int argc,\n \n \ttrace2_cmd_mode(\"verify\");\n \n-\topts.progress = isatty(2);\n \targc = parse_options(argc, argv, prefix,\n \t\t\t     options,\n \t\t\t     builtin_commit_graph_verify_usage, 0);\n@@ -140,23 +142,24 @@ static int cmd_commit_graph_verify(int argc,\n \n struct commit_graph_write_config_data {\n \tstruct commit_graph_opts *write_opts;\n+\tstruct opts_commit_graph *opts;\n };\n \n static int write_option_parse_split(const struct option *opt, const char *arg,\n \t\t\t\t    int unset)\n {\n-\tenum commit_graph_split_flags *flags = opt->value;\n+\tstruct commit_graph_write_config_data *data = opt->value;\n \n \tBUG_ON_OPT_NEG(unset);\n \n-\topts.split = 1;\n+\tdata->opts->split = 1;\n \tif (!arg)\n \t\treturn 0;\n \n \tif (!strcmp(arg, \"no-merge\"))\n-\t\t*flags = COMMIT_GRAPH_SPLIT_MERGE_PROHIBITED;\n+\t\tdata->write_opts->split_flags = COMMIT_GRAPH_SPLIT_MERGE_PROHIBITED;\n \telse if (!strcmp(arg, \"replace\"))\n-\t\t*flags = COMMIT_GRAPH_SPLIT_REPLACE;\n+\t\tdata->write_opts->split_flags = COMMIT_GRAPH_SPLIT_REPLACE;\n \telse\n \t\tdie(_(\"unrecognized --split argument, %s\"), arg);\n \n@@ -213,7 +216,7 @@ static int git_commit_graph_write_config(const char *var, const char *value,\n \tif (!strcmp(var, \"commitgraph.maxnewfilters\"))\n \t\tdata->write_opts->max_new_filters = git_config_int(var, value, ctx->kvi);\n \telse if (!strcmp(var, \"commitgraph.changedpaths\"))\n-\t\topts.enable_changed_paths = git_config_bool(var, value) ? 1 : -1;\n+\t\tdata->opts->enable_changed_paths = git_config_bool(var, value) ? 1 : -1;\n \t/*\n \t * No need to fall-back to 'git_default_config', since this was already\n \t * called in 'cmd_commit_graph()'.\n@@ -230,8 +233,13 @@ static int cmd_commit_graph_write(int argc,\n \t\t.size_multiple = 2,\n \t\t.max_new_filters = -1,\n \t};\n+\tstruct opts_commit_graph opts = {\n+\t\t.progress = isatty(2),\n+\t\t.enable_changed_paths = -1,\n+\t};\n \tstruct commit_graph_write_config_data config_data = {\n \t\t.write_opts = &write_opts,\n+\t\t.opts = &opts,\n \t};\n \tstruct string_list pack_indexes = STRING_LIST_INIT_DUP;\n \tstruct strbuf buf = STRBUF_INIT;\n@@ -251,7 +259,7 @@ static int cmd_commit_graph_write(int argc,\n \t\t\tN_(\"include all commits already in the commit-graph file\")),\n \t\tOPT_BOOL(0, \"changed-paths\", &opts.enable_changed_paths,\n \t\t\tN_(\"enable computation for changed paths\")),\n-\t\tOPT_CALLBACK_F(0, \"split\", &write_opts.split_flags, NULL,\n+\t\tOPT_CALLBACK_F(0, \"split\", &config_data, NULL,\n \t\t\tN_(\"allow writing an incremental commit-graph file\"),\n \t\t\tPARSE_OPT_OPTARG | PARSE_OPT_NONEG,\n \t\t\twrite_option_parse_split),\n@@ -270,9 +278,6 @@ static int cmd_commit_graph_write(int argc,\n \t\tOPT_END(),\n \t};\n \n-\topts.progress = isatty(2);\n-\topts.enable_changed_paths = -1;\n-\n \ttrace2_cmd_mode(\"write\");\n \n \trepo_config(repo, git_commit_graph_write_config, &config_data);\n\n-- \n2.56.0.341.g393f52fd96.dirty\n\n\n"},{"id":"556688","messageId":"DMGN1ERLYCYY.2L8R1V3K7G9TZ@fastmail.com","threadId":"66688","inReplyTo":"20261028-pks-commit-graph-cleanups-v1-7-c549344c363f@pks.im","subject":"Re: [PATCH 7/7] builtin/commit-graph: de-globalize options handling","fromName":"Mark C. Chu-Carroll","fromEmail":"markchucarroll@fastmail.com","sentAt":"2026-10-28T17:13:10Z","receivedAt":"2026-10-28T17:13:10Z","isPatch":true,"sender":{"key":"markchucarroll@fastmail.com","avatar":null},"body":"\nThis all looks correct and unobjectionable to me.\n\n    -Mark\n\n\n-- \nMark Craig Chu-Carroll (@MarkChuCarroll at gitlab)\n*** Software Tools/Math Geek - Software Engineer at Gitlab\n*** Work Email: mcarroll@gitlab.com / markchucarroll@fastmail.com\n*** Personal Blog: http://goodmath.org/blog / Personal email: markcc@gmail.com\n\n\n"},{"id":"556706","messageId":"xmqqv76l7e48.fsf@gitster.g","threadId":"66688","inReplyTo":"20261028-pks-commit-graph-cleanups-v1-0-c549344c363f@pks.im","subject":"Re: [PATCH 0/7] builtin/commit-graph: some small cleanups","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-28T20:40:39Z","receivedAt":"2026-10-28T20:40:39Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> Hi,\n>\n> I'm working into the direction of making commit-graphs pluggable so that\n> backends can fully control where exactly commit-graphs are written to\n> and read from. This patch series contains a couple of small preliminary\n> cleanups.\n>\n> Most of the patches are rather uncontroversial, I'd assume. The only\n> one that might raise some eyebrows is where I \"fix\" git-commit-graph(1)\n> to only accept \"--object-directory=\" for subcommands instead of both as\n> a command-global and subcommand option. I feel like this is quite a weird\n> outlier, and it got in my way. In any case, I'd appreciate some extra\n> thoughts on this.\n>\n> Thanks!\n>\n> Patrick\n\nI read the first 4 steps and they all looked sensible.  May come\nback to the remainder later this week if nobody beats me to it.\n\nThanks.\n\n>\n> ---\n> Patrick Steinhardt (7):\n>       builtin/commit-graph: rename subcommand functions\n>       builtin/commit-graph: drop declaration for `read_replace_refs`\n>       builtin/commit-graph: get rid of `the_repository`\n>       builtin/commit-graph: drop global \"--object-dir=\" switch\n>       builtin/commit-graph: simplify how we wire up common options\n>       builtin/commit-graph: de-globalize write options handling\n>       builtin/commit-graph: de-globalize options handling\n>\n>  builtin/commit-graph.c | 131 +++++++++++++++++++++++++------------------------\n>  1 file changed, 67 insertions(+), 64 deletions(-)\n>\n>\n> ---\n> base-commit: 37b3475fb530c14109211faca33716a173db61ed\n> change-id: 20261028-pks-commit-graph-cleanups-d1dc30f3e05a\n\n"},{"id":"556712","messageId":"xmqq8q3h7bvp.fsf@gitster.g","threadId":"66688","inReplyTo":"xmqqv76l7e48.fsf@gitster.g","subject":"Re: [PATCH 0/7] builtin/commit-graph: some small cleanups","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-28T21:28:58Z","receivedAt":"2026-10-28T21:28:58Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> I read the first 4 steps and they all looked sensible.  May come\n> back to the remainder later this week if nobody beats me to it.\n>\n> Thanks.\n\nAs to the rest, quite honestly, [6/7] and [7/7] were \"Meh\", even\nthough I do not think they hurt [*].\n\nAll the rest looked good to me.\n\n\n[Footnote]\n\n * Unless these things are lifted out of bulitin/* hierarchy, there\n   is no strong reason to avoid relying on global variables or even\n   the_repository.  Once we move things out of there to make them\n   truly reusable, these things start to matter, but until then...\n\n"},{"id":"556780","messageId":"CAOLa=ZRVhZjv3yXA76wK+fZ0o=FrwScHcT3=xJOOgYvjG6cSiQ@mail.gmail.com","threadId":"66688","inReplyTo":"xmqqv76l7e48.fsf@gitster.g","subject":"Re: [PATCH 0/7] builtin/commit-graph: some small cleanups","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2026-10-29T12:55:15Z","receivedAt":"2026-10-29T12:55:15Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Patrick Steinhardt <ps@pks.im> writes:\n>\n>> Hi,\n>>\n>> I'm working into the direction of making commit-graphs pluggable so that\n>> backends can fully control where exactly commit-graphs are written to\n>> and read from. This patch series contains a couple of small preliminary\n>> cleanups.\n>>\n>> Most of the patches are rather uncontroversial, I'd assume. The only\n>> one that might raise some eyebrows is where I \"fix\" git-commit-graph(1)\n>> to only accept \"--object-directory=\" for subcommands instead of both as\n>> a command-global and subcommand option. I feel like this is quite a weird\n>> outlier, and it got in my way. In any case, I'd appreciate some extra\n>> thoughts on this.\n>>\n>> Thanks!\n>>\n>> Patrick\n>\n> I read the first 4 steps and they all looked sensible.  May come\n> back to the remainder later this week if nobody beats me to it.\n>\n> Thanks.\n>\n\nI didn't beat you to it, but I too have nothing to object here,\neverything looks to be in order :)\n"}]}