{"thread":{"id":"66963","subject":"[PATCH 0/5] builtin/multi-pack-index: remove global state","startedAt":"2026-11-30T21:54:56Z","lastAt":"2026-12-02T16:04:21Z","messageCount":25,"participants":["Justin Tobler","Patrick Steinhardt"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"559745","messageId":"cover.1796075503.git.jltobler@gmail.com","threadId":"66963","inReplyTo":null,"subject":"[PATCH 0/5] builtin/multi-pack-index: remove global state","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-11-30T21:54:56Z","receivedAt":"2026-11-30T21:54:56Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"Greetings,\n\nThis series cleans up git-multi-pack-index(1) by getting rid of\n`the_repository` and the global state used to track its options. Each\nsubcommand now parses its options into a local structure, and the common\noptions are wired up via a macro instead of allocating a combined\noptions array for every subcommand.\n\nThe main reason the options are global is that \"--object-dir=\" and\n\"--[no-]progress\" are also accepted before the subcommand, where the\ntop-level builtin parses them into the same global state used by the\nsubcommands. Patch 3 drops support for giving these options before the\nsubcommand, as every subcommand already accepts both of them.\n\nThe \"--[no-]progress\" option was previously removed as a top-level\noption in 0394f8d002 (builtin/multi-pack-index.c: disable top-level\n--[no-]progress, 2021-09-20) and appears to have been inadvertently\nreintroduced via 6b8fb17490 (builtin/multi-pack-index.c: make\n'--progress' a common option, 2026-02-24). So I think it should be fine\nto drop.\n\nWhile \"--object-dir=\" has never previously been dropped, it appears to\nexist as a top-level option for the same historical reason, from when\nall options were parsed by the top-level builtin. Since the subcommands\nalready parse the common options themselves, it should ideally be\ndropped as well. If we want to keep this top-level option though, an\nalternative could be to propagate the option argument to each\nsubcommand. In this case, I don't think it's worth it, but happy to\nchange if others feel differently.\n\nThis series is built on top of 86e79b2795 (The 26th batch, 2026-11-29).\n\nThanks,\n-Justin\n\nJustin Tobler (5):\n  builtin/multi-pack-index: resolve default object directory lazily\n  builtin/multi-pack-index: get rid of `the_repository`\n  builtin/multi-pack-index: drop top-level options\n  builtin/multi-pack-index: simplify how common options are wired up\n  builtin/multi-pack-index: de-globalize options handling\n\n Documentation/git-multi-pack-index.adoc |  12 +-\n builtin/multi-pack-index.c              | 160 +++++++++++-------------\n t/lib-midx.sh                           |   2 +-\n t/t5319-multi-pack-index.sh             |  32 ++---\n 4 files changed, 97 insertions(+), 109 deletions(-)\n\n\nbase-commit: 86e79b2795e3ce3b0ad7685edd368574b0c8b9f2\n-- \n2.56.0\n\n\n"},{"id":"559746","messageId":"c381afb0da593080ae8fc96a6187b579da829658.1796075503.git.jltobler@gmail.com","threadId":"66963","inReplyTo":"cover.1796075503.git.jltobler@gmail.com","subject":"[PATCH 1/5] builtin/multi-pack-index: resolve default object directory lazily","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-11-30T21:54:57Z","receivedAt":"2026-11-30T21:54:57Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"The object directory used by git-multi-pack-index(1) defaults to the\npath of the primary object database source. This default is set eagerly\nin `cmd_multi_pack_index()` before any options are parsed, and again\nwhen \"--no-object-dir\" is given. Both cases access `the_repository` to\ndo so, and the eager initialization additionally has to guard against\nthe repository not being set up.\n\nIn a subsequent commit, the remaining references to `the_repository` in\n\"builtin/multi-pack-index.c\" are removed. In preparation for this\nchange, leave the object directory unset in both cases and lazily fall\nback to the path of the primary source in `handle_object_dir_option()`,\nwhere the repository is passed in explicitly. This also removes the\nneed for the defensive `NULL` checks guarding the eager initialization.\n\nSigned-off-by: Justin Tobler <jltobler@gmail.com>\n---\n builtin/multi-pack-index.c | 17 +++++++++--------\n 1 file changed, 9 insertions(+), 8 deletions(-)\n\ndiff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c\nindex c48212290cf8..1a27d523c7ab 100644\n--- a/builtin/multi-pack-index.c\n+++ b/builtin/multi-pack-index.c\n@@ -80,7 +80,7 @@ static int parse_object_dir(const struct option *opt, const char *arg,\n \tchar **value = opt->value;\n \tfree(*value);\n \tif (unset)\n-\t\t*value = xstrdup(the_repository->objects->source->path);\n+\t\t*value = NULL;\n \telse\n \t\t*value = real_pathdup(arg, 1);\n \treturn 0;\n@@ -88,10 +88,16 @@ static int parse_object_dir(const struct option *opt, const char *arg,\n \n static struct odb_source_packed *handle_object_dir_option(struct repository *repo)\n {\n-\tstruct odb_files_dir *dir = odb_source_files_find_dir(repo->objects, opts.object_dir);\n+\tconst char *object_dir = opts.object_dir;\n+\tstruct odb_files_dir *dir;\n+\n+\tif (!object_dir)\n+\t\tobject_dir = repo->objects->source->path;\n+\n+\tdir = odb_source_files_find_dir(repo->objects, object_dir);\n \tif (!dir)\n \t\tdie(_(\"object directory is not an alternate of the current repository: '%s'\"),\n-\t\t    opts.object_dir);\n+\t\t    object_dir);\n \treturn dir->packed;\n }\n \n@@ -424,11 +430,6 @@ int cmd_multi_pack_index(int argc,\n \n \trepo_config(the_repository, git_default_config, NULL);\n \n-\tif (the_repository &&\n-\t    the_repository->objects &&\n-\t    the_repository->objects->source)\n-\t\topts.object_dir = xstrdup(the_repository->objects->source->path);\n-\n \targc = parse_options(argc, argv, prefix, options,\n \t\t\t     builtin_multi_pack_index_usage, 0);\n \tFREE_AND_NULL(options);\n-- \n2.56.0\n\n\n"},{"id":"559747","messageId":"673945d65de346762178b675ad6d0de9606cc6ca.1796075503.git.jltobler@gmail.com","threadId":"66963","inReplyTo":"cover.1796075503.git.jltobler@gmail.com","subject":"[PATCH 2/5] builtin/multi-pack-index: get rid of `the_repository`","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-11-30T21:54:58Z","receivedAt":"2026-11-30T21:54:58Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"There are a couple of remaining references to `the_repository` in\ngit-multi-pack-index(1). The command cannot run outside of a repository,\nso these references can be trivially replaced with the repository\npassed to the subcommands.\n\nSigned-off-by: Justin Tobler <jltobler@gmail.com>\n---\n builtin/multi-pack-index.c | 19 +++++++++----------\n 1 file changed, 9 insertions(+), 10 deletions(-)\n\ndiff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c\nindex 1a27d523c7ab..8528f4f513ef 100644\n--- a/builtin/multi-pack-index.c\n+++ b/builtin/multi-pack-index.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n #include \"builtin.h\"\n #include \"abspath.h\"\n #include \"config.h\"\n@@ -180,7 +179,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,\n \n \topts.flags |= MIDX_WRITE_BITMAP_HASH_CACHE;\n \n-\trepo_config(the_repository, git_multi_pack_index_write_config, NULL);\n+\trepo_config(repo, git_multi_pack_index_write_config, NULL);\n \n \toptions = add_common_options(builtin_multi_pack_index_write_options);\n \n@@ -286,7 +285,7 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,\n \t\t\t\t   options);\n \t}\n \n-\tpacked_source = handle_object_dir_option(the_repository);\n+\tpacked_source = handle_object_dir_option(repo);\n \n \tFREE_AND_NULL(options);\n \n@@ -321,7 +320,7 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,\n \n static int cmd_multi_pack_index_verify(int argc, 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 option *options;\n \tstatic struct option builtin_multi_pack_index_verify_options[] = {\n@@ -341,7 +340,7 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,\n \tif (argc)\n \t\tusage_with_options(builtin_multi_pack_index_verify_usage,\n \t\t\t\t   options);\n-\tpacked_source = handle_object_dir_option(the_repository);\n+\tpacked_source = handle_object_dir_option(repo);\n \n \tFREE_AND_NULL(options);\n \n@@ -350,7 +349,7 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,\n \n static int cmd_multi_pack_index_expire(int argc, 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 option *options;\n \tstatic struct option builtin_multi_pack_index_expire_options[] = {\n@@ -370,7 +369,7 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv,\n \tif (argc)\n \t\tusage_with_options(builtin_multi_pack_index_expire_usage,\n \t\t\t\t   options);\n-\tpacked_source = handle_object_dir_option(the_repository);\n+\tpacked_source = handle_object_dir_option(repo);\n \n \tFREE_AND_NULL(options);\n \n@@ -379,7 +378,7 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv,\n \n static int cmd_multi_pack_index_repack(int argc, 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 option *options;\n \tstatic struct option builtin_multi_pack_index_repack_options[] = {\n@@ -402,7 +401,7 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,\n \tif (argc)\n \t\tusage_with_options(builtin_multi_pack_index_repack_usage,\n \t\t\t\t   options);\n-\tpacked_source = handle_object_dir_option(the_repository);\n+\tpacked_source = handle_object_dir_option(repo);\n \n \tFREE_AND_NULL(options);\n \n@@ -428,7 +427,7 @@ int cmd_multi_pack_index(int argc,\n \n \tdisable_replace_refs();\n \n-\trepo_config(the_repository, git_default_config, NULL);\n+\trepo_config(repo, git_default_config, NULL);\n \n \targc = parse_options(argc, argv, prefix, options,\n \t\t\t     builtin_multi_pack_index_usage, 0);\n-- \n2.56.0\n\n\n"},{"id":"559748","messageId":"cc2876d6803f4ac5d504ce18a5380949b97e65cf.1796075503.git.jltobler@gmail.com","threadId":"66963","inReplyTo":"cover.1796075503.git.jltobler@gmail.com","subject":"[PATCH 3/5] builtin/multi-pack-index: drop top-level options","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-11-30T21:54:59Z","receivedAt":"2026-11-30T21:54:59Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"When invoking git-multi-pack-index(1), the \"--object-dir=\" and\n\"--[no-]progress\" options can be given either before or after the\nsubcommand. This calling convention is atypical for Git commands, and it\nrequires the options parsed by `cmd_multi_pack_index()` to be stored in\nglobal state so that they can be accessed by the subcommands. Neither\noption needs to be accepted before the subcommand though.\n\nThe \"--[no-]progress\" option was already removed from the top-level\nbuiltin in 0394f8d002 (builtin/multi-pack-index.c: disable top-level\n--[no-]progress, 2021-09-20). When given before the subcommand, the\noption is not always respected, as each subcommand overrides it\ndepending on whether stderr is connected to a terminal. Furthermore, a\nsubcommand without a notion of progress would have to ignore the option\naltogether. The option was inadvertently reintroduced by 6b8fb17490\n(builtin/multi-pack-index.c: make '--progress' a common option,\n2026-02-24), which moved it into the common options that are also parsed\nby `cmd_multi_pack_index()`. Consequently, \"git multi-pack-index\n--no-progress write\" still shows progress when stderr is connected to a\nterminal.\n\nUnlike \"--[no-]progress\", the \"--object-dir=\" option was kept at the top\nlevel when 60ca94769c (builtin/multi-pack-index.c: split sub-commands,\n2021-03-30) taught each subcommand to parse its own options. Giving the\noption after the subcommand is the preferred form, so also accepting it\nat the top level is no longer necessary.\n\nDrop both options from the top-level builtin so that they are only\naccepted by the subcommands. This brings the command in line with how\nGit typically handles options and avoids the need for global state to\npass the options down to the subcommands. Update the synopsis, the usage\nstrings and the example in the documentation accordingly.\n\nSigned-off-by: Justin Tobler <jltobler@gmail.com>\n---\n Documentation/git-multi-pack-index.adoc | 12 +++++-----\n builtin/multi-pack-index.c              | 14 +++++------\n t/lib-midx.sh                           |  2 +-\n t/t5319-multi-pack-index.sh             | 32 ++++++++++++-------------\n 4 files changed, 29 insertions(+), 31 deletions(-)\n\ndiff --git a/Documentation/git-multi-pack-index.adoc b/Documentation/git-multi-pack-index.adoc\nindex c6d23aeeb9a0..0dd675f3fd46 100644\n--- a/Documentation/git-multi-pack-index.adoc\n+++ b/Documentation/git-multi-pack-index.adoc\n@@ -9,16 +9,16 @@ git-multi-pack-index - Write and verify multi-pack-indexes\n SYNOPSIS\n --------\n [verse]\n-'git multi-pack-index' [<options>] write [--preferred-pack=<pack>]\n+'git multi-pack-index' write [<options>] [--preferred-pack=<pack>]\n \t\t         [--[no-]bitmap] [--[no-]incremental] [--[no-]stdin-packs]\n \t\t         [--refs-snapshot=<path>] [--[no-]write-chain-file]\n \t\t\t [--base=<checksum>]\n-'git multi-pack-index' [<options>] compact [--[no-]incremental]\n+'git multi-pack-index' compact [<options>] [--[no-]incremental]\n \t\t         [--[no-]bitmap] [--base=<checksum>] [--[no-]write-chain-file]\n \t\t\t <from> <to>\n-'git multi-pack-index' [<options>] verify\n-'git multi-pack-index' [<options>] expire\n-'git multi-pack-index' [<options>] repack [--batch-size=<size>]\n+'git multi-pack-index' verify [<options>]\n+'git multi-pack-index' expire [<options>]\n+'git multi-pack-index' repack [<options>] [--batch-size=<size>]\n \n DESCRIPTION\n -----------\n@@ -183,7 +183,7 @@ $ git multi-pack-index write --preferred-pack=<pack> --bitmap\n * Write a MIDX file for the packfiles in an alternate object store.\n +\n -----------------------------------------------\n-$ git multi-pack-index --object-dir <alt> write\n+$ git multi-pack-index write --object-dir <alt>\n -----------------------------------------------\n \n * Verify the MIDX file for the packfiles in the current `.git` directory.\ndiff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c\nindex 8528f4f513ef..2b4e2f0cce9e 100644\n--- a/builtin/multi-pack-index.c\n+++ b/builtin/multi-pack-index.c\n@@ -14,24 +14,24 @@\n #include \"repository.h\"\n \n #define BUILTIN_MIDX_WRITE_USAGE \\\n-\tN_(\"git multi-pack-index [<options>] write [--preferred-pack=<pack>]\\n\" \\\n+\tN_(\"git multi-pack-index write [<options>] [--preferred-pack=<pack>]\\n\" \\\n \t   \"  [--[no-]bitmap] [--[no-]incremental] [--[no-]stdin-packs]\\n\" \\\n \t   \"  [--refs-snapshot=<path>] [--[no-]write-chain-file]\\n\" \\\n \t   \"  [--base=<checksum>]\")\n \n #define BUILTIN_MIDX_COMPACT_USAGE \\\n-\tN_(\"git multi-pack-index [<options>] compact [--[no-]incremental]\\n\" \\\n+\tN_(\"git multi-pack-index compact [<options>] [--[no-]incremental]\\n\" \\\n \t   \"  [--[no-]bitmap] [--base=<checksum>] [--[no-]write-chain-file]\\n\" \\\n \t   \"  <from> <to>\")\n \n #define BUILTIN_MIDX_VERIFY_USAGE \\\n-\tN_(\"git multi-pack-index [<options>] verify\")\n+\tN_(\"git multi-pack-index verify [<options>]\")\n \n #define BUILTIN_MIDX_EXPIRE_USAGE \\\n-\tN_(\"git multi-pack-index [<options>] expire\")\n+\tN_(\"git multi-pack-index expire [<options>]\")\n \n #define BUILTIN_MIDX_REPACK_USAGE \\\n-\tN_(\"git multi-pack-index [<options>] repack [--batch-size=<size>]\")\n+\tN_(\"git multi-pack-index repack [<options>] [--batch-size=<size>]\")\n \n static char const * const builtin_multi_pack_index_write_usage[] = {\n \tBUILTIN_MIDX_WRITE_USAGE,\n@@ -415,7 +415,7 @@ int cmd_multi_pack_index(int argc,\n {\n \tint res;\n \tparse_opt_subcommand_fn *fn = NULL;\n-\tstruct option builtin_multi_pack_index_options[] = {\n+\tstruct option options[] = {\n \t\tOPT_SUBCOMMAND(\"repack\", &fn, cmd_multi_pack_index_repack),\n \t\tOPT_SUBCOMMAND(\"write\", &fn, cmd_multi_pack_index_write),\n \t\tOPT_SUBCOMMAND(\"compact\", &fn, cmd_multi_pack_index_compact),\n@@ -423,7 +423,6 @@ int cmd_multi_pack_index(int argc,\n \t\tOPT_SUBCOMMAND(\"expire\", &fn, cmd_multi_pack_index_expire),\n \t\tOPT_END(),\n \t};\n-\tstruct option *options = parse_options_concat(builtin_multi_pack_index_options, common_opts);\n \n \tdisable_replace_refs();\n \n@@ -431,7 +430,6 @@ int cmd_multi_pack_index(int argc,\n \n \targc = parse_options(argc, argv, prefix, options,\n \t\t\t     builtin_multi_pack_index_usage, 0);\n-\tFREE_AND_NULL(options);\n \n \tres = fn(argc, argv, prefix, repo);\n \ndiff --git a/t/lib-midx.sh b/t/lib-midx.sh\nindex e38c609604c3..d7dc09b382ec 100644\n--- a/t/lib-midx.sh\n+++ b/t/lib-midx.sh\n@@ -4,7 +4,7 @@ test_midx_consistent () {\n \ttest-tool read-midx $1 | grep ^pack-.*\\.idx$ | sort >actual &&\n \n \ttest_cmp expect actual &&\n-\tgit multi-pack-index --object-dir=$1 verify\n+\tgit multi-pack-index verify --object-dir=$1\n }\n \n midx_checksum () {\ndiff --git a/t/t5319-multi-pack-index.sh b/t/t5319-multi-pack-index.sh\nindex e1684e3e69d7..b366add863d1 100755\n--- a/t/t5319-multi-pack-index.sh\n+++ b/t/t5319-multi-pack-index.sh\n@@ -50,7 +50,7 @@ test_expect_success 'setup' '\n '\n \n test_expect_success \"don't write midx with no packs\" '\n-\ttest_must_fail git multi-pack-index --object-dir=. write &&\n+\ttest_must_fail git multi-pack-index write --object-dir=. &&\n \ttest_path_is_missing pack/multi-pack-index\n '\n \n@@ -122,13 +122,13 @@ test_expect_success 'write midx with one v1 pack' '\n \tpack=$(git pack-objects --index-version=1 $objdir/pack/test <obj-list) &&\n \ttest_when_finished rm $objdir/pack/test-$pack.pack \\\n \t\t$objdir/pack/test-$pack.idx $objdir/pack/multi-pack-index &&\n-\tgit multi-pack-index --object-dir=$objdir write &&\n+\tgit multi-pack-index write --object-dir=$objdir &&\n \tmidx_read_expect 1 18 4 $objdir\n '\n \n test_expect_success 'write midx with one v2 pack' '\n \tgit pack-objects --index-version=2,0x40 $objdir/pack/test <obj-list &&\n-\tgit multi-pack-index --object-dir=$objdir write &&\n+\tgit multi-pack-index write --object-dir=$objdir &&\n \tmidx_read_expect 1 18 4 $objdir\n '\n \n@@ -158,7 +158,7 @@ test_expect_success 'add more objects' '\n \n test_expect_success 'write midx with two packs' '\n \tgit pack-objects --index-version=1 $objdir/pack/test-2 <obj-list &&\n-\tgit multi-pack-index --object-dir=$objdir write &&\n+\tgit multi-pack-index write --object-dir=$objdir &&\n \tmidx_read_expect 2 34 4 $objdir\n '\n \n@@ -192,17 +192,17 @@ test_expect_success 'write with no objects and preferred pack' '\n '\n \n test_expect_success 'write progress off for redirected stderr' '\n-\tgit multi-pack-index --object-dir=$objdir write 2>err &&\n+\tgit multi-pack-index write --object-dir=$objdir 2>err &&\n \ttest_line_count = 0 err\n '\n \n test_expect_success 'write force progress on for stderr' '\n-\tGIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir write --progress 2>err &&\n+\tGIT_PROGRESS_DELAY=0 git multi-pack-index write --object-dir=$objdir --progress 2>err &&\n \ttest_file_not_empty err\n '\n \n test_expect_success 'write with the --no-progress option' '\n-\tGIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir write --no-progress 2>err &&\n+\tGIT_PROGRESS_DELAY=0 git multi-pack-index write --object-dir=$objdir --no-progress 2>err &&\n \ttest_line_count = 0 err\n '\n \n@@ -218,7 +218,7 @@ test_expect_success 'add more packs' '\n compare_results_with_midx \"mixed mode (two packs + extra)\"\n \n test_expect_success 'write midx with twelve packs' '\n-\tgit multi-pack-index --object-dir=$objdir write &&\n+\tgit multi-pack-index write --object-dir=$objdir &&\n \tmidx_read_expect 12 74 4 $objdir\n '\n \n@@ -242,7 +242,7 @@ test_expect_success 'multi-pack-index *.rev cleanup with --object-dir' '\n \n \t(\n \t\tcd alternate &&\n-\t\tgit multi-pack-index --object-dir ../repo/.git/objects write\n+\t\tgit multi-pack-index write --object-dir ../repo/.git/objects\n \t) &&\n \n \t# writing a midx in \"repo\" should not remove the .rev file in the\n@@ -312,8 +312,8 @@ test_expect_success 'midx picks objects from preferred pack' '\n \t\tEOF\n \t\t) &&\n \n-\t\tgit multi-pack-index --object-dir=objects \\\n-\t\t\twrite --preferred-pack=test-BC-$bc.idx 2>err &&\n+\t\tgit multi-pack-index write --object-dir=objects \\\n+\t\t\t--preferred-pack=test-BC-$bc.idx 2>err &&\n \t\ttest_must_be_empty err &&\n \n \t\ttest-tool read-midx --show-objects objects >out &&\n@@ -611,17 +611,17 @@ test_expect_success 'verify packnames out of order (v1)' '\n '\n \n test_expect_success 'repack progress off for redirected stderr' '\n-\tGIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir repack 2>err &&\n+\tGIT_PROGRESS_DELAY=0 git multi-pack-index repack --object-dir=$objdir 2>err &&\n \ttest_line_count = 0 err\n '\n \n test_expect_success 'repack force progress on for stderr' '\n-\tGIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir repack --progress 2>err &&\n+\tGIT_PROGRESS_DELAY=0 git multi-pack-index repack --object-dir=$objdir --progress 2>err &&\n \ttest_file_not_empty err\n '\n \n test_expect_success 'repack with the --no-progress option' '\n-\tGIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir repack --no-progress 2>err &&\n+\tGIT_PROGRESS_DELAY=0 git multi-pack-index repack --object-dir=$objdir --no-progress 2>err &&\n \ttest_line_count = 0 err\n '\n \n@@ -730,7 +730,7 @@ test_expect_success 'force some 64-bit offsets with pack-objects' '\n \t(\n \t\tcd repo64 &&\n \t\t( cd ../objects64 && pwd ) >.git/objects/info/alternates &&\n-\t\tmidx64=$(git multi-pack-index --object-dir=../objects64 write)\n+\t\tmidx64=$(git multi-pack-index write --object-dir=../objects64)\n \t) &&\n \tmidx_read_expect 1 63 5 \"$(pwd)/objects64\" \" large-offsets\"\n '\n@@ -1296,7 +1296,7 @@ test_expect_success PERL_TEST_HELPERS 'reader bounds-checks large offset table'\n \t(\n \t\tcd repo &&\n \t\t(cd ../objects64 && pwd) >.git/objects/info/alternates &&\n-\t\tgit multi-pack-index --object-dir=../objects64 write &&\n+\t\tgit multi-pack-index write --object-dir=../objects64 &&\n \t\tmidx=../objects64/pack/multi-pack-index &&\n \t\tcorrupt_chunk_file $midx LOFF clear &&\n \t\t# using only %(objectsize) is important here; see the commit\n-- \n2.56.0\n\n\n"},{"id":"559749","messageId":"1c16a0988239253b3695c68c138b4b71ccc00de9.1796075503.git.jltobler@gmail.com","threadId":"66963","inReplyTo":"cover.1796075503.git.jltobler@gmail.com","subject":"[PATCH 4/5] builtin/multi-pack-index: simplify how common options are wired up","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-11-30T21:55:00Z","receivedAt":"2026-11-30T21:55:00Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"All git-multi-pack-index(1) subcommands accept the \"--object-dir=\" and\n\"--progress\" options. To avoid duplicating these common options, a\nhelper function concatenates them with the options array of each\nsubcommand. This works, but requires a separate options array to be\nallocated and freed for every subcommand.\n\nDefine the common options via a preprocessor macro instead, which each\noptions array can include directly. This avoids the extra allocations\nand is less verbose overall.\n\nSigned-off-by: Justin Tobler <jltobler@gmail.com>\n---\n builtin/multi-pack-index.c | 61 +++++++++++---------------------------\n 1 file changed, 17 insertions(+), 44 deletions(-)\n\ndiff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c\nindex 2b4e2f0cce9e..d3881aee6a11 100644\n--- a/builtin/multi-pack-index.c\n+++ b/builtin/multi-pack-index.c\n@@ -100,20 +100,13 @@ static struct odb_source_packed *handle_object_dir_option(struct repository *rep\n \treturn dir->packed;\n }\n \n-static struct option common_opts[] = {\n-\tOPT_CALLBACK(0, \"object-dir\", &opts.object_dir,\n-\t  N_(\"directory\"),\n-\t  N_(\"object directory containing set of packfile and pack-index pairs\"),\n-\t  parse_object_dir),\n-\tOPT_BIT(0, \"progress\", &opts.flags, N_(\"force progress reporting\"),\n-\t\tMIDX_PROGRESS),\n-\tOPT_END(),\n-};\n-\n-static struct option *add_common_options(struct option *prev)\n-{\n-\treturn parse_options_concat(common_opts, prev);\n-}\n+#define MULTI_PACK_INDEX_COMMON_OPTIONS(opts) \\\n+\tOPT_CALLBACK(0, \"object-dir\", &(opts)->object_dir, \\\n+\t  N_(\"directory\"), \\\n+\t  N_(\"object directory containing set of packfile and pack-index pairs\"), \\\n+\t  parse_object_dir), \\\n+\tOPT_BIT(0, \"progress\", &(opts)->flags, N_(\"force progress reporting\"), \\\n+\t\tMIDX_PROGRESS)\n \n static int git_multi_pack_index_write_config(const char *var, const char *value,\n \t\t\t\t\t     const struct config_context *ctx UNUSED,\n@@ -154,8 +147,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,\n \t\t\t\t      const char *prefix,\n \t\t\t\t      struct repository *repo)\n {\n-\tstruct option *options;\n-\tstatic struct option builtin_multi_pack_index_write_options[] = {\n+\tstatic struct option options[] = {\n \t\tOPT_STRING(0, \"preferred-pack\", &opts.preferred_pack,\n \t\t\t   N_(\"preferred-pack\"),\n \t\t\t   N_(\"pack for reuse when computing a multi-pack bitmap\")),\n@@ -172,6 +164,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,\n \t\t\t N_(\"write multi-pack index containing only given indexes\")),\n \t\tOPT_FILENAME(0, \"refs-snapshot\", &opts.refs_snapshot,\n \t\t\t     N_(\"refs snapshot for selecting bitmap commits\")),\n+\t\tMULTI_PACK_INDEX_COMMON_OPTIONS(&opts),\n \t\tOPT_END(),\n \t};\n \tstruct odb_source_packed *packed_source;\n@@ -181,8 +174,6 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,\n \n \trepo_config(repo, git_multi_pack_index_write_config, NULL);\n \n-\toptions = add_common_options(builtin_multi_pack_index_write_options);\n-\n \ttrace2_cmd_mode(argv[0]);\n \n \tif (isatty(2))\n@@ -211,8 +202,6 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,\n \n \tpacked_source = handle_object_dir_option(repo);\n \n-\tFREE_AND_NULL(options);\n-\n \tif (opts.stdin_packs) {\n \t\tstruct string_list packs = STRING_LIST_INIT_DUP;\n \n@@ -247,8 +236,7 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,\n \tstruct odb_source_packed *packed_source;\n \tint ret;\n \n-\tstruct option *options;\n-\tstatic struct option builtin_multi_pack_index_compact_options[] = {\n+\tstatic struct option options[] = {\n \t\tOPT_STRING(0, \"base\", &opts.incremental_base, N_(\"checksum\"),\n \t\t\t   N_(\"base MIDX for incremental writes\")),\n \t\tOPT_BIT(0, \"bitmap\", &opts.flags, N_(\"write multi-pack bitmap\"),\n@@ -258,13 +246,12 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,\n \t\tOPT_NEGBIT(0, \"write-chain-file\", &opts.flags,\n \t\t\tN_(\"write the multi-pack-index chain file\"),\n \t\t\tMIDX_WRITE_NO_CHAIN),\n+\t\tMULTI_PACK_INDEX_COMMON_OPTIONS(&opts),\n \t\tOPT_END(),\n \t};\n \n \trepo_config(repo, git_multi_pack_index_write_config, NULL);\n \n-\toptions = add_common_options(builtin_multi_pack_index_compact_options);\n-\n \ttrace2_cmd_mode(argv[0]);\n \n \tif (isatty(2))\n@@ -287,8 +274,6 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,\n \n \tpacked_source = handle_object_dir_option(repo);\n \n-\tFREE_AND_NULL(options);\n-\n \tm = get_multi_pack_index(packed_source);\n \n \tfor (cur = m; cur && !(from_midx && to_midx); cur = cur->base_midx) {\n@@ -322,14 +307,12 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,\n \t\t\t\t       const char *prefix,\n \t\t\t\t       struct repository *repo)\n {\n-\tstruct option *options;\n-\tstatic struct option builtin_multi_pack_index_verify_options[] = {\n+\tstatic struct option options[] = {\n+\t\tMULTI_PACK_INDEX_COMMON_OPTIONS(&opts),\n \t\tOPT_END(),\n \t};\n \tstruct odb_source_packed *packed_source;\n \n-\toptions = add_common_options(builtin_multi_pack_index_verify_options);\n-\n \ttrace2_cmd_mode(argv[0]);\n \n \tif (isatty(2))\n@@ -342,8 +325,6 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,\n \t\t\t\t   options);\n \tpacked_source = handle_object_dir_option(repo);\n \n-\tFREE_AND_NULL(options);\n-\n \treturn verify_midx_file(packed_source, opts.flags);\n }\n \n@@ -351,14 +332,12 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv,\n \t\t\t\t       const char *prefix,\n \t\t\t\t       struct repository *repo)\n {\n-\tstruct option *options;\n-\tstatic struct option builtin_multi_pack_index_expire_options[] = {\n+\tstatic struct option options[] = {\n+\t\tMULTI_PACK_INDEX_COMMON_OPTIONS(&opts),\n \t\tOPT_END(),\n \t};\n \tstruct odb_source_packed *packed_source;\n \n-\toptions = add_common_options(builtin_multi_pack_index_expire_options);\n-\n \ttrace2_cmd_mode(argv[0]);\n \n \tif (isatty(2))\n@@ -371,8 +350,6 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv,\n \t\t\t\t   options);\n \tpacked_source = handle_object_dir_option(repo);\n \n-\tFREE_AND_NULL(options);\n-\n \treturn expire_midx_packs(packed_source, opts.flags);\n }\n \n@@ -380,16 +357,14 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,\n \t\t\t\t       const char *prefix,\n \t\t\t\t       struct repository *repo)\n {\n-\tstruct option *options;\n-\tstatic struct option builtin_multi_pack_index_repack_options[] = {\n+\tstatic struct option options[] = {\n \t\tOPT_UNSIGNED(0, \"batch-size\", &opts.batch_size,\n \t\t  N_(\"during repack, collect pack-files of smaller size into a batch that is larger than this size\")),\n+\t\tMULTI_PACK_INDEX_COMMON_OPTIONS(&opts),\n \t\tOPT_END(),\n \t};\n \tstruct odb_source_packed *packed_source;\n \n-\toptions = add_common_options(builtin_multi_pack_index_repack_options);\n-\n \ttrace2_cmd_mode(argv[0]);\n \n \tif (isatty(2))\n@@ -403,8 +378,6 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,\n \t\t\t\t   options);\n \tpacked_source = handle_object_dir_option(repo);\n \n-\tFREE_AND_NULL(options);\n-\n \treturn midx_repack(packed_source, (size_t)opts.batch_size, opts.flags);\n }\n \n-- \n2.56.0\n\n\n"},{"id":"559750","messageId":"d8ac438101939336c17481b18ab8f3636aaabbd5.1796075503.git.jltobler@gmail.com","threadId":"66963","inReplyTo":"cover.1796075503.git.jltobler@gmail.com","subject":"[PATCH 5/5] builtin/multi-pack-index: de-globalize options handling","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-11-30T21:55:01Z","receivedAt":"2026-11-30T21:55:01Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"The options for git-multi-pack-index(1) are stored in a global variable\neven though each option is only needed by the subcommand that parses it.\nThe config callback for the \"write\" and \"compact\" subcommands also\naccesses the options, but they can just as well be passed to it via the\ncallback data.\n\nNow that `cmd_multi_pack_index()` no longer parses any of these options\nitself, nothing requires them to be global anymore. Refactor each\nsubcommand to track its options in a local variable and pass them to the\nconfig callback accordingly. With this change, no global state remains\nin \"builtin/multi-pack-index.c\".\n\nSigned-off-by: Justin Tobler <jltobler@gmail.com>\n---\n builtin/multi-pack-index.c | 77 +++++++++++++++++++++++---------------\n 1 file changed, 47 insertions(+), 30 deletions(-)\n\ndiff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c\nindex d3881aee6a11..eb5c77456b33 100644\n--- a/builtin/multi-pack-index.c\n+++ b/builtin/multi-pack-index.c\n@@ -62,7 +62,7 @@ static char const * const builtin_multi_pack_index_usage[] = {\n \tNULL\n };\n \n-static struct opts_multi_pack_index {\n+struct opts_multi_pack_index {\n \tchar *object_dir;\n \tconst char *preferred_pack;\n \tconst char *incremental_base;\n@@ -70,8 +70,7 @@ static struct opts_multi_pack_index {\n \tunsigned long batch_size;\n \tunsigned flags;\n \tint stdin_packs;\n-} opts;\n-\n+};\n \n static int parse_object_dir(const struct option *opt, const char *arg,\n \t\t\t    int unset)\n@@ -85,9 +84,9 @@ static int parse_object_dir(const struct option *opt, const char *arg,\n \treturn 0;\n }\n \n-static struct odb_source_packed *handle_object_dir_option(struct repository *repo)\n+static struct odb_source_packed *handle_object_dir_option(struct repository *repo,\n+\t\t\t\t\t\t\t  const char *object_dir)\n {\n-\tconst char *object_dir = opts.object_dir;\n \tstruct odb_files_dir *dir;\n \n \tif (!object_dir)\n@@ -110,20 +109,22 @@ static struct odb_source_packed *handle_object_dir_option(struct repository *rep\n \n static int git_multi_pack_index_write_config(const char *var, const char *value,\n \t\t\t\t\t     const struct config_context *ctx UNUSED,\n-\t\t\t\t\t     void *cb UNUSED)\n+\t\t\t\t\t     void *cb_data)\n {\n+\tstruct opts_multi_pack_index *opts = cb_data;\n+\n \tif (!strcmp(var, \"pack.writebitmaphashcache\")) {\n \t\tif (git_config_bool(var, value))\n-\t\t\topts.flags |= MIDX_WRITE_BITMAP_HASH_CACHE;\n+\t\t\topts->flags |= MIDX_WRITE_BITMAP_HASH_CACHE;\n \t\telse\n-\t\t\topts.flags &= ~MIDX_WRITE_BITMAP_HASH_CACHE;\n+\t\t\topts->flags &= ~MIDX_WRITE_BITMAP_HASH_CACHE;\n \t}\n \n \tif (!strcmp(var, \"pack.writebitmaplookuptable\")) {\n \t\tif (git_config_bool(var, value))\n-\t\t\topts.flags |= MIDX_WRITE_BITMAP_LOOKUP_TABLE;\n+\t\t\topts->flags |= MIDX_WRITE_BITMAP_LOOKUP_TABLE;\n \t\telse\n-\t\t\topts.flags &= ~MIDX_WRITE_BITMAP_LOOKUP_TABLE;\n+\t\t\topts->flags &= ~MIDX_WRITE_BITMAP_LOOKUP_TABLE;\n \t}\n \n \t/*\n@@ -147,7 +148,8 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,\n \t\t\t\t      const char *prefix,\n \t\t\t\t      struct repository *repo)\n {\n-\tstatic struct option options[] = {\n+\tstruct opts_multi_pack_index opts = { 0 };\n+\tstruct option options[] = {\n \t\tOPT_STRING(0, \"preferred-pack\", &opts.preferred_pack,\n \t\t\t   N_(\"preferred-pack\"),\n \t\t\t   N_(\"pack for reuse when computing a multi-pack bitmap\")),\n@@ -172,7 +174,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,\n \n \topts.flags |= MIDX_WRITE_BITMAP_HASH_CACHE;\n \n-\trepo_config(repo, git_multi_pack_index_write_config, NULL);\n+\trepo_config(repo, git_multi_pack_index_write_config, &opts);\n \n \ttrace2_cmd_mode(argv[0]);\n \n@@ -200,7 +202,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,\n \t\t\t\t   options);\n \t}\n \n-\tpacked_source = handle_object_dir_option(repo);\n+\tpacked_source = handle_object_dir_option(repo, opts.object_dir);\n \n \tif (opts.stdin_packs) {\n \t\tstruct string_list packs = STRING_LIST_INIT_DUP;\n@@ -214,6 +216,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,\n \n \t\tstring_list_clear(&packs, 0);\n \t\tfree(opts.refs_snapshot);\n+\t\tfree(opts.object_dir);\n \n \t\treturn ret;\n \n@@ -223,6 +226,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,\n \t\t\t      opts.refs_snapshot, opts.flags);\n \n \tfree(opts.refs_snapshot);\n+\tfree(opts.object_dir);\n \treturn ret;\n }\n \n@@ -230,13 +234,14 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,\n \t\t\t\t\tconst char *prefix,\n \t\t\t\t\tstruct repository *repo)\n {\n+\tstruct opts_multi_pack_index opts = { 0 };\n \tstruct multi_pack_index *m, *cur;\n \tstruct multi_pack_index *from_midx = NULL;\n \tstruct multi_pack_index *to_midx = NULL;\n \tstruct odb_source_packed *packed_source;\n \tint ret;\n \n-\tstatic struct option options[] = {\n+\tstruct option options[] = {\n \t\tOPT_STRING(0, \"base\", &opts.incremental_base, N_(\"checksum\"),\n \t\t\t   N_(\"base MIDX for incremental writes\")),\n \t\tOPT_BIT(0, \"bitmap\", &opts.flags, N_(\"write multi-pack bitmap\"),\n@@ -250,7 +255,7 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,\n \t\tOPT_END(),\n \t};\n \n-\trepo_config(repo, git_multi_pack_index_write_config, NULL);\n+\trepo_config(repo, git_multi_pack_index_write_config, &opts);\n \n \ttrace2_cmd_mode(argv[0]);\n \n@@ -272,7 +277,7 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,\n \t\t\t\t   options);\n \t}\n \n-\tpacked_source = handle_object_dir_option(repo);\n+\tpacked_source = handle_object_dir_option(repo, opts.object_dir);\n \n \tm = get_multi_pack_index(packed_source);\n \n@@ -300,6 +305,7 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,\n \tret = write_midx_file_compact(packed_source, from_midx, to_midx,\n \t\t\t\t      opts.incremental_base, opts.flags);\n \n+\tfree(opts.object_dir);\n \treturn ret;\n }\n \n@@ -307,11 +313,13 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,\n \t\t\t\t       const char *prefix,\n \t\t\t\t       struct repository *repo)\n {\n-\tstatic struct option options[] = {\n+\tstruct opts_multi_pack_index opts = { 0 };\n+\tstruct option options[] = {\n \t\tMULTI_PACK_INDEX_COMMON_OPTIONS(&opts),\n \t\tOPT_END(),\n \t};\n \tstruct odb_source_packed *packed_source;\n+\tint ret;\n \n \ttrace2_cmd_mode(argv[0]);\n \n@@ -323,20 +331,25 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,\n \tif (argc)\n \t\tusage_with_options(builtin_multi_pack_index_verify_usage,\n \t\t\t\t   options);\n-\tpacked_source = handle_object_dir_option(repo);\n+\tpacked_source = handle_object_dir_option(repo, opts.object_dir);\n \n-\treturn verify_midx_file(packed_source, opts.flags);\n+\tret = verify_midx_file(packed_source, opts.flags);\n+\n+\tfree(opts.object_dir);\n+\treturn ret;\n }\n \n static int cmd_multi_pack_index_expire(int argc, const char **argv,\n \t\t\t\t       const char *prefix,\n \t\t\t\t       struct repository *repo)\n {\n-\tstatic struct option options[] = {\n+\tstruct opts_multi_pack_index opts = { 0 };\n+\tstruct option options[] = {\n \t\tMULTI_PACK_INDEX_COMMON_OPTIONS(&opts),\n \t\tOPT_END(),\n \t};\n \tstruct odb_source_packed *packed_source;\n+\tint ret;\n \n \ttrace2_cmd_mode(argv[0]);\n \n@@ -348,22 +361,27 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv,\n \tif (argc)\n \t\tusage_with_options(builtin_multi_pack_index_expire_usage,\n \t\t\t\t   options);\n-\tpacked_source = handle_object_dir_option(repo);\n+\tpacked_source = handle_object_dir_option(repo, opts.object_dir);\n+\n+\tret = expire_midx_packs(packed_source, opts.flags);\n \n-\treturn expire_midx_packs(packed_source, opts.flags);\n+\tfree(opts.object_dir);\n+\treturn ret;\n }\n \n static int cmd_multi_pack_index_repack(int argc, const char **argv,\n \t\t\t\t       const char *prefix,\n \t\t\t\t       struct repository *repo)\n {\n-\tstatic struct option options[] = {\n+\tstruct opts_multi_pack_index opts = { 0 };\n+\tstruct option options[] = {\n \t\tOPT_UNSIGNED(0, \"batch-size\", &opts.batch_size,\n \t\t  N_(\"during repack, collect pack-files of smaller size into a batch that is larger than this size\")),\n \t\tMULTI_PACK_INDEX_COMMON_OPTIONS(&opts),\n \t\tOPT_END(),\n \t};\n \tstruct odb_source_packed *packed_source;\n+\tint ret;\n \n \ttrace2_cmd_mode(argv[0]);\n \n@@ -376,9 +394,12 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,\n \tif (argc)\n \t\tusage_with_options(builtin_multi_pack_index_repack_usage,\n \t\t\t\t   options);\n-\tpacked_source = handle_object_dir_option(repo);\n+\tpacked_source = handle_object_dir_option(repo, opts.object_dir);\n+\n+\tret = midx_repack(packed_source, (size_t)opts.batch_size, opts.flags);\n \n-\treturn midx_repack(packed_source, (size_t)opts.batch_size, opts.flags);\n+\tfree(opts.object_dir);\n+\treturn ret;\n }\n \n int cmd_multi_pack_index(int argc,\n@@ -386,7 +407,6 @@ int cmd_multi_pack_index(int argc,\n \t\t\t const char *prefix,\n \t\t\t struct repository *repo)\n {\n-\tint res;\n \tparse_opt_subcommand_fn *fn = NULL;\n \tstruct option options[] = {\n \t\tOPT_SUBCOMMAND(\"repack\", &fn, cmd_multi_pack_index_repack),\n@@ -404,8 +424,5 @@ int cmd_multi_pack_index(int argc,\n \targc = parse_options(argc, argv, prefix, options,\n \t\t\t     builtin_multi_pack_index_usage, 0);\n \n-\tres = fn(argc, argv, prefix, repo);\n-\n-\tfree(opts.object_dir);\n-\treturn res;\n+\treturn fn(argc, argv, prefix, repo);\n }\n-- \n2.56.0\n\n\n"},{"id":"559773","messageId":"aw6oO92LKQJM9TwS@pks.im","threadId":"66963","inReplyTo":"c381afb0da593080ae8fc96a6187b579da829658.1796075503.git.jltobler@gmail.com","subject":"Re: [PATCH 1/5] builtin/multi-pack-index: resolve default object directory lazily","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-12-01T10:58:13Z","receivedAt":"2026-12-01T10:58:13Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Mon, Nov 30, 2026 at 03:54:57PM -0600, Justin Tobler wrote:\n> diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c\n> index c48212290cf8..1a27d523c7ab 100644\n> --- a/builtin/multi-pack-index.c\n> +++ b/builtin/multi-pack-index.c\n> @@ -80,7 +80,7 @@ static int parse_object_dir(const struct option *opt, const char *arg,\n>  \tchar **value = opt->value;\n>  \tfree(*value);\n>  \tif (unset)\n> -\t\t*value = xstrdup(the_repository->objects->source->path);\n> +\t\t*value = NULL;\n>  \telse\n>  \t\t*value = real_pathdup(arg, 1);\n>  \treturn 0;\n\nMakes me wonder whether we could avoid allocating the value altogether\nand just assign the static string?\n\n> @@ -88,10 +88,16 @@ static int parse_object_dir(const struct option *opt, const char *arg,\n>  \n>  static struct odb_source_packed *handle_object_dir_option(struct repository *repo)\n>  {\n> -\tstruct odb_files_dir *dir = odb_source_files_find_dir(repo->objects, opts.object_dir);\n> +\tconst char *object_dir = opts.object_dir;\n> +\tstruct odb_files_dir *dir;\n> +\n> +\tif (!object_dir)\n> +\t\tobject_dir = repo->objects->source->path;\n> +\n> +\tdir = odb_source_files_find_dir(repo->objects, object_dir);\n>  \tif (!dir)\n>  \t\tdie(_(\"object directory is not an alternate of the current repository: '%s'\"),\n> -\t\t    opts.object_dir);\n> +\t\t    object_dir);\n>  \treturn dir->packed;\n>  }\n\nOkay, so instead of handling the default value in `parse_object_dir()`\nwe set it up here. Makes sense.\n\n> @@ -424,11 +430,6 @@ int cmd_multi_pack_index(int argc,\n>  \n>  \trepo_config(the_repository, git_default_config, NULL);\n>  \n> -\tif (the_repository &&\n> -\t    the_repository->objects &&\n> -\t    the_repository->objects->source)\n> -\t\topts.object_dir = xstrdup(the_repository->objects->source->path);\n\nWe previously handled the case where there is no repository, but we\ndon't do that in `handle_object_dir_option()`. But this command does not\nrun without a repository anyway, so that looks like a sensible change to\nme.\n\nPatrick\n\n"},{"id":"559774","messageId":"aw6oSl_-1eyDrMYB@pks.im","threadId":"66963","inReplyTo":"673945d65de346762178b675ad6d0de9606cc6ca.1796075503.git.jltobler@gmail.com","subject":"Re: [PATCH 2/5] builtin/multi-pack-index: get rid of `the_repository`","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-12-01T10:58:18Z","receivedAt":"2026-12-01T10:58:18Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Mon, Nov 30, 2026 at 03:54:58PM -0600, Justin Tobler wrote:\n> There are a couple of remaining references to `the_repository` in\n> git-multi-pack-index(1). The command cannot run outside of a repository,\n> so these references can be trivially replaced with the repository\n> passed to the subcommands.\n\nRight, but only in the case where `repo` is not dereferenced before we\ncall `parse_options()`. You do pass it to `repo_config()`, which\n(somewhat misleadingly) accepts `repo == NULL`.\n\n> diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c\n> index 1a27d523c7ab..8528f4f513ef 100644\n> --- a/builtin/multi-pack-index.c\n> +++ b/builtin/multi-pack-index.c\n\nAll of the conversions look fine to me, as there are no new callsites\nthat dereference the repository before `parse_options()`.\n\nPatrick\n\n"},{"id":"559775","messageId":"aw6oUL0h_zEMtCy8@pks.im","threadId":"66963","inReplyTo":"cc2876d6803f4ac5d504ce18a5380949b97e65cf.1796075503.git.jltobler@gmail.com","subject":"Re: [PATCH 3/5] builtin/multi-pack-index: drop top-level options","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-12-01T10:58:24Z","receivedAt":"2026-12-01T10:58:24Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Mon, Nov 30, 2026 at 03:54:59PM -0600, Justin Tobler wrote:\n> When invoking git-multi-pack-index(1), the \"--object-dir=\" and\n> \"--[no-]progress\" options can be given either before or after the\n> subcommand. This calling convention is atypical for Git commands, and it\n> requires the options parsed by `cmd_multi_pack_index()` to be stored in\n> global state so that they can be accessed by the subcommands. Neither\n> option needs to be accepted before the subcommand though.\n\nAh, this essentially does the same change that I'm also doing for\ngit-rerere(1) in an in-flight patch series. I'm obviously in favor of\nsuch changes -- they break backwards compatibility, but if you ask me\nit's a sensible change to make us more consistent.\n\n> The \"--[no-]progress\" option was already removed from the top-level\n> builtin in 0394f8d002 (builtin/multi-pack-index.c: disable top-level\n> --[no-]progress, 2021-09-20). When given before the subcommand, the\n> option is not always respected, as each subcommand overrides it\n> depending on whether stderr is connected to a terminal. Furthermore, a\n> subcommand without a notion of progress would have to ignore the option\n> altogether. The option was inadvertently reintroduced by 6b8fb17490\n> (builtin/multi-pack-index.c: make '--progress' a common option,\n> 2026-02-24), which moved it into the common options that are also parsed\n> by `cmd_multi_pack_index()`. Consequently, \"git multi-pack-index\n> --no-progress write\" still shows progress when stderr is connected to a\n> terminal.\n\nHeh, fun.\n\n> diff --git a/Documentation/git-multi-pack-index.adoc b/Documentation/git-multi-pack-index.adoc\n> index c6d23aeeb9a0..0dd675f3fd46 100644\n> --- a/Documentation/git-multi-pack-index.adoc\n> +++ b/Documentation/git-multi-pack-index.adoc\n> @@ -9,16 +9,16 @@ git-multi-pack-index - Write and verify multi-pack-indexes\n>  SYNOPSIS\n>  --------\n>  [verse]\n> -'git multi-pack-index' [<options>] write [--preferred-pack=<pack>]\n> +'git multi-pack-index' write [<options>] [--preferred-pack=<pack>]\n\nIs the `[<options>]` placeholder even required now? We already list all\nthe options, don't we?\n\n> diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c\n> index 8528f4f513ef..2b4e2f0cce9e 100644\n> --- a/builtin/multi-pack-index.c\n> +++ b/builtin/multi-pack-index.c\n> @@ -415,7 +415,7 @@ int cmd_multi_pack_index(int argc,\n>  {\n>  \tint res;\n>  \tparse_opt_subcommand_fn *fn = NULL;\n> -\tstruct option builtin_multi_pack_index_options[] = {\n> +\tstruct option options[] = {\n>  \t\tOPT_SUBCOMMAND(\"repack\", &fn, cmd_multi_pack_index_repack),\n>  \t\tOPT_SUBCOMMAND(\"write\", &fn, cmd_multi_pack_index_write),\n>  \t\tOPT_SUBCOMMAND(\"compact\", &fn, cmd_multi_pack_index_compact),\n> @@ -423,7 +423,6 @@ int cmd_multi_pack_index(int argc,\n>  \t\tOPT_SUBCOMMAND(\"expire\", &fn, cmd_multi_pack_index_expire),\n>  \t\tOPT_END(),\n>  \t};\n> -\tstruct option *options = parse_options_concat(builtin_multi_pack_index_options, common_opts);\n>  \n>  \tdisable_replace_refs();\n>  \n> @@ -431,7 +430,6 @@ int cmd_multi_pack_index(int argc,\n>  \n>  \targc = parse_options(argc, argv, prefix, options,\n>  \t\t\t     builtin_multi_pack_index_usage, 0);\n> -\tFREE_AND_NULL(options);\n>  \n>  \tres = fn(argc, argv, prefix, repo);\n>  \n\nI really dislike this `parse_options_concat()` pattern. We can also\neasily replace it by defininging something like:\n\n        #define MULTI_PACK_INDEX_COMMON_OPTIONS(var) \\\n                OPT_FOO(...), \\\n                OPT_BAR(...)\n\nAnd then you simply add it to the options at compile time. So maybe\nthat's another refactoring we could add in a subsequent patch?\n\n... Ah, you already do in your next patch. Great!\n\nPatrick\n\n"},{"id":"559776","messageId":"aw6oWC_yENDJjd3h@pks.im","threadId":"66963","inReplyTo":"1c16a0988239253b3695c68c138b4b71ccc00de9.1796075503.git.jltobler@gmail.com","subject":"Re: [PATCH 4/5] builtin/multi-pack-index: simplify how common options are wired up","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-12-01T10:58:32Z","receivedAt":"2026-12-01T10:58:32Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Mon, Nov 30, 2026 at 03:55:00PM -0600, Justin Tobler wrote:\n> diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c\n> index 2b4e2f0cce9e..d3881aee6a11 100644\n> --- a/builtin/multi-pack-index.c\n> +++ b/builtin/multi-pack-index.c\n> @@ -100,20 +100,13 @@ static struct odb_source_packed *handle_object_dir_option(struct repository *rep\n>  \treturn dir->packed;\n>  }\n>  \n> -static struct option common_opts[] = {\n> -\tOPT_CALLBACK(0, \"object-dir\", &opts.object_dir,\n> -\t  N_(\"directory\"),\n> -\t  N_(\"object directory containing set of packfile and pack-index pairs\"),\n> -\t  parse_object_dir),\n> -\tOPT_BIT(0, \"progress\", &opts.flags, N_(\"force progress reporting\"),\n> -\t\tMIDX_PROGRESS),\n> -\tOPT_END(),\n> -};\n> -\n> -static struct option *add_common_options(struct option *prev)\n> -{\n> -\treturn parse_options_concat(common_opts, prev);\n> -}\n> +#define MULTI_PACK_INDEX_COMMON_OPTIONS(opts) \\\n> +\tOPT_CALLBACK(0, \"object-dir\", &(opts)->object_dir, \\\n> +\t  N_(\"directory\"), \\\n> +\t  N_(\"object directory containing set of packfile and pack-index pairs\"), \\\n> +\t  parse_object_dir), \\\n> +\tOPT_BIT(0, \"progress\", &(opts)->flags, N_(\"force progress reporting\"), \\\n> +\t\tMIDX_PROGRESS)\n\nAwesome, exactly what I was hoping for.\n\n> @@ -154,8 +147,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,\n>  \t\t\t\t      const char *prefix,\n>  \t\t\t\t      struct repository *repo)\n>  {\n> -\tstruct option *options;\n> -\tstatic struct option builtin_multi_pack_index_write_options[] = {\n> +\tstatic struct option options[] = {\n>  \t\tOPT_STRING(0, \"preferred-pack\", &opts.preferred_pack,\n>  \t\t\t   N_(\"preferred-pack\"),\n>  \t\t\t   N_(\"pack for reuse when computing a multi-pack bitmap\")),\n> @@ -172,6 +164,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,\n>  \t\t\t N_(\"write multi-pack index containing only given indexes\")),\n>  \t\tOPT_FILENAME(0, \"refs-snapshot\", &opts.refs_snapshot,\n>  \t\t\t     N_(\"refs snapshot for selecting bitmap commits\")),\n> +\t\tMULTI_PACK_INDEX_COMMON_OPTIONS(&opts),\n>  \t\tOPT_END(),\n>  \t};\n>  \tstruct odb_source_packed *packed_source;\n\nI think this causes a slight change in that the common opitons are now\nat the end of these options, whereas they have been at the beginning\nbeforehand. Doesn't really matter much, but it can also easily be\navoided by adding the common options first.\n\n> @@ -380,16 +357,14 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,\n>  \t\t\t\t       const char *prefix,\n>  \t\t\t\t       struct repository *repo)\n>  {\n> -\tstruct option *options;\n> -\tstatic struct option builtin_multi_pack_index_repack_options[] = {\n> +\tstatic struct option options[] = {\n>  \t\tOPT_UNSIGNED(0, \"batch-size\", &opts.batch_size,\n>  \t\t  N_(\"during repack, collect pack-files of smaller size into a batch that is larger than this size\")),\n> +\t\tMULTI_PACK_INDEX_COMMON_OPTIONS(&opts),\n>  \t\tOPT_END(),\n>  \t};\n\nLikewise.\n\nPatrick\n\n"},{"id":"559777","messageId":"aw6onR6DqUkKJmzY@pks.im","threadId":"66963","inReplyTo":"d8ac438101939336c17481b18ab8f3636aaabbd5.1796075503.git.jltobler@gmail.com","subject":"Re: [PATCH 5/5] builtin/multi-pack-index: de-globalize options handling","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-12-01T10:59:41Z","receivedAt":"2026-12-01T10:59:41Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Mon, Nov 30, 2026 at 03:55:01PM -0600, Justin Tobler wrote:\n> diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c\n> index d3881aee6a11..eb5c77456b33 100644\n> --- a/builtin/multi-pack-index.c\n> +++ b/builtin/multi-pack-index.c\n> @@ -214,6 +216,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,\n>  \n>  \t\tstring_list_clear(&packs, 0);\n>  \t\tfree(opts.refs_snapshot);\n> +\t\tfree(opts.object_dir);\n>  \n>  \t\treturn ret;\n>  \n> @@ -223,6 +226,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,\n>  \t\t\t      opts.refs_snapshot, opts.flags);\n>  \n>  \tfree(opts.refs_snapshot);\n> +\tfree(opts.object_dir);\n>  \treturn ret;\n>  }\n\nOkay. Now that the options aren't global anymore we of course have to\nfree everything they reference. It would have been nice though to unify\nthe logic a bit, either by introducing a common return path or by\nintroducing a function that releases the memory held on to by `opts`. Or\nboth.\n\n> @@ -404,8 +424,5 @@ int cmd_multi_pack_index(int argc,\n>  \targc = parse_options(argc, argv, prefix, options,\n>  \t\t\t     builtin_multi_pack_index_usage, 0);\n>  \n> -\tres = fn(argc, argv, prefix, repo);\n> -\n> -\tfree(opts.object_dir);\n> -\treturn res;\n> +\treturn fn(argc, argv, prefix, repo);\n\nAh, no, not quite. We did free it, but in the global function. Quite\nugly, so good that we're getting rid of this now.\n\nThanks!\n\nPatrick\n\n"},{"id":"559815","messageId":"aw73WMyW-Ri79rWU@denethor","threadId":"66963","inReplyTo":"aw6oO92LKQJM9TwS@pks.im","subject":"Re: [PATCH 1/5] builtin/multi-pack-index: resolve default object directory lazily","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-12-01T16:39:00Z","receivedAt":"2026-12-01T16:39:00Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"On 26/12/01 11:58AM, Patrick Steinhardt wrote:\n> On Mon, Nov 30, 2026 at 03:54:57PM -0600, Justin Tobler wrote:\n> > diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c\n> > index c48212290cf8..1a27d523c7ab 100644\n> > --- a/builtin/multi-pack-index.c\n> > +++ b/builtin/multi-pack-index.c\n> > @@ -80,7 +80,7 @@ static int parse_object_dir(const struct option *opt, const char *arg,\n> >  \tchar **value = opt->value;\n> >  \tfree(*value);\n> >  \tif (unset)\n> > -\t\t*value = xstrdup(the_repository->objects->source->path);\n> > +\t\t*value = NULL;\n> >  \telse\n> >  \t\t*value = real_pathdup(arg, 1);\n> >  \treturn 0;\n> \n> Makes me wonder whether we could avoid allocating the value altogether\n> and just assign the static string?\n\nYa, now that the option value is only set here, it should be fine to\nstop allocating the string. Will update in the next version.\n\n-Justin\n\n"},{"id":"559817","messageId":"aw74PSIwv5SLYbvl@denethor","threadId":"66963","inReplyTo":"aw6oSl_-1eyDrMYB@pks.im","subject":"Re: [PATCH 2/5] builtin/multi-pack-index: get rid of `the_repository`","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-12-01T16:46:51Z","receivedAt":"2026-12-01T16:46:51Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"On 26/12/01 11:58AM, Patrick Steinhardt wrote:\n> On Mon, Nov 30, 2026 at 03:54:58PM -0600, Justin Tobler wrote:\n> > There are a couple of remaining references to `the_repository` in\n> > git-multi-pack-index(1). The command cannot run outside of a repository,\n> > so these references can be trivially replaced with the repository\n> > passed to the subcommands.\n> \n> Right, but only in the case where `repo` is not dereferenced before we\n> call `parse_options()`. You do pass it to `repo_config()`, which\n> (somewhat misleadingly) accepts `repo == NULL`.\n\nThat is correct. The repository could still be NULL here when running\nsomething like `git multi-pack-index -h` in which case would need to be\nhandled by `parse_options()` first. I'll try to clarify the message\nslightly in the next version.\n\n-Justin\n\n"},{"id":"559818","messageId":"aw76H8aiByt-UFZp@denethor","threadId":"66963","inReplyTo":"aw6oUL0h_zEMtCy8@pks.im","subject":"Re: [PATCH 3/5] builtin/multi-pack-index: drop top-level options","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-12-01T17:11:21Z","receivedAt":"2026-12-01T17:11:21Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"On 26/12/01 11:58AM, Patrick Steinhardt wrote:\n> On Mon, Nov 30, 2026 at 03:54:59PM -0600, Justin Tobler wrote:\n> > diff --git a/Documentation/git-multi-pack-index.adoc b/Documentation/git-multi-pack-index.adoc\n> > index c6d23aeeb9a0..0dd675f3fd46 100644\n> > --- a/Documentation/git-multi-pack-index.adoc\n> > +++ b/Documentation/git-multi-pack-index.adoc\n> > @@ -9,16 +9,16 @@ git-multi-pack-index - Write and verify multi-pack-indexes\n> >  SYNOPSIS\n> >  --------\n> >  [verse]\n> > -'git multi-pack-index' [<options>] write [--preferred-pack=<pack>]\n> > +'git multi-pack-index' write [<options>] [--preferred-pack=<pack>]\n> \n> Is the `[<options>]` placeholder even required now? We already list all\n> the options, don't we?\n\nBoth the synopsis and usage strings still only explicitly list the\noptions specific to each subcommand. The common options are only denoted\nvia `[<options>]`. It might just be better to be explicit here though\nand write out both the common options for each of the subcommands. I'll\ndo this in the next version.\n\n> > diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c\n> > index 8528f4f513ef..2b4e2f0cce9e 100644\n> > --- a/builtin/multi-pack-index.c\n> > +++ b/builtin/multi-pack-index.c\n> > @@ -415,7 +415,7 @@ int cmd_multi_pack_index(int argc,\n> >  {\n> >  \tint res;\n> >  \tparse_opt_subcommand_fn *fn = NULL;\n> > -\tstruct option builtin_multi_pack_index_options[] = {\n> > +\tstruct option options[] = {\n> >  \t\tOPT_SUBCOMMAND(\"repack\", &fn, cmd_multi_pack_index_repack),\n> >  \t\tOPT_SUBCOMMAND(\"write\", &fn, cmd_multi_pack_index_write),\n> >  \t\tOPT_SUBCOMMAND(\"compact\", &fn, cmd_multi_pack_index_compact),\n> > @@ -423,7 +423,6 @@ int cmd_multi_pack_index(int argc,\n> >  \t\tOPT_SUBCOMMAND(\"expire\", &fn, cmd_multi_pack_index_expire),\n> >  \t\tOPT_END(),\n> >  \t};\n> > -\tstruct option *options = parse_options_concat(builtin_multi_pack_index_options, common_opts);\n> >  \n> >  \tdisable_replace_refs();\n> >  \n> > @@ -431,7 +430,6 @@ int cmd_multi_pack_index(int argc,\n> >  \n> >  \targc = parse_options(argc, argv, prefix, options,\n> >  \t\t\t     builtin_multi_pack_index_usage, 0);\n> > -\tFREE_AND_NULL(options);\n> >  \n> >  \tres = fn(argc, argv, prefix, repo);\n> >  \n> \n> I really dislike this `parse_options_concat()` pattern. We can also\n> easily replace it by defininging something like:\n> \n>         #define MULTI_PACK_INDEX_COMMON_OPTIONS(var) \\\n>                 OPT_FOO(...), \\\n>                 OPT_BAR(...)\n> \n> And then you simply add it to the options at compile time. So maybe\n> that's another refactoring we could add in a subsequent patch?\n> \n> ... Ah, you already do in your next patch. Great!\n\nYup! :)\n\n-Justin\n\n"},{"id":"559819","messageId":"aw7_6efAzLClbLMY@denethor","threadId":"66963","inReplyTo":"aw6oWC_yENDJjd3h@pks.im","subject":"Re: [PATCH 4/5] builtin/multi-pack-index: simplify how common options are wired up","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-12-01T17:13:00Z","receivedAt":"2026-12-01T17:13:00Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"On 26/12/01 11:58AM, Patrick Steinhardt wrote:\n> On Mon, Nov 30, 2026 at 03:55:00PM -0600, Justin Tobler wrote:\n> > @@ -154,8 +147,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,\n> >  \t\t\t\t      const char *prefix,\n> >  \t\t\t\t      struct repository *repo)\n> >  {\n> > -\tstruct option *options;\n> > -\tstatic struct option builtin_multi_pack_index_write_options[] = {\n> > +\tstatic struct option options[] = {\n> >  \t\tOPT_STRING(0, \"preferred-pack\", &opts.preferred_pack,\n> >  \t\t\t   N_(\"preferred-pack\"),\n> >  \t\t\t   N_(\"pack for reuse when computing a multi-pack bitmap\")),\n> > @@ -172,6 +164,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,\n> >  \t\t\t N_(\"write multi-pack index containing only given indexes\")),\n> >  \t\tOPT_FILENAME(0, \"refs-snapshot\", &opts.refs_snapshot,\n> >  \t\t\t     N_(\"refs snapshot for selecting bitmap commits\")),\n> > +\t\tMULTI_PACK_INDEX_COMMON_OPTIONS(&opts),\n> >  \t\tOPT_END(),\n> >  \t};\n> >  \tstruct odb_source_packed *packed_source;\n> \n> I think this causes a slight change in that the common opitons are now\n> at the end of these options, whereas they have been at the beginning\n> beforehand. Doesn't really matter much, but it can also easily be\n> avoided by adding the common options first.\n\nGood catch. I'll move the common options to the front in the next\nversion.\n\n-Justin\n\n"},{"id":"559820","messageId":"aw8A3FPmNwUvMoMC@denethor","threadId":"66963","inReplyTo":"aw6onR6DqUkKJmzY@pks.im","subject":"Re: [PATCH 5/5] builtin/multi-pack-index: de-globalize options handling","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-12-01T17:18:45Z","receivedAt":"2026-12-01T17:18:45Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"On 26/12/01 11:59AM, Patrick Steinhardt wrote:\n> On Mon, Nov 30, 2026 at 03:55:01PM -0600, Justin Tobler wrote:\n> > diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c\n> > index d3881aee6a11..eb5c77456b33 100644\n> > --- a/builtin/multi-pack-index.c\n> > +++ b/builtin/multi-pack-index.c\n> > @@ -214,6 +216,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,\n> >  \n> >  \t\tstring_list_clear(&packs, 0);\n> >  \t\tfree(opts.refs_snapshot);\n> > +\t\tfree(opts.object_dir);\n> >  \n> >  \t\treturn ret;\n> >  \n> > @@ -223,6 +226,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,\n> >  \t\t\t      opts.refs_snapshot, opts.flags);\n> >  \n> >  \tfree(opts.refs_snapshot);\n> > +\tfree(opts.object_dir);\n> >  \treturn ret;\n> >  }\n> \n> Okay. Now that the options aren't global anymore we of course have to\n> free everything they reference. It would have been nice though to unify\n> the logic a bit, either by introducing a common return path or by\n> introducing a function that releases the memory held on to by `opts`. Or\n> both.\n\nWith the changes suggested for patch 1, \"--object-dir=\" no longer needs\nto be allocated, and consuently no longer needs to be freed. I'll leave\nthe existing handling of `refs_snapshot` as-is for now.\n\nThanks for the review,\n-Justin\n\n"},{"id":"559825","messageId":"cover.1796147221.git.jltobler@gmail.com","threadId":"66963","inReplyTo":"cover.1796075503.git.jltobler@gmail.com","subject":"[PATCH v2 0/5] builtin/multi-pack-index: remove global state","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-12-01T18:16:11Z","receivedAt":"2026-12-01T18:16:11Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"Greetings,\n\nThis series cleans up git-multi-pack-index(1) by getting rid of\n`the_repository` and the global state used to track its options. Each\nsubcommand now parses its options into a local structure, and the common\noptions are wired up via a macro instead of allocating a combined\noptions array for every subcommand.\n\nThe main reason the options are global is that \"--object-dir=\" and\n\"--[no-]progress\" are also accepted before the subcommand, where the\ntop-level builtin parses them into the same global state used by the\nsubcommands. Patch 3 drops support for giving these options before the\nsubcommand, as every subcommand already accepts both of them.\n\nThe \"--[no-]progress\" option was previously removed as a top-level\noption in 0394f8d002 (builtin/multi-pack-index.c: disable top-level\n--[no-]progress, 2021-09-20) and appears to have been inadvertently\nreintroduced via 6b8fb17490 (builtin/multi-pack-index.c: make\n'--progress' a common option, 2026-02-24). So I think it should be fine\nto drop.\n\nWhile \"--object-dir=\" has never previously been dropped, it appears to\nexist as a top-level option for the same historical reason, from when\nall options were parsed by the top-level builtin. Since the subcommands\nalready parse the common options themselves, it should ideally be\ndropped as well. If we want to keep this top-level option though, an\nalternative could be to propagate the option argument to each\nsubcommand. In this case, I don't think it's worth it, but happy to\nchange if others feel differently.\n\nThis series is built on top of 86e79b2795 (The 26th batch, 2026-11-29).\n\nChanges since V1:\n  - \"--object-dir=\" is now parsed via `OPT_STRING()`, so the option\n    value no longer needs to be allocated or freed.\n  - Clarified in the message of patch 2 that the repository may still be\n    `NULL` until `parse_options()` has been called.\n  - The synopsis and usage strings now explicitly list the common\n    options instead of using the `[<options>]` placeholder.\n  - The common options are now added at the front of each options array,\n    so the order of the \"-h\" output stays the same.\n\nThanks for the review,\n-Justin\n\nJustin Tobler (5):\n  builtin/multi-pack-index: resolve default object directory lazily\n  builtin/multi-pack-index: get rid of `the_repository`\n  builtin/multi-pack-index: drop top-level options\n  builtin/multi-pack-index: simplify how common options are wired up\n  builtin/multi-pack-index: de-globalize options handling\n\n Documentation/git-multi-pack-index.adoc |  23 ++--\n builtin/multi-pack-index.c              | 165 +++++++++---------------\n t/lib-midx.sh                           |   2 +-\n t/t5319-multi-pack-index.sh             |  32 ++---\n 4 files changed, 91 insertions(+), 131 deletions(-)\n\nRange-diff against v1:\n1:  c381afb0da59 ! 1:  3e6369b99ba3 builtin/multi-pack-index: resolve default object directory lazily\n    @@ Commit message\n         where the repository is passed in explicitly. This also removes the\n         need for the defensive `NULL` checks guarding the eager initialization.\n     \n    +    With the default handled lazily, the callback for \"--object-dir=\" is\n    +    only left to resolve the given path via `real_pathdup()`. This is\n    +    unnecessary though, as `odb_source_files_find_dir()` already resolves\n    +    the path itself when looking up the matching object directory. Replace\n    +    the callback with a plain `OPT_STRING()`, which also means that the\n    +    option value no longer has to be allocated and freed.\n    +\n         Signed-off-by: Justin Tobler <jltobler@gmail.com>\n     \n      ## builtin/multi-pack-index.c ##\n    -@@ builtin/multi-pack-index.c: static int parse_object_dir(const struct option *opt, const char *arg,\n    - \tchar **value = opt->value;\n    - \tfree(*value);\n    - \tif (unset)\n    --\t\t*value = xstrdup(the_repository->objects->source->path);\n    -+\t\t*value = NULL;\n    - \telse\n    - \t\t*value = real_pathdup(arg, 1);\n    - \treturn 0;\n    -@@ builtin/multi-pack-index.c: static int parse_object_dir(const struct option *opt, const char *arg,\n    +@@\n    + #define USE_THE_REPOSITORY_VARIABLE\n    + #include \"builtin.h\"\n    +-#include \"abspath.h\"\n    + #include \"config.h\"\n    + #include \"environment.h\"\n    + #include \"gettext.h\"\n    +@@ builtin/multi-pack-index.c: static char const * const builtin_multi_pack_index_usage[] = {\n    + };\n    + \n    + static struct opts_multi_pack_index {\n    +-\tchar *object_dir;\n    ++\tconst char *object_dir;\n    + \tconst char *preferred_pack;\n    + \tconst char *incremental_base;\n    + \tchar *refs_snapshot;\n    +@@ builtin/multi-pack-index.c: static struct opts_multi_pack_index {\n    + \tint stdin_packs;\n    + } opts;\n      \n    +-\n    +-static int parse_object_dir(const struct option *opt, const char *arg,\n    +-\t\t\t    int unset)\n    +-{\n    +-\tchar **value = opt->value;\n    +-\tfree(*value);\n    +-\tif (unset)\n    +-\t\t*value = xstrdup(the_repository->objects->source->path);\n    +-\telse\n    +-\t\t*value = real_pathdup(arg, 1);\n    +-\treturn 0;\n    +-}\n    +-\n      static struct odb_source_packed *handle_object_dir_option(struct repository *repo)\n      {\n     -\tstruct odb_files_dir *dir = odb_source_files_find_dir(repo->objects, opts.object_dir);\n    @@ builtin/multi-pack-index.c: static int parse_object_dir(const struct option *opt\n      \treturn dir->packed;\n      }\n      \n    + static struct option common_opts[] = {\n    +-\tOPT_CALLBACK(0, \"object-dir\", &opts.object_dir,\n    +-\t  N_(\"directory\"),\n    +-\t  N_(\"object directory containing set of packfile and pack-index pairs\"),\n    +-\t  parse_object_dir),\n    ++\tOPT_STRING(0, \"object-dir\", &opts.object_dir, N_(\"directory\"),\n    ++\t  N_(\"object directory containing set of packfile and pack-index pairs\")),\n    + \tOPT_BIT(0, \"progress\", &opts.flags, N_(\"force progress reporting\"),\n    + \t\tMIDX_PROGRESS),\n    + \tOPT_END(),\n     @@ builtin/multi-pack-index.c: int cmd_multi_pack_index(int argc,\n      \n      \trepo_config(the_repository, git_default_config, NULL);\n    @@ builtin/multi-pack-index.c: int cmd_multi_pack_index(int argc,\n      \targc = parse_options(argc, argv, prefix, options,\n      \t\t\t     builtin_multi_pack_index_usage, 0);\n      \tFREE_AND_NULL(options);\n    + \n    + \tres = fn(argc, argv, prefix, repo);\n    + \n    +-\tfree(opts.object_dir);\n    + \treturn res;\n    + }\n2:  673945d65de3 ! 2:  28d7916f0a24 builtin/multi-pack-index: get rid of `the_repository`\n    @@ Commit message\n         builtin/multi-pack-index: get rid of `the_repository`\n     \n         There are a couple of remaining references to `the_repository` in\n    -    git-multi-pack-index(1). The command cannot run outside of a repository,\n    -    so these references can be trivially replaced with the repository\n    -    passed to the subcommands.\n    +    git-multi-pack-index(1). Replace them with the repository that is passed\n    +    to the builtin and its subcommands.\n    +\n    +    Note that the repository may still be `NULL` until `parse_options()` has\n    +    been called. The only use of the repository before that point is\n    +    `repo_config()`, which handles a `NULL` repository.\n     \n         Signed-off-by: Justin Tobler <jltobler@gmail.com>\n     \n    @@ builtin/multi-pack-index.c\n     @@\n     -#define USE_THE_REPOSITORY_VARIABLE\n      #include \"builtin.h\"\n    - #include \"abspath.h\"\n      #include \"config.h\"\n    + #include \"environment.h\"\n     @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_write(int argc, const char **argv,\n      \n      \topts.flags |= MIDX_WRITE_BITMAP_HASH_CACHE;\n3:  cc2876d6803f ! 3:  5fe18c5564c3 builtin/multi-pack-index: drop top-level options\n    @@ Documentation/git-multi-pack-index.adoc: git-multi-pack-index - Write and verify\n      --------\n      [verse]\n     -'git multi-pack-index' [<options>] write [--preferred-pack=<pack>]\n    -+'git multi-pack-index' write [<options>] [--preferred-pack=<pack>]\n    - \t\t         [--[no-]bitmap] [--[no-]incremental] [--[no-]stdin-packs]\n    - \t\t         [--refs-snapshot=<path>] [--[no-]write-chain-file]\n    - \t\t\t [--base=<checksum>]\n    +-\t\t         [--[no-]bitmap] [--[no-]incremental] [--[no-]stdin-packs]\n    +-\t\t         [--refs-snapshot=<path>] [--[no-]write-chain-file]\n    +-\t\t\t [--base=<checksum>]\n     -'git multi-pack-index' [<options>] compact [--[no-]incremental]\n    -+'git multi-pack-index' compact [<options>] [--[no-]incremental]\n    - \t\t         [--[no-]bitmap] [--base=<checksum>] [--[no-]write-chain-file]\n    - \t\t\t <from> <to>\n    +-\t\t         [--[no-]bitmap] [--base=<checksum>] [--[no-]write-chain-file]\n    +-\t\t\t <from> <to>\n     -'git multi-pack-index' [<options>] verify\n     -'git multi-pack-index' [<options>] expire\n     -'git multi-pack-index' [<options>] repack [--batch-size=<size>]\n    -+'git multi-pack-index' verify [<options>]\n    -+'git multi-pack-index' expire [<options>]\n    -+'git multi-pack-index' repack [<options>] [--batch-size=<size>]\n    ++'git multi-pack-index' write [--object-dir=<dir>] [--[no-]progress]\n    ++\t\t         [--preferred-pack=<pack>] [--[no-]bitmap] [--[no-]incremental]\n    ++\t\t         [--[no-]stdin-packs] [--refs-snapshot=<path>]\n    ++\t\t         [--[no-]write-chain-file] [--base=<checksum>]\n    ++'git multi-pack-index' compact [--object-dir=<dir>] [--[no-]progress]\n    ++\t\t         [--[no-]incremental] [--[no-]bitmap] [--base=<checksum>]\n    ++\t\t         [--[no-]write-chain-file] <from> <to>\n    ++'git multi-pack-index' verify [--object-dir=<dir>] [--[no-]progress]\n    ++'git multi-pack-index' expire [--object-dir=<dir>] [--[no-]progress]\n    ++'git multi-pack-index' repack [--object-dir=<dir>] [--[no-]progress]\n    ++\t\t         [--batch-size=<size>]\n      \n      DESCRIPTION\n      -----------\n    @@ builtin/multi-pack-index.c\n      \n      #define BUILTIN_MIDX_WRITE_USAGE \\\n     -\tN_(\"git multi-pack-index [<options>] write [--preferred-pack=<pack>]\\n\" \\\n    -+\tN_(\"git multi-pack-index write [<options>] [--preferred-pack=<pack>]\\n\" \\\n    - \t   \"  [--[no-]bitmap] [--[no-]incremental] [--[no-]stdin-packs]\\n\" \\\n    - \t   \"  [--refs-snapshot=<path>] [--[no-]write-chain-file]\\n\" \\\n    - \t   \"  [--base=<checksum>]\")\n    +-\t   \"  [--[no-]bitmap] [--[no-]incremental] [--[no-]stdin-packs]\\n\" \\\n    +-\t   \"  [--refs-snapshot=<path>] [--[no-]write-chain-file]\\n\" \\\n    +-\t   \"  [--base=<checksum>]\")\n    ++\tN_(\"git multi-pack-index write [--object-dir=<dir>] [--[no-]progress]\\n\" \\\n    ++\t   \"  [--preferred-pack=<pack>] [--[no-]bitmap] [--[no-]incremental]\\n\" \\\n    ++\t   \"  [--[no-]stdin-packs] [--refs-snapshot=<path>]\\n\" \\\n    ++\t   \"  [--[no-]write-chain-file] [--base=<checksum>]\")\n      \n      #define BUILTIN_MIDX_COMPACT_USAGE \\\n     -\tN_(\"git multi-pack-index [<options>] compact [--[no-]incremental]\\n\" \\\n    -+\tN_(\"git multi-pack-index compact [<options>] [--[no-]incremental]\\n\" \\\n    - \t   \"  [--[no-]bitmap] [--base=<checksum>] [--[no-]write-chain-file]\\n\" \\\n    - \t   \"  <from> <to>\")\n    +-\t   \"  [--[no-]bitmap] [--base=<checksum>] [--[no-]write-chain-file]\\n\" \\\n    +-\t   \"  <from> <to>\")\n    ++\tN_(\"git multi-pack-index compact [--object-dir=<dir>] [--[no-]progress]\\n\" \\\n    ++\t   \"  [--[no-]incremental] [--[no-]bitmap] [--base=<checksum>]\\n\" \\\n    ++\t   \"  [--[no-]write-chain-file] <from> <to>\")\n      \n      #define BUILTIN_MIDX_VERIFY_USAGE \\\n     -\tN_(\"git multi-pack-index [<options>] verify\")\n    -+\tN_(\"git multi-pack-index verify [<options>]\")\n    ++\tN_(\"git multi-pack-index verify [--object-dir=<dir>] [--[no-]progress]\")\n      \n      #define BUILTIN_MIDX_EXPIRE_USAGE \\\n     -\tN_(\"git multi-pack-index [<options>] expire\")\n    -+\tN_(\"git multi-pack-index expire [<options>]\")\n    ++\tN_(\"git multi-pack-index expire [--object-dir=<dir>] [--[no-]progress]\")\n      \n      #define BUILTIN_MIDX_REPACK_USAGE \\\n     -\tN_(\"git multi-pack-index [<options>] repack [--batch-size=<size>]\")\n    -+\tN_(\"git multi-pack-index repack [<options>] [--batch-size=<size>]\")\n    ++\tN_(\"git multi-pack-index repack [--object-dir=<dir>] [--[no-]progress]\\n\" \\\n    ++\t   \"  [--batch-size=<size>]\")\n      \n      static char const * const builtin_multi_pack_index_write_usage[] = {\n      \tBUILTIN_MIDX_WRITE_USAGE,\n4:  1c16a0988239 ! 4:  3bb2b9a69f1c builtin/multi-pack-index: simplify how common options are wired up\n    @@ builtin/multi-pack-index.c: static struct odb_source_packed *handle_object_dir_o\n      }\n      \n     -static struct option common_opts[] = {\n    --\tOPT_CALLBACK(0, \"object-dir\", &opts.object_dir,\n    --\t  N_(\"directory\"),\n    --\t  N_(\"object directory containing set of packfile and pack-index pairs\"),\n    --\t  parse_object_dir),\n    +-\tOPT_STRING(0, \"object-dir\", &opts.object_dir, N_(\"directory\"),\n    +-\t  N_(\"object directory containing set of packfile and pack-index pairs\")),\n     -\tOPT_BIT(0, \"progress\", &opts.flags, N_(\"force progress reporting\"),\n     -\t\tMIDX_PROGRESS),\n     -\tOPT_END(),\n    @@ builtin/multi-pack-index.c: static struct odb_source_packed *handle_object_dir_o\n     -\treturn parse_options_concat(common_opts, prev);\n     -}\n     +#define MULTI_PACK_INDEX_COMMON_OPTIONS(opts) \\\n    -+\tOPT_CALLBACK(0, \"object-dir\", &(opts)->object_dir, \\\n    -+\t  N_(\"directory\"), \\\n    -+\t  N_(\"object directory containing set of packfile and pack-index pairs\"), \\\n    -+\t  parse_object_dir), \\\n    ++\tOPT_STRING(0, \"object-dir\", &(opts)->object_dir, N_(\"directory\"), \\\n    ++\t  N_(\"object directory containing set of packfile and pack-index pairs\")), \\\n     +\tOPT_BIT(0, \"progress\", &(opts)->flags, N_(\"force progress reporting\"), \\\n     +\t\tMIDX_PROGRESS)\n      \n    @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_write(int argc, cons\n     -\tstruct option *options;\n     -\tstatic struct option builtin_multi_pack_index_write_options[] = {\n     +\tstatic struct option options[] = {\n    ++\t\tMULTI_PACK_INDEX_COMMON_OPTIONS(&opts),\n      \t\tOPT_STRING(0, \"preferred-pack\", &opts.preferred_pack,\n      \t\t\t   N_(\"preferred-pack\"),\n      \t\t\t   N_(\"pack for reuse when computing a multi-pack bitmap\")),\n     @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_write(int argc, const char **argv,\n    - \t\t\t N_(\"write multi-pack index containing only given indexes\")),\n    - \t\tOPT_FILENAME(0, \"refs-snapshot\", &opts.refs_snapshot,\n    - \t\t\t     N_(\"refs snapshot for selecting bitmap commits\")),\n    -+\t\tMULTI_PACK_INDEX_COMMON_OPTIONS(&opts),\n    - \t\tOPT_END(),\n    - \t};\n    - \tstruct odb_source_packed *packed_source;\n    -@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_write(int argc, const char **argv,\n      \n      \trepo_config(repo, git_multi_pack_index_write_config, NULL);\n      \n    @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_compact(int argc, co\n     -\tstruct option *options;\n     -\tstatic struct option builtin_multi_pack_index_compact_options[] = {\n     +\tstatic struct option options[] = {\n    ++\t\tMULTI_PACK_INDEX_COMMON_OPTIONS(&opts),\n      \t\tOPT_STRING(0, \"base\", &opts.incremental_base, N_(\"checksum\"),\n      \t\t\t   N_(\"base MIDX for incremental writes\")),\n      \t\tOPT_BIT(0, \"bitmap\", &opts.flags, N_(\"write multi-pack bitmap\"),\n     @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_compact(int argc, const char **argv,\n    - \t\tOPT_NEGBIT(0, \"write-chain-file\", &opts.flags,\n    - \t\t\tN_(\"write the multi-pack-index chain file\"),\n    - \t\t\tMIDX_WRITE_NO_CHAIN),\n    -+\t\tMULTI_PACK_INDEX_COMMON_OPTIONS(&opts),\n    - \t\tOPT_END(),\n    - \t};\n      \n      \trepo_config(repo, git_multi_pack_index_write_config, NULL);\n      \n    @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_repack(int argc, con\n     -\tstruct option *options;\n     -\tstatic struct option builtin_multi_pack_index_repack_options[] = {\n     +\tstatic struct option options[] = {\n    ++\t\tMULTI_PACK_INDEX_COMMON_OPTIONS(&opts),\n      \t\tOPT_UNSIGNED(0, \"batch-size\", &opts.batch_size,\n      \t\t  N_(\"during repack, collect pack-files of smaller size into a batch that is larger than this size\")),\n    -+\t\tMULTI_PACK_INDEX_COMMON_OPTIONS(&opts),\n      \t\tOPT_END(),\n      \t};\n      \tstruct odb_source_packed *packed_source;\n5:  d8ac43810193 ! 5:  46a59a5daf52 builtin/multi-pack-index: de-globalize options handling\n    @@ builtin/multi-pack-index.c: static char const * const builtin_multi_pack_index_u\n      \n     -static struct opts_multi_pack_index {\n     +struct opts_multi_pack_index {\n    - \tchar *object_dir;\n    + \tconst char *object_dir;\n      \tconst char *preferred_pack;\n      \tconst char *incremental_base;\n     @@ builtin/multi-pack-index.c: static struct opts_multi_pack_index {\n    @@ builtin/multi-pack-index.c: static struct opts_multi_pack_index {\n      \tunsigned flags;\n      \tint stdin_packs;\n     -} opts;\n    --\n     +};\n      \n    - static int parse_object_dir(const struct option *opt, const char *arg,\n    - \t\t\t    int unset)\n    -@@ builtin/multi-pack-index.c: static int parse_object_dir(const struct option *opt, const char *arg,\n    - \treturn 0;\n    - }\n    - \n     -static struct odb_source_packed *handle_object_dir_option(struct repository *repo)\n     +static struct odb_source_packed *handle_object_dir_option(struct repository *repo,\n     +\t\t\t\t\t\t\t  const char *object_dir)\n    @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_write(int argc, cons\n     -\tstatic struct option options[] = {\n     +\tstruct opts_multi_pack_index opts = { 0 };\n     +\tstruct option options[] = {\n    + \t\tMULTI_PACK_INDEX_COMMON_OPTIONS(&opts),\n      \t\tOPT_STRING(0, \"preferred-pack\", &opts.preferred_pack,\n      \t\t\t   N_(\"preferred-pack\"),\n    - \t\t\t   N_(\"pack for reuse when computing a multi-pack bitmap\")),\n     @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_write(int argc, const char **argv,\n      \n      \topts.flags |= MIDX_WRITE_BITMAP_HASH_CACHE;\n    @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_write(int argc, cons\n      \n      \tif (opts.stdin_packs) {\n      \t\tstruct string_list packs = STRING_LIST_INIT_DUP;\n    -@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_write(int argc, const char **argv,\n    - \n    - \t\tstring_list_clear(&packs, 0);\n    - \t\tfree(opts.refs_snapshot);\n    -+\t\tfree(opts.object_dir);\n    - \n    - \t\treturn ret;\n    - \n    -@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_write(int argc, const char **argv,\n    - \t\t\t      opts.refs_snapshot, opts.flags);\n    - \n    - \tfree(opts.refs_snapshot);\n    -+\tfree(opts.object_dir);\n    - \treturn ret;\n    - }\n    - \n     @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_compact(int argc, const char **argv,\n      \t\t\t\t\tconst char *prefix,\n      \t\t\t\t\tstruct repository *repo)\n    @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_compact(int argc, co\n      \n     -\tstatic struct option options[] = {\n     +\tstruct option options[] = {\n    + \t\tMULTI_PACK_INDEX_COMMON_OPTIONS(&opts),\n      \t\tOPT_STRING(0, \"base\", &opts.incremental_base, N_(\"checksum\"),\n      \t\t\t   N_(\"base MIDX for incremental writes\")),\n    - \t\tOPT_BIT(0, \"bitmap\", &opts.flags, N_(\"write multi-pack bitmap\"),\n     @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_compact(int argc, const char **argv,\n      \t\tOPT_END(),\n      \t};\n    @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_compact(int argc, co\n      \n      \tm = get_multi_pack_index(packed_source);\n      \n    -@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_compact(int argc, const char **argv,\n    - \tret = write_midx_file_compact(packed_source, from_midx, to_midx,\n    - \t\t\t\t      opts.incremental_base, opts.flags);\n    - \n    -+\tfree(opts.object_dir);\n    - \treturn ret;\n    - }\n    - \n     @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_verify(int argc, const char **argv,\n      \t\t\t\t       const char *prefix,\n      \t\t\t\t       struct repository *repo)\n    @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_verify(int argc, con\n      \t\tMULTI_PACK_INDEX_COMMON_OPTIONS(&opts),\n      \t\tOPT_END(),\n      \t};\n    - \tstruct odb_source_packed *packed_source;\n    -+\tint ret;\n    - \n    - \ttrace2_cmd_mode(argv[0]);\n    - \n     @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_verify(int argc, const char **argv,\n      \tif (argc)\n      \t\tusage_with_options(builtin_multi_pack_index_verify_usage,\n    @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_verify(int argc, con\n     -\tpacked_source = handle_object_dir_option(repo);\n     +\tpacked_source = handle_object_dir_option(repo, opts.object_dir);\n      \n    --\treturn verify_midx_file(packed_source, opts.flags);\n    -+\tret = verify_midx_file(packed_source, opts.flags);\n    -+\n    -+\tfree(opts.object_dir);\n    -+\treturn ret;\n    + \treturn verify_midx_file(packed_source, opts.flags);\n      }\n    - \n    - static int cmd_multi_pack_index_expire(int argc, const char **argv,\n    +@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_expire(int argc, const char **argv,\n      \t\t\t\t       const char *prefix,\n      \t\t\t\t       struct repository *repo)\n      {\n    @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_verify(int argc, con\n      \t\tMULTI_PACK_INDEX_COMMON_OPTIONS(&opts),\n      \t\tOPT_END(),\n      \t};\n    - \tstruct odb_source_packed *packed_source;\n    -+\tint ret;\n    - \n    - \ttrace2_cmd_mode(argv[0]);\n    - \n     @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_expire(int argc, const char **argv,\n      \tif (argc)\n      \t\tusage_with_options(builtin_multi_pack_index_expire_usage,\n      \t\t\t\t   options);\n     -\tpacked_source = handle_object_dir_option(repo);\n     +\tpacked_source = handle_object_dir_option(repo, opts.object_dir);\n    -+\n    -+\tret = expire_midx_packs(packed_source, opts.flags);\n      \n    --\treturn expire_midx_packs(packed_source, opts.flags);\n    -+\tfree(opts.object_dir);\n    -+\treturn ret;\n    + \treturn expire_midx_packs(packed_source, opts.flags);\n      }\n    - \n    - static int cmd_multi_pack_index_repack(int argc, const char **argv,\n    +@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_repack(int argc, const char **argv,\n      \t\t\t\t       const char *prefix,\n      \t\t\t\t       struct repository *repo)\n      {\n     -\tstatic struct option options[] = {\n     +\tstruct opts_multi_pack_index opts = { 0 };\n     +\tstruct option options[] = {\n    + \t\tMULTI_PACK_INDEX_COMMON_OPTIONS(&opts),\n      \t\tOPT_UNSIGNED(0, \"batch-size\", &opts.batch_size,\n      \t\t  N_(\"during repack, collect pack-files of smaller size into a batch that is larger than this size\")),\n    - \t\tMULTI_PACK_INDEX_COMMON_OPTIONS(&opts),\n    - \t\tOPT_END(),\n    - \t};\n    - \tstruct odb_source_packed *packed_source;\n    -+\tint ret;\n    - \n    - \ttrace2_cmd_mode(argv[0]);\n    - \n     @@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_repack(int argc, const char **argv,\n      \tif (argc)\n      \t\tusage_with_options(builtin_multi_pack_index_repack_usage,\n      \t\t\t\t   options);\n     -\tpacked_source = handle_object_dir_option(repo);\n     +\tpacked_source = handle_object_dir_option(repo, opts.object_dir);\n    -+\n    -+\tret = midx_repack(packed_source, (size_t)opts.batch_size, opts.flags);\n      \n    --\treturn midx_repack(packed_source, (size_t)opts.batch_size, opts.flags);\n    -+\tfree(opts.object_dir);\n    -+\treturn ret;\n    + \treturn midx_repack(packed_source, (size_t)opts.batch_size, opts.flags);\n      }\n    - \n    - int cmd_multi_pack_index(int argc,\n     @@ builtin/multi-pack-index.c: int cmd_multi_pack_index(int argc,\n      \t\t\t const char *prefix,\n      \t\t\t struct repository *repo)\n    @@ builtin/multi-pack-index.c: int cmd_multi_pack_index(int argc,\n      \n     -\tres = fn(argc, argv, prefix, repo);\n     -\n    --\tfree(opts.object_dir);\n     -\treturn res;\n     +\treturn fn(argc, argv, prefix, repo);\n      }\n\nbase-commit: 86e79b2795e3ce3b0ad7685edd368574b0c8b9f2\n-- \n2.56.0\n\n\n"},{"id":"559826","messageId":"3e6369b99ba39b135fc1b315dc0721d098968e13.1796147221.git.jltobler@gmail.com","threadId":"66963","inReplyTo":"cover.1796147221.git.jltobler@gmail.com","subject":"[PATCH v2 1/5] builtin/multi-pack-index: resolve default object directory lazily","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-12-01T18:16:12Z","receivedAt":"2026-12-01T18:16:12Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"The object directory used by git-multi-pack-index(1) defaults to the\npath of the primary object database source. This default is set eagerly\nin `cmd_multi_pack_index()` before any options are parsed, and again\nwhen \"--no-object-dir\" is given. Both cases access `the_repository` to\ndo so, and the eager initialization additionally has to guard against\nthe repository not being set up.\n\nIn a subsequent commit, the remaining references to `the_repository` in\n\"builtin/multi-pack-index.c\" are removed. In preparation for this\nchange, leave the object directory unset in both cases and lazily fall\nback to the path of the primary source in `handle_object_dir_option()`,\nwhere the repository is passed in explicitly. This also removes the\nneed for the defensive `NULL` checks guarding the eager initialization.\n\nWith the default handled lazily, the callback for \"--object-dir=\" is\nonly left to resolve the given path via `real_pathdup()`. This is\nunnecessary though, as `odb_source_files_find_dir()` already resolves\nthe path itself when looking up the matching object directory. Replace\nthe callback with a plain `OPT_STRING()`, which also means that the\noption value no longer has to be allocated and freed.\n\nSigned-off-by: Justin Tobler <jltobler@gmail.com>\n---\n builtin/multi-pack-index.c | 38 +++++++++++---------------------------\n 1 file changed, 11 insertions(+), 27 deletions(-)\n\ndiff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c\nindex c48212290cf8..ba5f326dd6ef 100644\n--- a/builtin/multi-pack-index.c\n+++ b/builtin/multi-pack-index.c\n@@ -1,6 +1,5 @@\n #define USE_THE_REPOSITORY_VARIABLE\n #include \"builtin.h\"\n-#include \"abspath.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\n@@ -64,7 +63,7 @@ static char const * const builtin_multi_pack_index_usage[] = {\n };\n \n static struct opts_multi_pack_index {\n-\tchar *object_dir;\n+\tconst char *object_dir;\n \tconst char *preferred_pack;\n \tconst char *incremental_base;\n \tchar *refs_snapshot;\n@@ -73,33 +72,24 @@ static struct opts_multi_pack_index {\n \tint stdin_packs;\n } opts;\n \n-\n-static int parse_object_dir(const struct option *opt, const char *arg,\n-\t\t\t    int unset)\n-{\n-\tchar **value = opt->value;\n-\tfree(*value);\n-\tif (unset)\n-\t\t*value = xstrdup(the_repository->objects->source->path);\n-\telse\n-\t\t*value = real_pathdup(arg, 1);\n-\treturn 0;\n-}\n-\n static struct odb_source_packed *handle_object_dir_option(struct repository *repo)\n {\n-\tstruct odb_files_dir *dir = odb_source_files_find_dir(repo->objects, opts.object_dir);\n+\tconst char *object_dir = opts.object_dir;\n+\tstruct odb_files_dir *dir;\n+\n+\tif (!object_dir)\n+\t\tobject_dir = repo->objects->source->path;\n+\n+\tdir = odb_source_files_find_dir(repo->objects, object_dir);\n \tif (!dir)\n \t\tdie(_(\"object directory is not an alternate of the current repository: '%s'\"),\n-\t\t    opts.object_dir);\n+\t\t    object_dir);\n \treturn dir->packed;\n }\n \n static struct option common_opts[] = {\n-\tOPT_CALLBACK(0, \"object-dir\", &opts.object_dir,\n-\t  N_(\"directory\"),\n-\t  N_(\"object directory containing set of packfile and pack-index pairs\"),\n-\t  parse_object_dir),\n+\tOPT_STRING(0, \"object-dir\", &opts.object_dir, N_(\"directory\"),\n+\t  N_(\"object directory containing set of packfile and pack-index pairs\")),\n \tOPT_BIT(0, \"progress\", &opts.flags, N_(\"force progress reporting\"),\n \t\tMIDX_PROGRESS),\n \tOPT_END(),\n@@ -424,17 +414,11 @@ int cmd_multi_pack_index(int argc,\n \n \trepo_config(the_repository, git_default_config, NULL);\n \n-\tif (the_repository &&\n-\t    the_repository->objects &&\n-\t    the_repository->objects->source)\n-\t\topts.object_dir = xstrdup(the_repository->objects->source->path);\n-\n \targc = parse_options(argc, argv, prefix, options,\n \t\t\t     builtin_multi_pack_index_usage, 0);\n \tFREE_AND_NULL(options);\n \n \tres = fn(argc, argv, prefix, repo);\n \n-\tfree(opts.object_dir);\n \treturn res;\n }\n-- \n2.56.0\n\n\n"},{"id":"559827","messageId":"28d7916f0a24c2cc382f86940af0459bf85b9a6e.1796147221.git.jltobler@gmail.com","threadId":"66963","inReplyTo":"cover.1796147221.git.jltobler@gmail.com","subject":"[PATCH v2 2/5] builtin/multi-pack-index: get rid of `the_repository`","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-12-01T18:16:13Z","receivedAt":"2026-12-01T18:16:13Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"There are a couple of remaining references to `the_repository` in\ngit-multi-pack-index(1). Replace them with the repository that is passed\nto the builtin and its subcommands.\n\nNote that the repository may still be `NULL` until `parse_options()` has\nbeen called. The only use of the repository before that point is\n`repo_config()`, which handles a `NULL` repository.\n\nSigned-off-by: Justin Tobler <jltobler@gmail.com>\n---\n builtin/multi-pack-index.c | 19 +++++++++----------\n 1 file changed, 9 insertions(+), 10 deletions(-)\n\ndiff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c\nindex ba5f326dd6ef..c1ad8ebbcc15 100644\n--- a/builtin/multi-pack-index.c\n+++ b/builtin/multi-pack-index.c\n@@ -1,4 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"environment.h\"\n@@ -164,7 +163,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,\n \n \topts.flags |= MIDX_WRITE_BITMAP_HASH_CACHE;\n \n-\trepo_config(the_repository, git_multi_pack_index_write_config, NULL);\n+\trepo_config(repo, git_multi_pack_index_write_config, NULL);\n \n \toptions = add_common_options(builtin_multi_pack_index_write_options);\n \n@@ -270,7 +269,7 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,\n \t\t\t\t   options);\n \t}\n \n-\tpacked_source = handle_object_dir_option(the_repository);\n+\tpacked_source = handle_object_dir_option(repo);\n \n \tFREE_AND_NULL(options);\n \n@@ -305,7 +304,7 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,\n \n static int cmd_multi_pack_index_verify(int argc, 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 option *options;\n \tstatic struct option builtin_multi_pack_index_verify_options[] = {\n@@ -325,7 +324,7 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,\n \tif (argc)\n \t\tusage_with_options(builtin_multi_pack_index_verify_usage,\n \t\t\t\t   options);\n-\tpacked_source = handle_object_dir_option(the_repository);\n+\tpacked_source = handle_object_dir_option(repo);\n \n \tFREE_AND_NULL(options);\n \n@@ -334,7 +333,7 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,\n \n static int cmd_multi_pack_index_expire(int argc, 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 option *options;\n \tstatic struct option builtin_multi_pack_index_expire_options[] = {\n@@ -354,7 +353,7 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv,\n \tif (argc)\n \t\tusage_with_options(builtin_multi_pack_index_expire_usage,\n \t\t\t\t   options);\n-\tpacked_source = handle_object_dir_option(the_repository);\n+\tpacked_source = handle_object_dir_option(repo);\n \n \tFREE_AND_NULL(options);\n \n@@ -363,7 +362,7 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv,\n \n static int cmd_multi_pack_index_repack(int argc, 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 option *options;\n \tstatic struct option builtin_multi_pack_index_repack_options[] = {\n@@ -386,7 +385,7 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,\n \tif (argc)\n \t\tusage_with_options(builtin_multi_pack_index_repack_usage,\n \t\t\t\t   options);\n-\tpacked_source = handle_object_dir_option(the_repository);\n+\tpacked_source = handle_object_dir_option(repo);\n \n \tFREE_AND_NULL(options);\n \n@@ -412,7 +411,7 @@ int cmd_multi_pack_index(int argc,\n \n \tdisable_replace_refs();\n \n-\trepo_config(the_repository, git_default_config, NULL);\n+\trepo_config(repo, git_default_config, NULL);\n \n \targc = parse_options(argc, argv, prefix, options,\n \t\t\t     builtin_multi_pack_index_usage, 0);\n-- \n2.56.0\n\n\n"},{"id":"559828","messageId":"5fe18c5564c35cb42785c955dcc0a6872a5ab910.1796147221.git.jltobler@gmail.com","threadId":"66963","inReplyTo":"cover.1796147221.git.jltobler@gmail.com","subject":"[PATCH v2 3/5] builtin/multi-pack-index: drop top-level options","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-12-01T18:16:14Z","receivedAt":"2026-12-01T18:16:14Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"When invoking git-multi-pack-index(1), the \"--object-dir=\" and\n\"--[no-]progress\" options can be given either before or after the\nsubcommand. This calling convention is atypical for Git commands, and it\nrequires the options parsed by `cmd_multi_pack_index()` to be stored in\nglobal state so that they can be accessed by the subcommands. Neither\noption needs to be accepted before the subcommand though.\n\nThe \"--[no-]progress\" option was already removed from the top-level\nbuiltin in 0394f8d002 (builtin/multi-pack-index.c: disable top-level\n--[no-]progress, 2021-09-20). When given before the subcommand, the\noption is not always respected, as each subcommand overrides it\ndepending on whether stderr is connected to a terminal. Furthermore, a\nsubcommand without a notion of progress would have to ignore the option\naltogether. The option was inadvertently reintroduced by 6b8fb17490\n(builtin/multi-pack-index.c: make '--progress' a common option,\n2026-02-24), which moved it into the common options that are also parsed\nby `cmd_multi_pack_index()`. Consequently, \"git multi-pack-index\n--no-progress write\" still shows progress when stderr is connected to a\nterminal.\n\nUnlike \"--[no-]progress\", the \"--object-dir=\" option was kept at the top\nlevel when 60ca94769c (builtin/multi-pack-index.c: split sub-commands,\n2021-03-30) taught each subcommand to parse its own options. Giving the\noption after the subcommand is the preferred form, so also accepting it\nat the top level is no longer necessary.\n\nDrop both options from the top-level builtin so that they are only\naccepted by the subcommands. This brings the command in line with how\nGit typically handles options and avoids the need for global state to\npass the options down to the subcommands. Update the synopsis, the usage\nstrings and the example in the documentation accordingly.\n\nSigned-off-by: Justin Tobler <jltobler@gmail.com>\n---\n Documentation/git-multi-pack-index.adoc | 23 +++++++++---------\n builtin/multi-pack-index.c              | 25 ++++++++++---------\n t/lib-midx.sh                           |  2 +-\n t/t5319-multi-pack-index.sh             | 32 ++++++++++++-------------\n 4 files changed, 41 insertions(+), 41 deletions(-)\n\ndiff --git a/Documentation/git-multi-pack-index.adoc b/Documentation/git-multi-pack-index.adoc\nindex c6d23aeeb9a0..65e09a3012d1 100644\n--- a/Documentation/git-multi-pack-index.adoc\n+++ b/Documentation/git-multi-pack-index.adoc\n@@ -9,16 +9,17 @@ git-multi-pack-index - Write and verify multi-pack-indexes\n SYNOPSIS\n --------\n [verse]\n-'git multi-pack-index' [<options>] write [--preferred-pack=<pack>]\n-\t\t         [--[no-]bitmap] [--[no-]incremental] [--[no-]stdin-packs]\n-\t\t         [--refs-snapshot=<path>] [--[no-]write-chain-file]\n-\t\t\t [--base=<checksum>]\n-'git multi-pack-index' [<options>] compact [--[no-]incremental]\n-\t\t         [--[no-]bitmap] [--base=<checksum>] [--[no-]write-chain-file]\n-\t\t\t <from> <to>\n-'git multi-pack-index' [<options>] verify\n-'git multi-pack-index' [<options>] expire\n-'git multi-pack-index' [<options>] repack [--batch-size=<size>]\n+'git multi-pack-index' write [--object-dir=<dir>] [--[no-]progress]\n+\t\t         [--preferred-pack=<pack>] [--[no-]bitmap] [--[no-]incremental]\n+\t\t         [--[no-]stdin-packs] [--refs-snapshot=<path>]\n+\t\t         [--[no-]write-chain-file] [--base=<checksum>]\n+'git multi-pack-index' compact [--object-dir=<dir>] [--[no-]progress]\n+\t\t         [--[no-]incremental] [--[no-]bitmap] [--base=<checksum>]\n+\t\t         [--[no-]write-chain-file] <from> <to>\n+'git multi-pack-index' verify [--object-dir=<dir>] [--[no-]progress]\n+'git multi-pack-index' expire [--object-dir=<dir>] [--[no-]progress]\n+'git multi-pack-index' repack [--object-dir=<dir>] [--[no-]progress]\n+\t\t         [--batch-size=<size>]\n \n DESCRIPTION\n -----------\n@@ -183,7 +184,7 @@ $ git multi-pack-index write --preferred-pack=<pack> --bitmap\n * Write a MIDX file for the packfiles in an alternate object store.\n +\n -----------------------------------------------\n-$ git multi-pack-index --object-dir <alt> write\n+$ git multi-pack-index write --object-dir <alt>\n -----------------------------------------------\n \n * Verify the MIDX file for the packfiles in the current `.git` directory.\ndiff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c\nindex c1ad8ebbcc15..e84df0c947ce 100644\n--- a/builtin/multi-pack-index.c\n+++ b/builtin/multi-pack-index.c\n@@ -13,24 +13,25 @@\n #include \"repository.h\"\n \n #define BUILTIN_MIDX_WRITE_USAGE \\\n-\tN_(\"git multi-pack-index [<options>] write [--preferred-pack=<pack>]\\n\" \\\n-\t   \"  [--[no-]bitmap] [--[no-]incremental] [--[no-]stdin-packs]\\n\" \\\n-\t   \"  [--refs-snapshot=<path>] [--[no-]write-chain-file]\\n\" \\\n-\t   \"  [--base=<checksum>]\")\n+\tN_(\"git multi-pack-index write [--object-dir=<dir>] [--[no-]progress]\\n\" \\\n+\t   \"  [--preferred-pack=<pack>] [--[no-]bitmap] [--[no-]incremental]\\n\" \\\n+\t   \"  [--[no-]stdin-packs] [--refs-snapshot=<path>]\\n\" \\\n+\t   \"  [--[no-]write-chain-file] [--base=<checksum>]\")\n \n #define BUILTIN_MIDX_COMPACT_USAGE \\\n-\tN_(\"git multi-pack-index [<options>] compact [--[no-]incremental]\\n\" \\\n-\t   \"  [--[no-]bitmap] [--base=<checksum>] [--[no-]write-chain-file]\\n\" \\\n-\t   \"  <from> <to>\")\n+\tN_(\"git multi-pack-index compact [--object-dir=<dir>] [--[no-]progress]\\n\" \\\n+\t   \"  [--[no-]incremental] [--[no-]bitmap] [--base=<checksum>]\\n\" \\\n+\t   \"  [--[no-]write-chain-file] <from> <to>\")\n \n #define BUILTIN_MIDX_VERIFY_USAGE \\\n-\tN_(\"git multi-pack-index [<options>] verify\")\n+\tN_(\"git multi-pack-index verify [--object-dir=<dir>] [--[no-]progress]\")\n \n #define BUILTIN_MIDX_EXPIRE_USAGE \\\n-\tN_(\"git multi-pack-index [<options>] expire\")\n+\tN_(\"git multi-pack-index expire [--object-dir=<dir>] [--[no-]progress]\")\n \n #define BUILTIN_MIDX_REPACK_USAGE \\\n-\tN_(\"git multi-pack-index [<options>] repack [--batch-size=<size>]\")\n+\tN_(\"git multi-pack-index repack [--object-dir=<dir>] [--[no-]progress]\\n\" \\\n+\t   \"  [--batch-size=<size>]\")\n \n static char const * const builtin_multi_pack_index_write_usage[] = {\n \tBUILTIN_MIDX_WRITE_USAGE,\n@@ -399,7 +400,7 @@ int cmd_multi_pack_index(int argc,\n {\n \tint res;\n \tparse_opt_subcommand_fn *fn = NULL;\n-\tstruct option builtin_multi_pack_index_options[] = {\n+\tstruct option options[] = {\n \t\tOPT_SUBCOMMAND(\"repack\", &fn, cmd_multi_pack_index_repack),\n \t\tOPT_SUBCOMMAND(\"write\", &fn, cmd_multi_pack_index_write),\n \t\tOPT_SUBCOMMAND(\"compact\", &fn, cmd_multi_pack_index_compact),\n@@ -407,7 +408,6 @@ int cmd_multi_pack_index(int argc,\n \t\tOPT_SUBCOMMAND(\"expire\", &fn, cmd_multi_pack_index_expire),\n \t\tOPT_END(),\n \t};\n-\tstruct option *options = parse_options_concat(builtin_multi_pack_index_options, common_opts);\n \n \tdisable_replace_refs();\n \n@@ -415,7 +415,6 @@ int cmd_multi_pack_index(int argc,\n \n \targc = parse_options(argc, argv, prefix, options,\n \t\t\t     builtin_multi_pack_index_usage, 0);\n-\tFREE_AND_NULL(options);\n \n \tres = fn(argc, argv, prefix, repo);\n \ndiff --git a/t/lib-midx.sh b/t/lib-midx.sh\nindex e38c609604c3..d7dc09b382ec 100644\n--- a/t/lib-midx.sh\n+++ b/t/lib-midx.sh\n@@ -4,7 +4,7 @@ test_midx_consistent () {\n \ttest-tool read-midx $1 | grep ^pack-.*\\.idx$ | sort >actual &&\n \n \ttest_cmp expect actual &&\n-\tgit multi-pack-index --object-dir=$1 verify\n+\tgit multi-pack-index verify --object-dir=$1\n }\n \n midx_checksum () {\ndiff --git a/t/t5319-multi-pack-index.sh b/t/t5319-multi-pack-index.sh\nindex e1684e3e69d7..b366add863d1 100755\n--- a/t/t5319-multi-pack-index.sh\n+++ b/t/t5319-multi-pack-index.sh\n@@ -50,7 +50,7 @@ test_expect_success 'setup' '\n '\n \n test_expect_success \"don't write midx with no packs\" '\n-\ttest_must_fail git multi-pack-index --object-dir=. write &&\n+\ttest_must_fail git multi-pack-index write --object-dir=. &&\n \ttest_path_is_missing pack/multi-pack-index\n '\n \n@@ -122,13 +122,13 @@ test_expect_success 'write midx with one v1 pack' '\n \tpack=$(git pack-objects --index-version=1 $objdir/pack/test <obj-list) &&\n \ttest_when_finished rm $objdir/pack/test-$pack.pack \\\n \t\t$objdir/pack/test-$pack.idx $objdir/pack/multi-pack-index &&\n-\tgit multi-pack-index --object-dir=$objdir write &&\n+\tgit multi-pack-index write --object-dir=$objdir &&\n \tmidx_read_expect 1 18 4 $objdir\n '\n \n test_expect_success 'write midx with one v2 pack' '\n \tgit pack-objects --index-version=2,0x40 $objdir/pack/test <obj-list &&\n-\tgit multi-pack-index --object-dir=$objdir write &&\n+\tgit multi-pack-index write --object-dir=$objdir &&\n \tmidx_read_expect 1 18 4 $objdir\n '\n \n@@ -158,7 +158,7 @@ test_expect_success 'add more objects' '\n \n test_expect_success 'write midx with two packs' '\n \tgit pack-objects --index-version=1 $objdir/pack/test-2 <obj-list &&\n-\tgit multi-pack-index --object-dir=$objdir write &&\n+\tgit multi-pack-index write --object-dir=$objdir &&\n \tmidx_read_expect 2 34 4 $objdir\n '\n \n@@ -192,17 +192,17 @@ test_expect_success 'write with no objects and preferred pack' '\n '\n \n test_expect_success 'write progress off for redirected stderr' '\n-\tgit multi-pack-index --object-dir=$objdir write 2>err &&\n+\tgit multi-pack-index write --object-dir=$objdir 2>err &&\n \ttest_line_count = 0 err\n '\n \n test_expect_success 'write force progress on for stderr' '\n-\tGIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir write --progress 2>err &&\n+\tGIT_PROGRESS_DELAY=0 git multi-pack-index write --object-dir=$objdir --progress 2>err &&\n \ttest_file_not_empty err\n '\n \n test_expect_success 'write with the --no-progress option' '\n-\tGIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir write --no-progress 2>err &&\n+\tGIT_PROGRESS_DELAY=0 git multi-pack-index write --object-dir=$objdir --no-progress 2>err &&\n \ttest_line_count = 0 err\n '\n \n@@ -218,7 +218,7 @@ test_expect_success 'add more packs' '\n compare_results_with_midx \"mixed mode (two packs + extra)\"\n \n test_expect_success 'write midx with twelve packs' '\n-\tgit multi-pack-index --object-dir=$objdir write &&\n+\tgit multi-pack-index write --object-dir=$objdir &&\n \tmidx_read_expect 12 74 4 $objdir\n '\n \n@@ -242,7 +242,7 @@ test_expect_success 'multi-pack-index *.rev cleanup with --object-dir' '\n \n \t(\n \t\tcd alternate &&\n-\t\tgit multi-pack-index --object-dir ../repo/.git/objects write\n+\t\tgit multi-pack-index write --object-dir ../repo/.git/objects\n \t) &&\n \n \t# writing a midx in \"repo\" should not remove the .rev file in the\n@@ -312,8 +312,8 @@ test_expect_success 'midx picks objects from preferred pack' '\n \t\tEOF\n \t\t) &&\n \n-\t\tgit multi-pack-index --object-dir=objects \\\n-\t\t\twrite --preferred-pack=test-BC-$bc.idx 2>err &&\n+\t\tgit multi-pack-index write --object-dir=objects \\\n+\t\t\t--preferred-pack=test-BC-$bc.idx 2>err &&\n \t\ttest_must_be_empty err &&\n \n \t\ttest-tool read-midx --show-objects objects >out &&\n@@ -611,17 +611,17 @@ test_expect_success 'verify packnames out of order (v1)' '\n '\n \n test_expect_success 'repack progress off for redirected stderr' '\n-\tGIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir repack 2>err &&\n+\tGIT_PROGRESS_DELAY=0 git multi-pack-index repack --object-dir=$objdir 2>err &&\n \ttest_line_count = 0 err\n '\n \n test_expect_success 'repack force progress on for stderr' '\n-\tGIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir repack --progress 2>err &&\n+\tGIT_PROGRESS_DELAY=0 git multi-pack-index repack --object-dir=$objdir --progress 2>err &&\n \ttest_file_not_empty err\n '\n \n test_expect_success 'repack with the --no-progress option' '\n-\tGIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir repack --no-progress 2>err &&\n+\tGIT_PROGRESS_DELAY=0 git multi-pack-index repack --object-dir=$objdir --no-progress 2>err &&\n \ttest_line_count = 0 err\n '\n \n@@ -730,7 +730,7 @@ test_expect_success 'force some 64-bit offsets with pack-objects' '\n \t(\n \t\tcd repo64 &&\n \t\t( cd ../objects64 && pwd ) >.git/objects/info/alternates &&\n-\t\tmidx64=$(git multi-pack-index --object-dir=../objects64 write)\n+\t\tmidx64=$(git multi-pack-index write --object-dir=../objects64)\n \t) &&\n \tmidx_read_expect 1 63 5 \"$(pwd)/objects64\" \" large-offsets\"\n '\n@@ -1296,7 +1296,7 @@ test_expect_success PERL_TEST_HELPERS 'reader bounds-checks large offset table'\n \t(\n \t\tcd repo &&\n \t\t(cd ../objects64 && pwd) >.git/objects/info/alternates &&\n-\t\tgit multi-pack-index --object-dir=../objects64 write &&\n+\t\tgit multi-pack-index write --object-dir=../objects64 &&\n \t\tmidx=../objects64/pack/multi-pack-index &&\n \t\tcorrupt_chunk_file $midx LOFF clear &&\n \t\t# using only %(objectsize) is important here; see the commit\n-- \n2.56.0\n\n\n"},{"id":"559829","messageId":"3bb2b9a69f1c6cd6c6690d961757acbec3c92aa6.1796147221.git.jltobler@gmail.com","threadId":"66963","inReplyTo":"cover.1796147221.git.jltobler@gmail.com","subject":"[PATCH v2 4/5] builtin/multi-pack-index: simplify how common options are wired up","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-12-01T18:16:15Z","receivedAt":"2026-12-01T18:16:15Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"All git-multi-pack-index(1) subcommands accept the \"--object-dir=\" and\n\"--progress\" options. To avoid duplicating these common options, a\nhelper function concatenates them with the options array of each\nsubcommand. This works, but requires a separate options array to be\nallocated and freed for every subcommand.\n\nDefine the common options via a preprocessor macro instead, which each\noptions array can include directly. This avoids the extra allocations\nand is less verbose overall.\n\nSigned-off-by: Justin Tobler <jltobler@gmail.com>\n---\n builtin/multi-pack-index.c | 57 ++++++++++----------------------------\n 1 file changed, 15 insertions(+), 42 deletions(-)\n\ndiff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c\nindex e84df0c947ce..7dfae23411bc 100644\n--- a/builtin/multi-pack-index.c\n+++ b/builtin/multi-pack-index.c\n@@ -87,18 +87,11 @@ static struct odb_source_packed *handle_object_dir_option(struct repository *rep\n \treturn dir->packed;\n }\n \n-static struct option common_opts[] = {\n-\tOPT_STRING(0, \"object-dir\", &opts.object_dir, N_(\"directory\"),\n-\t  N_(\"object directory containing set of packfile and pack-index pairs\")),\n-\tOPT_BIT(0, \"progress\", &opts.flags, N_(\"force progress reporting\"),\n-\t\tMIDX_PROGRESS),\n-\tOPT_END(),\n-};\n-\n-static struct option *add_common_options(struct option *prev)\n-{\n-\treturn parse_options_concat(common_opts, prev);\n-}\n+#define MULTI_PACK_INDEX_COMMON_OPTIONS(opts) \\\n+\tOPT_STRING(0, \"object-dir\", &(opts)->object_dir, N_(\"directory\"), \\\n+\t  N_(\"object directory containing set of packfile and pack-index pairs\")), \\\n+\tOPT_BIT(0, \"progress\", &(opts)->flags, N_(\"force progress reporting\"), \\\n+\t\tMIDX_PROGRESS)\n \n static int git_multi_pack_index_write_config(const char *var, const char *value,\n \t\t\t\t\t     const struct config_context *ctx UNUSED,\n@@ -139,8 +132,8 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,\n \t\t\t\t      const char *prefix,\n \t\t\t\t      struct repository *repo)\n {\n-\tstruct option *options;\n-\tstatic struct option builtin_multi_pack_index_write_options[] = {\n+\tstatic struct option options[] = {\n+\t\tMULTI_PACK_INDEX_COMMON_OPTIONS(&opts),\n \t\tOPT_STRING(0, \"preferred-pack\", &opts.preferred_pack,\n \t\t\t   N_(\"preferred-pack\"),\n \t\t\t   N_(\"pack for reuse when computing a multi-pack bitmap\")),\n@@ -166,8 +159,6 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,\n \n \trepo_config(repo, git_multi_pack_index_write_config, NULL);\n \n-\toptions = add_common_options(builtin_multi_pack_index_write_options);\n-\n \ttrace2_cmd_mode(argv[0]);\n \n \tif (isatty(2))\n@@ -196,8 +187,6 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,\n \n \tpacked_source = handle_object_dir_option(repo);\n \n-\tFREE_AND_NULL(options);\n-\n \tif (opts.stdin_packs) {\n \t\tstruct string_list packs = STRING_LIST_INIT_DUP;\n \n@@ -232,8 +221,8 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,\n \tstruct odb_source_packed *packed_source;\n \tint ret;\n \n-\tstruct option *options;\n-\tstatic struct option builtin_multi_pack_index_compact_options[] = {\n+\tstatic struct option options[] = {\n+\t\tMULTI_PACK_INDEX_COMMON_OPTIONS(&opts),\n \t\tOPT_STRING(0, \"base\", &opts.incremental_base, N_(\"checksum\"),\n \t\t\t   N_(\"base MIDX for incremental writes\")),\n \t\tOPT_BIT(0, \"bitmap\", &opts.flags, N_(\"write multi-pack bitmap\"),\n@@ -248,8 +237,6 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,\n \n \trepo_config(repo, git_multi_pack_index_write_config, NULL);\n \n-\toptions = add_common_options(builtin_multi_pack_index_compact_options);\n-\n \ttrace2_cmd_mode(argv[0]);\n \n \tif (isatty(2))\n@@ -272,8 +259,6 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,\n \n \tpacked_source = handle_object_dir_option(repo);\n \n-\tFREE_AND_NULL(options);\n-\n \tm = get_multi_pack_index(packed_source);\n \n \tfor (cur = m; cur && !(from_midx && to_midx); cur = cur->base_midx) {\n@@ -307,14 +292,12 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,\n \t\t\t\t       const char *prefix,\n \t\t\t\t       struct repository *repo)\n {\n-\tstruct option *options;\n-\tstatic struct option builtin_multi_pack_index_verify_options[] = {\n+\tstatic struct option options[] = {\n+\t\tMULTI_PACK_INDEX_COMMON_OPTIONS(&opts),\n \t\tOPT_END(),\n \t};\n \tstruct odb_source_packed *packed_source;\n \n-\toptions = add_common_options(builtin_multi_pack_index_verify_options);\n-\n \ttrace2_cmd_mode(argv[0]);\n \n \tif (isatty(2))\n@@ -327,8 +310,6 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,\n \t\t\t\t   options);\n \tpacked_source = handle_object_dir_option(repo);\n \n-\tFREE_AND_NULL(options);\n-\n \treturn verify_midx_file(packed_source, opts.flags);\n }\n \n@@ -336,14 +317,12 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv,\n \t\t\t\t       const char *prefix,\n \t\t\t\t       struct repository *repo)\n {\n-\tstruct option *options;\n-\tstatic struct option builtin_multi_pack_index_expire_options[] = {\n+\tstatic struct option options[] = {\n+\t\tMULTI_PACK_INDEX_COMMON_OPTIONS(&opts),\n \t\tOPT_END(),\n \t};\n \tstruct odb_source_packed *packed_source;\n \n-\toptions = add_common_options(builtin_multi_pack_index_expire_options);\n-\n \ttrace2_cmd_mode(argv[0]);\n \n \tif (isatty(2))\n@@ -356,8 +335,6 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv,\n \t\t\t\t   options);\n \tpacked_source = handle_object_dir_option(repo);\n \n-\tFREE_AND_NULL(options);\n-\n \treturn expire_midx_packs(packed_source, opts.flags);\n }\n \n@@ -365,16 +342,14 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,\n \t\t\t\t       const char *prefix,\n \t\t\t\t       struct repository *repo)\n {\n-\tstruct option *options;\n-\tstatic struct option builtin_multi_pack_index_repack_options[] = {\n+\tstatic struct option options[] = {\n+\t\tMULTI_PACK_INDEX_COMMON_OPTIONS(&opts),\n \t\tOPT_UNSIGNED(0, \"batch-size\", &opts.batch_size,\n \t\t  N_(\"during repack, collect pack-files of smaller size into a batch that is larger than this size\")),\n \t\tOPT_END(),\n \t};\n \tstruct odb_source_packed *packed_source;\n \n-\toptions = add_common_options(builtin_multi_pack_index_repack_options);\n-\n \ttrace2_cmd_mode(argv[0]);\n \n \tif (isatty(2))\n@@ -388,8 +363,6 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,\n \t\t\t\t   options);\n \tpacked_source = handle_object_dir_option(repo);\n \n-\tFREE_AND_NULL(options);\n-\n \treturn midx_repack(packed_source, (size_t)opts.batch_size, opts.flags);\n }\n \n-- \n2.56.0\n\n\n"},{"id":"559830","messageId":"46a59a5daf5200f840832cbf25430a9a6cbfedad.1796147221.git.jltobler@gmail.com","threadId":"66963","inReplyTo":"cover.1796147221.git.jltobler@gmail.com","subject":"[PATCH v2 5/5] builtin/multi-pack-index: de-globalize options handling","fromName":"Justin Tobler","fromEmail":"jltobler@gmail.com","sentAt":"2026-12-01T18:16:16Z","receivedAt":"2026-12-01T18:16:16Z","isPatch":true,"sender":{"key":"jltobler@gmail.com","avatar":"https://avatars.githubusercontent.com/u/53454972?v=4"},"body":"The options for git-multi-pack-index(1) are stored in a global variable\neven though each option is only needed by the subcommand that parses it.\nThe config callback for the \"write\" and \"compact\" subcommands also\naccesses the options, but they can just as well be passed to it via the\ncallback data.\n\nNow that `cmd_multi_pack_index()` no longer parses any of these options\nitself, nothing requires them to be global anymore. Refactor each\nsubcommand to track its options in a local variable and pass them to the\nconfig callback accordingly. With this change, no global state remains\nin \"builtin/multi-pack-index.c\".\n\nSigned-off-by: Justin Tobler <jltobler@gmail.com>\n---\n builtin/multi-pack-index.c | 54 ++++++++++++++++++++------------------\n 1 file changed, 29 insertions(+), 25 deletions(-)\n\ndiff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c\nindex 7dfae23411bc..ac99fec7d3c5 100644\n--- a/builtin/multi-pack-index.c\n+++ b/builtin/multi-pack-index.c\n@@ -62,7 +62,7 @@ static char const * const builtin_multi_pack_index_usage[] = {\n \tNULL\n };\n \n-static struct opts_multi_pack_index {\n+struct opts_multi_pack_index {\n \tconst char *object_dir;\n \tconst char *preferred_pack;\n \tconst char *incremental_base;\n@@ -70,11 +70,11 @@ static struct opts_multi_pack_index {\n \tunsigned long batch_size;\n \tunsigned flags;\n \tint stdin_packs;\n-} opts;\n+};\n \n-static struct odb_source_packed *handle_object_dir_option(struct repository *repo)\n+static struct odb_source_packed *handle_object_dir_option(struct repository *repo,\n+\t\t\t\t\t\t\t  const char *object_dir)\n {\n-\tconst char *object_dir = opts.object_dir;\n \tstruct odb_files_dir *dir;\n \n \tif (!object_dir)\n@@ -95,20 +95,22 @@ static struct odb_source_packed *handle_object_dir_option(struct repository *rep\n \n static int git_multi_pack_index_write_config(const char *var, const char *value,\n \t\t\t\t\t     const struct config_context *ctx UNUSED,\n-\t\t\t\t\t     void *cb UNUSED)\n+\t\t\t\t\t     void *cb_data)\n {\n+\tstruct opts_multi_pack_index *opts = cb_data;\n+\n \tif (!strcmp(var, \"pack.writebitmaphashcache\")) {\n \t\tif (git_config_bool(var, value))\n-\t\t\topts.flags |= MIDX_WRITE_BITMAP_HASH_CACHE;\n+\t\t\topts->flags |= MIDX_WRITE_BITMAP_HASH_CACHE;\n \t\telse\n-\t\t\topts.flags &= ~MIDX_WRITE_BITMAP_HASH_CACHE;\n+\t\t\topts->flags &= ~MIDX_WRITE_BITMAP_HASH_CACHE;\n \t}\n \n \tif (!strcmp(var, \"pack.writebitmaplookuptable\")) {\n \t\tif (git_config_bool(var, value))\n-\t\t\topts.flags |= MIDX_WRITE_BITMAP_LOOKUP_TABLE;\n+\t\t\topts->flags |= MIDX_WRITE_BITMAP_LOOKUP_TABLE;\n \t\telse\n-\t\t\topts.flags &= ~MIDX_WRITE_BITMAP_LOOKUP_TABLE;\n+\t\t\topts->flags &= ~MIDX_WRITE_BITMAP_LOOKUP_TABLE;\n \t}\n \n \t/*\n@@ -132,7 +134,8 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,\n \t\t\t\t      const char *prefix,\n \t\t\t\t      struct repository *repo)\n {\n-\tstatic struct option options[] = {\n+\tstruct opts_multi_pack_index opts = { 0 };\n+\tstruct option options[] = {\n \t\tMULTI_PACK_INDEX_COMMON_OPTIONS(&opts),\n \t\tOPT_STRING(0, \"preferred-pack\", &opts.preferred_pack,\n \t\t\t   N_(\"preferred-pack\"),\n@@ -157,7 +160,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,\n \n \topts.flags |= MIDX_WRITE_BITMAP_HASH_CACHE;\n \n-\trepo_config(repo, git_multi_pack_index_write_config, NULL);\n+\trepo_config(repo, git_multi_pack_index_write_config, &opts);\n \n \ttrace2_cmd_mode(argv[0]);\n \n@@ -185,7 +188,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,\n \t\t\t\t   options);\n \t}\n \n-\tpacked_source = handle_object_dir_option(repo);\n+\tpacked_source = handle_object_dir_option(repo, opts.object_dir);\n \n \tif (opts.stdin_packs) {\n \t\tstruct string_list packs = STRING_LIST_INIT_DUP;\n@@ -215,13 +218,14 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,\n \t\t\t\t\tconst char *prefix,\n \t\t\t\t\tstruct repository *repo)\n {\n+\tstruct opts_multi_pack_index opts = { 0 };\n \tstruct multi_pack_index *m, *cur;\n \tstruct multi_pack_index *from_midx = NULL;\n \tstruct multi_pack_index *to_midx = NULL;\n \tstruct odb_source_packed *packed_source;\n \tint ret;\n \n-\tstatic struct option options[] = {\n+\tstruct option options[] = {\n \t\tMULTI_PACK_INDEX_COMMON_OPTIONS(&opts),\n \t\tOPT_STRING(0, \"base\", &opts.incremental_base, N_(\"checksum\"),\n \t\t\t   N_(\"base MIDX for incremental writes\")),\n@@ -235,7 +239,7 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,\n \t\tOPT_END(),\n \t};\n \n-\trepo_config(repo, git_multi_pack_index_write_config, NULL);\n+\trepo_config(repo, git_multi_pack_index_write_config, &opts);\n \n \ttrace2_cmd_mode(argv[0]);\n \n@@ -257,7 +261,7 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,\n \t\t\t\t   options);\n \t}\n \n-\tpacked_source = handle_object_dir_option(repo);\n+\tpacked_source = handle_object_dir_option(repo, opts.object_dir);\n \n \tm = get_multi_pack_index(packed_source);\n \n@@ -292,7 +296,8 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,\n \t\t\t\t       const char *prefix,\n \t\t\t\t       struct repository *repo)\n {\n-\tstatic struct option options[] = {\n+\tstruct opts_multi_pack_index opts = { 0 };\n+\tstruct option options[] = {\n \t\tMULTI_PACK_INDEX_COMMON_OPTIONS(&opts),\n \t\tOPT_END(),\n \t};\n@@ -308,7 +313,7 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,\n \tif (argc)\n \t\tusage_with_options(builtin_multi_pack_index_verify_usage,\n \t\t\t\t   options);\n-\tpacked_source = handle_object_dir_option(repo);\n+\tpacked_source = handle_object_dir_option(repo, opts.object_dir);\n \n \treturn verify_midx_file(packed_source, opts.flags);\n }\n@@ -317,7 +322,8 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv,\n \t\t\t\t       const char *prefix,\n \t\t\t\t       struct repository *repo)\n {\n-\tstatic struct option options[] = {\n+\tstruct opts_multi_pack_index opts = { 0 };\n+\tstruct option options[] = {\n \t\tMULTI_PACK_INDEX_COMMON_OPTIONS(&opts),\n \t\tOPT_END(),\n \t};\n@@ -333,7 +339,7 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv,\n \tif (argc)\n \t\tusage_with_options(builtin_multi_pack_index_expire_usage,\n \t\t\t\t   options);\n-\tpacked_source = handle_object_dir_option(repo);\n+\tpacked_source = handle_object_dir_option(repo, opts.object_dir);\n \n \treturn expire_midx_packs(packed_source, opts.flags);\n }\n@@ -342,7 +348,8 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,\n \t\t\t\t       const char *prefix,\n \t\t\t\t       struct repository *repo)\n {\n-\tstatic struct option options[] = {\n+\tstruct opts_multi_pack_index opts = { 0 };\n+\tstruct option options[] = {\n \t\tMULTI_PACK_INDEX_COMMON_OPTIONS(&opts),\n \t\tOPT_UNSIGNED(0, \"batch-size\", &opts.batch_size,\n \t\t  N_(\"during repack, collect pack-files of smaller size into a batch that is larger than this size\")),\n@@ -361,7 +368,7 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,\n \tif (argc)\n \t\tusage_with_options(builtin_multi_pack_index_repack_usage,\n \t\t\t\t   options);\n-\tpacked_source = handle_object_dir_option(repo);\n+\tpacked_source = handle_object_dir_option(repo, opts.object_dir);\n \n \treturn midx_repack(packed_source, (size_t)opts.batch_size, opts.flags);\n }\n@@ -371,7 +378,6 @@ int cmd_multi_pack_index(int argc,\n \t\t\t const char *prefix,\n \t\t\t struct repository *repo)\n {\n-\tint res;\n \tparse_opt_subcommand_fn *fn = NULL;\n \tstruct option options[] = {\n \t\tOPT_SUBCOMMAND(\"repack\", &fn, cmd_multi_pack_index_repack),\n@@ -389,7 +395,5 @@ int cmd_multi_pack_index(int argc,\n \targc = parse_options(argc, argv, prefix, options,\n \t\t\t     builtin_multi_pack_index_usage, 0);\n \n-\tres = fn(argc, argv, prefix, repo);\n-\n-\treturn res;\n+\treturn fn(argc, argv, prefix, repo);\n }\n-- \n2.56.0\n\n\n"},{"id":"559894","messageId":"axBBdpVPeqy6YVmj@pks.im","threadId":"66963","inReplyTo":"3e6369b99ba39b135fc1b315dc0721d098968e13.1796147221.git.jltobler@gmail.com","subject":"Re: [PATCH v2 1/5] builtin/multi-pack-index: resolve default object directory lazily","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-12-02T16:04:06Z","receivedAt":"2026-12-02T16:04:06Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Tue, Dec 01, 2026 at 12:16:12PM -0600, Justin Tobler wrote:\n> diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c\n> index c48212290cf8..ba5f326dd6ef 100644\n> --- a/builtin/multi-pack-index.c\n> +++ b/builtin/multi-pack-index.c\n> @@ -73,33 +72,24 @@ static struct opts_multi_pack_index {\n>  \tint stdin_packs;\n>  } opts;\n>  \n> -\n> -static int parse_object_dir(const struct option *opt, const char *arg,\n> -\t\t\t    int unset)\n> -{\n> -\tchar **value = opt->value;\n> -\tfree(*value);\n> -\tif (unset)\n> -\t\t*value = xstrdup(the_repository->objects->source->path);\n> -\telse\n> -\t\t*value = real_pathdup(arg, 1);\n> -\treturn 0;\n> -}\n> -\n>  static struct odb_source_packed *handle_object_dir_option(struct repository *repo)\n>  {\n> -\tstruct odb_files_dir *dir = odb_source_files_find_dir(repo->objects, opts.object_dir);\n> +\tconst char *object_dir = opts.object_dir;\n> +\tstruct odb_files_dir *dir;\n> +\n> +\tif (!object_dir)\n> +\t\tobject_dir = repo->objects->source->path;\n> +\n> +\tdir = odb_source_files_find_dir(repo->objects, object_dir);\n>  \tif (!dir)\n>  \t\tdie(_(\"object directory is not an alternate of the current repository: '%s'\"),\n> -\t\t    opts.object_dir);\n> +\t\t    object_dir);\n>  \treturn dir->packed;\n>  }\n>  \n>  static struct option common_opts[] = {\n> -\tOPT_CALLBACK(0, \"object-dir\", &opts.object_dir,\n> -\t  N_(\"directory\"),\n> -\t  N_(\"object directory containing set of packfile and pack-index pairs\"),\n> -\t  parse_object_dir),\n> +\tOPT_STRING(0, \"object-dir\", &opts.object_dir, N_(\"directory\"),\n> +\t  N_(\"object directory containing set of packfile and pack-index pairs\")),\n>  \tOPT_BIT(0, \"progress\", &opts.flags, N_(\"force progress reporting\"),\n>  \t\tMIDX_PROGRESS),\n>  \tOPT_END(),\n\nNice simplification overall.\n\nPatrick\n\n"},{"id":"559895","messageId":"axBBfsRueKV8T-rW@pks.im","threadId":"66963","inReplyTo":"46a59a5daf5200f840832cbf25430a9a6cbfedad.1796147221.git.jltobler@gmail.com","subject":"Re: [PATCH v2 5/5] builtin/multi-pack-index: de-globalize options handling","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-12-02T16:04:14Z","receivedAt":"2026-12-02T16:04:14Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Tue, Dec 01, 2026 at 12:16:16PM -0600, Justin Tobler wrote:\n> diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c\n> index 7dfae23411bc..ac99fec7d3c5 100644\n> --- a/builtin/multi-pack-index.c\n> +++ b/builtin/multi-pack-index.c\n> @@ -62,7 +62,7 @@ static char const * const builtin_multi_pack_index_usage[] = {\n>  \tNULL\n>  };\n>  \n> -static struct opts_multi_pack_index {\n> +struct opts_multi_pack_index {\n>  \tconst char *object_dir;\n>  \tconst char *preferred_pack;\n>  \tconst char *incremental_base;\n> @@ -70,11 +70,11 @@ static struct opts_multi_pack_index {\n>  \tunsigned long batch_size;\n>  \tunsigned flags;\n>  \tint stdin_packs;\n> -} opts;\n> +};\n\nNice, this patch looks simpler, as well, as we don't have to free\n`object_dir` anymore.\n\nPatrick\n\n"},{"id":"559896","messageId":"axBBhZVBmKH4N_uI@pks.im","threadId":"66963","inReplyTo":"cover.1796147221.git.jltobler@gmail.com","subject":"Re: [PATCH v2 0/5] builtin/multi-pack-index: remove global state","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-12-02T16:04:21Z","receivedAt":"2026-12-02T16:04:21Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Tue, Dec 01, 2026 at 12:16:11PM -0600, Justin Tobler wrote:\n> Changes since V1:\n>   - \"--object-dir=\" is now parsed via `OPT_STRING()`, so the option\n>     value no longer needs to be allocated or freed.\n>   - Clarified in the message of patch 2 that the repository may still be\n>     `NULL` until `parse_options()` has been called.\n>   - The synopsis and usage strings now explicitly list the common\n>     options instead of using the `[<options>]` placeholder.\n>   - The common options are now added at the front of each options array,\n>     so the order of the \"-h\" output stays the same.\n\nThe range-diff is rather verbose, but all of the changes look sensible\nto me. I'm a bit indifferent whether the more verbose synopsis with the\ncommon options repeated is actually better, but I don't think we have an\nestablished way of spelling common options out. So that's nothing that\nreally makes me pause for too long.\n\nThanks!\n\nPatrick\n\n"}]}