When invoking git-multi-pack-index(1), the "--object-dir=" and "--[no-]progress" options can be given either before or after the subcommand. This calling convention is atypical for Git commands, and it requires the options parsed by `cmd_multi_pack_index()` to be stored in global state so that they can be accessed by the subcommands. Neither option needs to be accepted before the subcommand though. The "--[no-]progress" option was already removed from the top-level builtin in 0394f8d002 (builtin/multi-pack-index.c: disable top-level --[no-]progress, 2021-09-20). When given before the subcommand, the option is not always respected, as each subcommand overrides it depending on whether stderr is connected to a terminal. Furthermore, a subcommand without a notion of progress would have to ignore the option altogether. The option was inadvertently reintroduced by 6b8fb17490 (builtin/multi-pack-index.c: make '--progress' a common option, 2026-02-24), which moved it into the common options that are also parsed by `cmd_multi_pack_index()`. Consequently, "git multi-pack-index --no-progress write" still shows progress when stderr is connected to a terminal. Unlike "--[no-]progress", the "--object-dir=" option was kept at the top level when 60ca94769c (builtin/multi-pack-index.c: split sub-commands, 2021-03-30) taught each subcommand to parse its own options. Giving the option after the subcommand is the preferred form, so also accepting it at the top level is no longer necessary. Drop both options from the top-level builtin so that they are only accepted by the subcommands. This brings the command in line with how Git typically handles options and avoids the need for global state to pass the options down to the subcommands. Update the synopsis, the usage strings and the example in the documentation accordingly. Signed-off-by: Justin Tobler <jlto…@gmail.com> --- Documentation/git-multi-pack-index.adoc | 23 +++++++++--------- builtin/multi-pack-index.c | 25 ++++++++++--------- t/lib-midx.sh | 2 +- t/t5319-multi-pack-index.sh | 32 ++++++++++++------------- 4 files changed, 41 insertions(+), 41 deletions(-) diff --git a/Documentation/git-multi-pack-index.adoc b/Documentation/git-multi-pack-index.adoc index c6d23aeeb9a0..65e09a3012d1 100644 --- a/Documentation/git-multi-pack-index.adoc +++ b/Documentation/git-multi-pack-index.adoc @@ -9,16 +9,17 @@ git-multi-pack-index - Write and verify multi-pack-indexes SYNOPSIS -------- [verse] -'git multi-pack-index' [<options>] write [--preferred-pack=<pack>] - [--[no-]bitmap] [--[no-]incremental] [--[no-]stdin-packs] - [--refs-snapshot=<path>] [--[no-]write-chain-file] - [--base=<checksum>] -'git multi-pack-index' [<options>] compact [--[no-]incremental] - [--[no-]bitmap] [--base=<checksum>] [--[no-]write-chain-file] - <from> <to> -'git multi-pack-index' [<options>] verify -'git multi-pack-index' [<options>] expire -'git multi-pack-index' [<options>] repack [--batch-size=<size>] +'git multi-pack-index' write [--object-dir=<dir>] [--[no-]progress] + [--preferred-pack=<pack>] [--[no-]bitmap] [--[no-]incremental] + [--[no-]stdin-packs] [--refs-snapshot=<path>] + [--[no-]write-chain-file] [--base=<checksum>] +'git multi-pack-index' compact [--object-dir=<dir>] [--[no-]progress] + [--[no-]incremental] [--[no-]bitmap] [--base=<checksum>] + [--[no-]write-chain-file] <from> <to> +'git multi-pack-index' verify [--object-dir=<dir>] [--[no-]progress] +'git multi-pack-index' expire [--object-dir=<dir>] [--[no-]progress] +'git multi-pack-index' repack [--object-dir=<dir>] [--[no-]progress] + [--batch-size=<size>] DESCRIPTION ----------- @@ -183,7 +184,7 @@ $ git multi-pack-index write --preferred-pack=<pack> --bitmap * Write a MIDX file for the packfiles in an alternate object store. + ----------------------------------------------- -$ git multi-pack-index --object-dir <alt> write +$ git multi-pack-index write --object-dir <alt> ----------------------------------------------- * Verify the MIDX file for the packfiles in the current `.git` directory. diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c index c1ad8ebbcc15..e84df0c947ce 100644 --- a/builtin/multi-pack-index.c +++ b/builtin/multi-pack-index.c @@ -13,24 +13,25 @@ #include "repository.h" #define BUILTIN_MIDX_WRITE_USAGE \ - N_("git multi-pack-index [<options>] write [--preferred-pack=<pack>]\n" \ - " [--[no-]bitmap] [--[no-]incremental] [--[no-]stdin-packs]\n" \ - " [--refs-snapshot=<path>] [--[no-]write-chain-file]\n" \ - " [--base=<checksum>]") + N_("git multi-pack-index write [--object-dir=<dir>] [--[no-]progress]\n" \ + " [--preferred-pack=<pack>] [--[no-]bitmap] [--[no-]incremental]\n" \ + " [--[no-]stdin-packs] [--refs-snapshot=<path>]\n" \ + " [--[no-]write-chain-file] [--base=<checksum>]") #define BUILTIN_MIDX_COMPACT_USAGE \ - N_("git multi-pack-index [<options>] compact [--[no-]incremental]\n" \ - " [--[no-]bitmap] [--base=<checksum>] [--[no-]write-chain-file]\n" \ - " <from> <to>") + N_("git multi-pack-index compact [--object-dir=<dir>] [--[no-]progress]\n" \ + " [--[no-]incremental] [--[no-]bitmap] [--base=<checksum>]\n" \ + " [--[no-]write-chain-file] <from> <to>") #define BUILTIN_MIDX_VERIFY_USAGE \ - N_("git multi-pack-index [<options>] verify") + N_("git multi-pack-index verify [--object-dir=<dir>] [--[no-]progress]") #define BUILTIN_MIDX_EXPIRE_USAGE \ - N_("git multi-pack-index [<options>] expire") + N_("git multi-pack-index expire [--object-dir=<dir>] [--[no-]progress]") #define BUILTIN_MIDX_REPACK_USAGE \ - N_("git multi-pack-index [<options>] repack [--batch-size=<size>]") + N_("git multi-pack-index repack [--object-dir=<dir>] [--[no-]progress]\n" \ + " [--batch-size=<size>]") static char const * const builtin_multi_pack_index_write_usage[] = { BUILTIN_MIDX_WRITE_USAGE, @@ -399,7 +400,7 @@ int cmd_multi_pack_index(int argc, { int res; parse_opt_subcommand_fn *fn = NULL; - struct option builtin_multi_pack_index_options[] = { + struct option options[] = { OPT_SUBCOMMAND("repack", &fn, cmd_multi_pack_index_repack), OPT_SUBCOMMAND("write", &fn, cmd_multi_pack_index_write), OPT_SUBCOMMAND("compact", &fn, cmd_multi_pack_index_compact), @@ -407,7 +408,6 @@ int cmd_multi_pack_index(int argc, OPT_SUBCOMMAND("expire", &fn, cmd_multi_pack_index_expire), OPT_END(), }; - struct option *options = parse_options_concat(builtin_multi_pack_index_options, common_opts); disable_replace_refs(); @@ -415,7 +415,6 @@ int cmd_multi_pack_index(int argc, argc = parse_options(argc, argv, prefix, options, builtin_multi_pack_index_usage, 0); - FREE_AND_NULL(options); res = fn(argc, argv, prefix, repo); diff --git a/t/lib-midx.sh b/t/lib-midx.sh index e38c609604c3..d7dc09b382ec 100644 --- a/t/lib-midx.sh +++ b/t/lib-midx.sh @@ -4,7 +4,7 @@ test_midx_consistent () { test-tool read-midx $1 | grep ^pack-.*\.idx$ | sort >actual && test_cmp expect actual && - git multi-pack-index --object-dir=$1 verify + git multi-pack-index verify --object-dir=$1 } midx_checksum () { diff --git a/t/t5319-multi-pack-index.sh b/t/t5319-multi-pack-index.sh index e1684e3e69d7..b366add863d1 100755 --- a/t/t5319-multi-pack-index.sh +++ b/t/t5319-multi-pack-index.sh @@ -50,7 +50,7 @@ test_expect_success 'setup' ' ' test_expect_success "don't write midx with no packs" ' - test_must_fail git multi-pack-index --object-dir=. write && + test_must_fail git multi-pack-index write --object-dir=. && test_path_is_missing pack/multi-pack-index ' @@ -122,13 +122,13 @@ test_expect_success 'write midx with one v1 pack' ' pack=$(git pack-objects --index-version=1 $objdir/pack/test <obj-list) && test_when_finished rm $objdir/pack/test-$pack.pack \ $objdir/pack/test-$pack.idx $objdir/pack/multi-pack-index && - git multi-pack-index --object-dir=$objdir write && + git multi-pack-index write --object-dir=$objdir && midx_read_expect 1 18 4 $objdir ' test_expect_success 'write midx with one v2 pack' ' git pack-objects --index-version=2,0x40 $objdir/pack/test <obj-list && - git multi-pack-index --object-dir=$objdir write && + git multi-pack-index write --object-dir=$objdir && midx_read_expect 1 18 4 $objdir ' @@ -158,7 +158,7 @@ test_expect_success 'add more objects' ' test_expect_success 'write midx with two packs' ' git pack-objects --index-version=1 $objdir/pack/test-2 <obj-list && - git multi-pack-index --object-dir=$objdir write && + git multi-pack-index write --object-dir=$objdir && midx_read_expect 2 34 4 $objdir ' @@ -192,17 +192,17 @@ test_expect_success 'write with no objects and preferred pack' ' ' test_expect_success 'write progress off for redirected stderr' ' - git multi-pack-index --object-dir=$objdir write 2>err && + git multi-pack-index write --object-dir=$objdir 2>err && test_line_count = 0 err ' test_expect_success 'write force progress on for stderr' ' - GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir write --progress 2>err && + GIT_PROGRESS_DELAY=0 git multi-pack-index write --object-dir=$objdir --progress 2>err && test_file_not_empty err ' test_expect_success 'write with the --no-progress option' ' - GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir write --no-progress 2>err && + GIT_PROGRESS_DELAY=0 git multi-pack-index write --object-dir=$objdir --no-progress 2>err && test_line_count = 0 err ' @@ -218,7 +218,7 @@ test_expect_success 'add more packs' ' compare_results_with_midx "mixed mode (two packs + extra)" test_expect_success 'write midx with twelve packs' ' - git multi-pack-index --object-dir=$objdir write && + git multi-pack-index write --object-dir=$objdir && midx_read_expect 12 74 4 $objdir ' @@ -242,7 +242,7 @@ test_expect_success 'multi-pack-index *.rev cleanup with --object-dir' ' ( cd alternate && - git multi-pack-index --object-dir ../repo/.git/objects write + git multi-pack-index write --object-dir ../repo/.git/objects ) && # writing a midx in "repo" should not remove the .rev file in the @@ -312,8 +312,8 @@ test_expect_success 'midx picks objects from preferred pack' ' EOF ) && - git multi-pack-index --object-dir=objects \ - write --preferred-pack=test-BC-$bc.idx 2>err && + git multi-pack-index write --object-dir=objects \ + --preferred-pack=test-BC-$bc.idx 2>err && test_must_be_empty err && test-tool read-midx --show-objects objects >out && @@ -611,17 +611,17 @@ test_expect_success 'verify packnames out of order (v1)' ' ' test_expect_success 'repack progress off for redirected stderr' ' - GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir repack 2>err && + GIT_PROGRESS_DELAY=0 git multi-pack-index repack --object-dir=$objdir 2>err && test_line_count = 0 err ' test_expect_success 'repack force progress on for stderr' ' - GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir repack --progress 2>err && + GIT_PROGRESS_DELAY=0 git multi-pack-index repack --object-dir=$objdir --progress 2>err && test_file_not_empty err ' test_expect_success 'repack with the --no-progress option' ' - GIT_PROGRESS_DELAY=0 git multi-pack-index --object-dir=$objdir repack --no-progress 2>err && + GIT_PROGRESS_DELAY=0 git multi-pack-index repack --object-dir=$objdir --no-progress 2>err && test_line_count = 0 err ' @@ -730,7 +730,7 @@ test_expect_success 'force some 64-bit offsets with pack-objects' ' ( cd repo64 && ( cd ../objects64 && pwd ) >.git/objects/info/alternates && - midx64=$(git multi-pack-index --object-dir=../objects64 write) + midx64=$(git multi-pack-index write --object-dir=../objects64) ) && midx_read_expect 1 63 5 "$(pwd)/objects64" " large-offsets" ' @@ -1296,7 +1296,7 @@ test_expect_success PERL_TEST_HELPERS 'reader bounds-checks large offset table' ( cd repo && (cd ../objects64 && pwd) >.git/objects/info/alternates && - git multi-pack-index --object-dir=../objects64 write && + git multi-pack-index write --object-dir=../objects64 && midx=../objects64/pack/multi-pack-index && corrupt_chunk_file $midx LOFF clear && # using only %(objectsize) is important here; see the commit
-- 2.56.0