Thread View: linux.kernel.git
16 messages
16 total messages
Started by Justin Tobler
Mon, 30 Nov 2026 21:54
[PATCH 0/5] builtin/multi-pack-index: remove global state
Author: Justin Tobler
Date: Mon, 30 Nov 2026 21:54
Date: Mon, 30 Nov 2026 21:54
53 lines
12313 bytes
12313 bytes
Greetings, This series cleans up git-multi-pack-index(1) by getting rid of `the_repository` and the global state used to track its options. Each subcommand now parses its options into a local structure, and the common options are wired up via a macro instead of allocating a combined options array for every subcommand. The main reason the options are global is that "--object-dir=" and "--[no-]progress" are also accepted before the subcommand, where the top-level builtin parses them into the same global state used by the subcommands. Patch 3 drops support for giving these options before the subcommand, as every subcommand already accepts both of them. The "--[no-]progress" option was previously removed as a top-level option in 0394f8d002 (builtin/multi-pack-index.c: disable top-level --[no-]progress, 2021-09-20) and appears to have been inadvertently reintroduced via 6b8fb17490 (builtin/multi-pack-index.c: make '--progress' a common option, 2026-02-24). So I think it should be fine to drop. While "--object-dir=" has never previously been dropped, it appears to exist as a top-level option for the same historical reason, from when all options were parsed by the top-level builtin. Since the subcommands already parse the common options themselves, it should ideally be dropped as well. If we want to keep this top-level option though, an alternative could be to propagate the option argument to each subcommand. In this case, I don't think it's worth it, but happy to change if others feel differently. This series is built on top of 86e79b2795 (The 26th batch, 2026-11-29). Thanks, -Justin Justin Tobler (5): builtin/multi-pack-index: resolve default object directory lazily builtin/multi-pack-index: get rid of `the_repository` builtin/multi-pack-index: drop top-level options builtin/multi-pack-index: simplify how common options are wired up builtin/multi-pack-index: de-globalize options handling Documentation/git-multi-pack-index.adoc | 12 +- builtin/multi-pack-index.c | 160 +++++++++++------------- t/lib-midx.sh | 2 +- t/t5319-multi-pack-index.sh | 32 ++--- 4 files changed, 97 insertions(+), 109 deletions(-) base-commit: 86e79b2795e3ce3b0ad7685edd368574b0c8b9f2 -- 2.56.0
[PATCH 1/5] builtin/multi-pack-index: resolve default object directory lazily
Author: Justin Tobler
Date: Mon, 30 Nov 2026 21:54
Date: Mon, 30 Nov 2026 21:54
66 lines
13060 bytes
13060 bytes
The object directory used by git-multi-pack-index(1) defaults to the
path of the primary object database source. This default is set eagerly
in `cmd_multi_pack_index()` before any options are parsed, and again
when "--no-object-dir" is given. Both cases access `the_repository` to
do so, and the eager initialization additionally has to guard against
the repository not being set up.
In a subsequent commit, the remaining references to `the_repository` in
"builtin/multi-pack-index.c" are removed. In preparation for this
change, leave the object directory unset in both cases and lazily fall
back to the path of the primary source in `handle_object_dir_option()`,
where the repository is passed in explicitly. This also removes the
need for the defensive `NULL` checks guarding the eager initialization.
Signed-off-by: Justin Tobler <jltobler@gmail.com>
---
builtin/multi-pack-index.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index c48212290cf8..1a27d523c7ab 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -80,7 +80,7 @@ static int parse_object_dir(const struct option *opt, const char *arg,
char **value = opt->value;
free(*value);
if (unset)
- *value = xstrdup(the_repository->objects->source->path);
+ *value = NULL;
else
*value = real_pathdup(arg, 1);
return 0;
@@ -88,10 +88,16 @@ static int parse_object_dir(const struct option *opt, const char *arg,
static struct odb_source_packed *handle_object_dir_option(struct repository *repo)
{
- struct odb_files_dir *dir = odb_source_files_find_dir(repo->objects, opts.object_dir);
+ const char *object_dir = opts.object_dir;
+ struct odb_files_dir *dir;
+
+ if (!object_dir)
+ object_dir = repo->objects->source->path;
+
+ dir = odb_source_files_find_dir(repo->objects, object_dir);
if (!dir)
die(_("object directory is not an alternate of the current repository: '%s'"),
- opts.object_dir);
+ object_dir);
return dir->packed;
}
@@ -424,11 +430,6 @@ int cmd_multi_pack_index(int argc,
repo_config(the_repository, git_default_config, NULL);
- if (the_repository &&
- the_repository->objects &&
- the_repository->objects->source)
- opts.object_dir = xstrdup(the_repository->objects->source->path);
-
argc = parse_options(argc, argv, prefix, options,
builtin_multi_pack_index_usage, 0);
FREE_AND_NULL(options);
--
2.56.0
[PATCH 2/5] builtin/multi-pack-index: get rid of `the_repository`
Author: Justin Tobler
Date: Mon, 30 Nov 2026 21:54
Date: Mon, 30 Nov 2026 21:54
103 lines
14291 bytes
14291 bytes
There are a couple of remaining references to `the_repository` in
git-multi-pack-index(1). The command cannot run outside of a repository,
so these references can be trivially replaced with the repository
passed to the subcommands.
Signed-off-by: Justin Tobler <jltobler@gmail.com>
---
builtin/multi-pack-index.c | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index 1a27d523c7ab..8528f4f513ef 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -1,4 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
#include "builtin.h"
#include "abspath.h"
#include "config.h"
@@ -180,7 +179,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
opts.flags |= MIDX_WRITE_BITMAP_HASH_CACHE;
- repo_config(the_repository, git_multi_pack_index_write_config, NULL);
+ repo_config(repo, git_multi_pack_index_write_config, NULL);
options = add_common_options(builtin_multi_pack_index_write_options);
@@ -286,7 +285,7 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,
options);
}
- packed_source = handle_object_dir_option(the_repository);
+ packed_source = handle_object_dir_option(repo);
FREE_AND_NULL(options);
@@ -321,7 +320,7 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,
static int cmd_multi_pack_index_verify(int argc, const char **argv,
const char *prefix,
- struct repository *repo UNUSED)
+ struct repository *repo)
{
struct option *options;
static struct option builtin_multi_pack_index_verify_options[] = {
@@ -341,7 +340,7 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,
if (argc)
usage_with_options(builtin_multi_pack_index_verify_usage,
options);
- packed_source = handle_object_dir_option(the_repository);
+ packed_source = handle_object_dir_option(repo);
FREE_AND_NULL(options);
@@ -350,7 +349,7 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,
static int cmd_multi_pack_index_expire(int argc, const char **argv,
const char *prefix,
- struct repository *repo UNUSED)
+ struct repository *repo)
{
struct option *options;
static struct option builtin_multi_pack_index_expire_options[] = {
@@ -370,7 +369,7 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv,
if (argc)
usage_with_options(builtin_multi_pack_index_expire_usage,
options);
- packed_source = handle_object_dir_option(the_repository);
+ packed_source = handle_object_dir_option(repo);
FREE_AND_NULL(options);
@@ -379,7 +378,7 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv,
static int cmd_multi_pack_index_repack(int argc, const char **argv,
const char *prefix,
- struct repository *repo UNUSED)
+ struct repository *repo)
{
struct option *options;
static struct option builtin_multi_pack_index_repack_options[] = {
@@ -402,7 +401,7 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,
if (argc)
usage_with_options(builtin_multi_pack_index_repack_usage,
options);
- packed_source = handle_object_dir_option(the_repository);
+ packed_source = handle_object_dir_option(repo);
FREE_AND_NULL(options);
@@ -428,7 +427,7 @@ int cmd_multi_pack_index(int argc,
disable_replace_refs();
- repo_config(the_repository, git_default_config, NULL);
+ repo_config(repo, git_default_config, NULL);
argc = parse_options(argc, argv, prefix, options,
builtin_multi_pack_index_usage, 0);
--
2.56.0
[PATCH 3/5] builtin/multi-pack-index: drop top-level options
Author: Justin Tobler
Date: Mon, 30 Nov 2026 21:54
Date: Mon, 30 Nov 2026 21:54
277 lines
22295 bytes
22295 bytes
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 <jltobler@gmail.com>
---
Documentation/git-multi-pack-index.adoc | 12 +++++-----
builtin/multi-pack-index.c | 14 +++++------
t/lib-midx.sh | 2 +-
t/t5319-multi-pack-index.sh | 32 ++++++++++++-------------
4 files changed, 29 insertions(+), 31 deletions(-)
diff --git a/Documentation/git-multi-pack-index.adoc b/Documentation/git-multi-pack-index.adoc
index c6d23aeeb9a0..0dd675f3fd46 100644
--- a/Documentation/git-multi-pack-index.adoc
+++ b/Documentation/git-multi-pack-index.adoc
@@ -9,16 +9,16 @@ git-multi-pack-index - Write and verify multi-pack-indexes
SYNOPSIS
--------
[verse]
-'git multi-pack-index' [<options>] write [--preferred-pack=<pack>]
+'git multi-pack-index' write [<options>] [--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]
+'git multi-pack-index' compact [<options>] [--[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' verify [<options>]
+'git multi-pack-index' expire [<options>]
+'git multi-pack-index' repack [<options>] [--batch-size=<size>]
DESCRIPTION
-----------
@@ -183,7 +183,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 8528f4f513ef..2b4e2f0cce9e 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -14,24 +14,24 @@
#include "repository.h"
#define BUILTIN_MIDX_WRITE_USAGE \
- N_("git multi-pack-index [<options>] write [--preferred-pack=<pack>]\n" \
+ N_("git multi-pack-index write [<options>] [--preferred-pack=<pack>]\n" \
" [--[no-]bitmap] [--[no-]incremental] [--[no-]stdin-packs]\n" \
" [--refs-snapshot=<path>] [--[no-]write-chain-file]\n" \
" [--base=<checksum>]")
#define BUILTIN_MIDX_COMPACT_USAGE \
- N_("git multi-pack-index [<options>] compact [--[no-]incremental]\n" \
+ N_("git multi-pack-index compact [<options>] [--[no-]incremental]\n" \
" [--[no-]bitmap] [--base=<checksum>] [--[no-]write-chain-file]\n" \
" <from> <to>")
#define BUILTIN_MIDX_VERIFY_USAGE \
- N_("git multi-pack-index [<options>] verify")
+ N_("git multi-pack-index verify [<options>]")
#define BUILTIN_MIDX_EXPIRE_USAGE \
- N_("git multi-pack-index [<options>] expire")
+ N_("git multi-pack-index expire [<options>]")
#define BUILTIN_MIDX_REPACK_USAGE \
- N_("git multi-pack-index [<options>] repack [--batch-size=<size>]")
+ N_("git multi-pack-index repack [<options>] [--batch-size=<size>]")
static char const * const builtin_multi_pack_index_write_usage[] = {
BUILTIN_MIDX_WRITE_USAGE,
@@ -415,7 +415,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),
@@ -423,7 +423,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();
@@ -431,7 +430,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
[PATCH 4/5] builtin/multi-pack-index: simplify how common options are wired up
Author: Justin Tobler
Date: Mon, 30 Nov 2026 21:55
Date: Mon, 30 Nov 2026 21:55
200 lines
17593 bytes
17593 bytes
All git-multi-pack-index(1) subcommands accept the "--object-dir=" and
"--progress" options. To avoid duplicating these common options, a
helper function concatenates them with the options array of each
subcommand. This works, but requires a separate options array to be
allocated and freed for every subcommand.
Define the common options via a preprocessor macro instead, which each
options array can include directly. This avoids the extra allocations
and is less verbose overall.
Signed-off-by: Justin Tobler <jltobler@gmail.com>
---
builtin/multi-pack-index.c | 61 +++++++++++---------------------------
1 file changed, 17 insertions(+), 44 deletions(-)
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index 2b4e2f0cce9e..d3881aee6a11 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -100,20 +100,13 @@ static struct odb_source_packed *handle_object_dir_option(struct repository *rep
return dir->packed;
}
-static struct option common_opts[] = {
- OPT_CALLBACK(0, "object-dir", &opts.object_dir,
- N_("directory"),
- N_("object directory containing set of packfile and pack-index pairs"),
- parse_object_dir),
- OPT_BIT(0, "progress", &opts.flags, N_("force progress reporting"),
- MIDX_PROGRESS),
- OPT_END(),
-};
-
-static struct option *add_common_options(struct option *prev)
-{
- return parse_options_concat(common_opts, prev);
-}
+#define MULTI_PACK_INDEX_COMMON_OPTIONS(opts) \
+ OPT_CALLBACK(0, "object-dir", &(opts)->object_dir, \
+ N_("directory"), \
+ N_("object directory containing set of packfile and pack-index pairs"), \
+ parse_object_dir), \
+ OPT_BIT(0, "progress", &(opts)->flags, N_("force progress reporting"), \
+ MIDX_PROGRESS)
static int git_multi_pack_index_write_config(const char *var, const char *value,
const struct config_context *ctx UNUSED,
@@ -154,8 +147,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
const char *prefix,
struct repository *repo)
{
- struct option *options;
- static struct option builtin_multi_pack_index_write_options[] = {
+ static struct option options[] = {
OPT_STRING(0, "preferred-pack", &opts.preferred_pack,
N_("preferred-pack"),
N_("pack for reuse when computing a multi-pack bitmap")),
@@ -172,6 +164,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
N_("write multi-pack index containing only given indexes")),
OPT_FILENAME(0, "refs-snapshot", &opts.refs_snapshot,
N_("refs snapshot for selecting bitmap commits")),
+ MULTI_PACK_INDEX_COMMON_OPTIONS(&opts),
OPT_END(),
};
struct odb_source_packed *packed_source;
@@ -181,8 +174,6 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
repo_config(repo, git_multi_pack_index_write_config, NULL);
- options = add_common_options(builtin_multi_pack_index_write_options);
-
trace2_cmd_mode(argv[0]);
if (isatty(2))
@@ -211,8 +202,6 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
packed_source = handle_object_dir_option(repo);
- FREE_AND_NULL(options);
-
if (opts.stdin_packs) {
struct string_list packs = STRING_LIST_INIT_DUP;
@@ -247,8 +236,7 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,
struct odb_source_packed *packed_source;
int ret;
- struct option *options;
- static struct option builtin_multi_pack_index_compact_options[] = {
+ static struct option options[] = {
OPT_STRING(0, "base", &opts.incremental_base, N_("checksum"),
N_("base MIDX for incremental writes")),
OPT_BIT(0, "bitmap", &opts.flags, N_("write multi-pack bitmap"),
@@ -258,13 +246,12 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,
OPT_NEGBIT(0, "write-chain-file", &opts.flags,
N_("write the multi-pack-index chain file"),
MIDX_WRITE_NO_CHAIN),
+ MULTI_PACK_INDEX_COMMON_OPTIONS(&opts),
OPT_END(),
};
repo_config(repo, git_multi_pack_index_write_config, NULL);
- options = add_common_options(builtin_multi_pack_index_compact_options);
-
trace2_cmd_mode(argv[0]);
if (isatty(2))
@@ -287,8 +274,6 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,
packed_source = handle_object_dir_option(repo);
- FREE_AND_NULL(options);
-
m = get_multi_pack_index(packed_source);
for (cur = m; cur && !(from_midx && to_midx); cur = cur->base_midx) {
@@ -322,14 +307,12 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,
const char *prefix,
struct repository *repo)
{
- struct option *options;
- static struct option builtin_multi_pack_index_verify_options[] = {
+ static struct option options[] = {
+ MULTI_PACK_INDEX_COMMON_OPTIONS(&opts),
OPT_END(),
};
struct odb_source_packed *packed_source;
- options = add_common_options(builtin_multi_pack_index_verify_options);
-
trace2_cmd_mode(argv[0]);
if (isatty(2))
@@ -342,8 +325,6 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,
options);
packed_source = handle_object_dir_option(repo);
- FREE_AND_NULL(options);
-
return verify_midx_file(packed_source, opts.flags);
}
@@ -351,14 +332,12 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv,
const char *prefix,
struct repository *repo)
{
- struct option *options;
- static struct option builtin_multi_pack_index_expire_options[] = {
+ static struct option options[] = {
+ MULTI_PACK_INDEX_COMMON_OPTIONS(&opts),
OPT_END(),
};
struct odb_source_packed *packed_source;
- options = add_common_options(builtin_multi_pack_index_expire_options);
-
trace2_cmd_mode(argv[0]);
if (isatty(2))
@@ -371,8 +350,6 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv,
options);
packed_source = handle_object_dir_option(repo);
- FREE_AND_NULL(options);
-
return expire_midx_packs(packed_source, opts.flags);
}
@@ -380,16 +357,14 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,
const char *prefix,
struct repository *repo)
{
- struct option *options;
- static struct option builtin_multi_pack_index_repack_options[] = {
+ static struct option options[] = {
OPT_UNSIGNED(0, "batch-size", &opts.batch_size,
N_("during repack, collect pack-files of smaller size into a batch that is larger than this size")),
+ MULTI_PACK_INDEX_COMMON_OPTIONS(&opts),
OPT_END(),
};
struct odb_source_packed *packed_source;
- options = add_common_options(builtin_multi_pack_index_repack_options);
-
trace2_cmd_mode(argv[0]);
if (isatty(2))
@@ -403,8 +378,6 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,
options);
packed_source = handle_object_dir_option(repo);
- FREE_AND_NULL(options);
-
return midx_repack(packed_source, (size_t)opts.batch_size, opts.flags);
}
--
2.56.0
[PATCH 5/5] builtin/multi-pack-index: de-globalize options handling
Author: Justin Tobler
Date: Mon, 30 Nov 2026 21:55
Date: Mon, 30 Nov 2026 21:55
277 lines
19796 bytes
19796 bytes
The options for git-multi-pack-index(1) are stored in a global variable
even though each option is only needed by the subcommand that parses it.
The config callback for the "write" and "compact" subcommands also
accesses the options, but they can just as well be passed to it via the
callback data.
Now that `cmd_multi_pack_index()` no longer parses any of these options
itself, nothing requires them to be global anymore. Refactor each
subcommand to track its options in a local variable and pass them to the
config callback accordingly. With this change, no global state remains
in "builtin/multi-pack-index.c".
Signed-off-by: Justin Tobler <jltobler@gmail.com>
---
builtin/multi-pack-index.c | 77 +++++++++++++++++++++++---------------
1 file changed, 47 insertions(+), 30 deletions(-)
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index d3881aee6a11..eb5c77456b33 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -62,7 +62,7 @@ static char const * const builtin_multi_pack_index_usage[] = {
NULL
};
-static struct opts_multi_pack_index {
+struct opts_multi_pack_index {
char *object_dir;
const char *preferred_pack;
const char *incremental_base;
@@ -70,8 +70,7 @@ static struct opts_multi_pack_index {
unsigned long batch_size;
unsigned flags;
int stdin_packs;
-} opts;
-
+};
static int parse_object_dir(const struct option *opt, const char *arg,
int unset)
@@ -85,9 +84,9 @@ static int parse_object_dir(const struct option *opt, const char *arg,
return 0;
}
-static struct odb_source_packed *handle_object_dir_option(struct repository *repo)
+static struct odb_source_packed *handle_object_dir_option(struct repository *repo,
+ const char *object_dir)
{
- const char *object_dir = opts.object_dir;
struct odb_files_dir *dir;
if (!object_dir)
@@ -110,20 +109,22 @@ static struct odb_source_packed *handle_object_dir_option(struct repository *rep
static int git_multi_pack_index_write_config(const char *var, const char *value,
const struct config_context *ctx UNUSED,
- void *cb UNUSED)
+ void *cb_data)
{
+ struct opts_multi_pack_index *opts = cb_data;
+
if (!strcmp(var, "pack.writebitmaphashcache")) {
if (git_config_bool(var, value))
- opts.flags |= MIDX_WRITE_BITMAP_HASH_CACHE;
+ opts->flags |= MIDX_WRITE_BITMAP_HASH_CACHE;
else
- opts.flags &= ~MIDX_WRITE_BITMAP_HASH_CACHE;
+ opts->flags &= ~MIDX_WRITE_BITMAP_HASH_CACHE;
}
if (!strcmp(var, "pack.writebitmaplookuptable")) {
if (git_config_bool(var, value))
- opts.flags |= MIDX_WRITE_BITMAP_LOOKUP_TABLE;
+ opts->flags |= MIDX_WRITE_BITMAP_LOOKUP_TABLE;
else
- opts.flags &= ~MIDX_WRITE_BITMAP_LOOKUP_TABLE;
+ opts->flags &= ~MIDX_WRITE_BITMAP_LOOKUP_TABLE;
}
/*
@@ -147,7 +148,8 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
const char *prefix,
struct repository *repo)
{
- static struct option options[] = {
+ struct opts_multi_pack_index opts = { 0 };
+ struct option options[] = {
OPT_STRING(0, "preferred-pack", &opts.preferred_pack,
N_("preferred-pack"),
N_("pack for reuse when computing a multi-pack bitmap")),
@@ -172,7 +174,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
opts.flags |= MIDX_WRITE_BITMAP_HASH_CACHE;
- repo_config(repo, git_multi_pack_index_write_config, NULL);
+ repo_config(repo, git_multi_pack_index_write_config, &opts);
trace2_cmd_mode(argv[0]);
@@ -200,7 +202,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
options);
}
- packed_source = handle_object_dir_option(repo);
+ packed_source = handle_object_dir_option(repo, opts.object_dir);
if (opts.stdin_packs) {
struct string_list packs = STRING_LIST_INIT_DUP;
@@ -214,6 +216,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
string_list_clear(&packs, 0);
free(opts.refs_snapshot);
+ free(opts.object_dir);
return ret;
@@ -223,6 +226,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
opts.refs_snapshot, opts.flags);
free(opts.refs_snapshot);
+ free(opts.object_dir);
return ret;
}
@@ -230,13 +234,14 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,
const char *prefix,
struct repository *repo)
{
+ struct opts_multi_pack_index opts = { 0 };
struct multi_pack_index *m, *cur;
struct multi_pack_index *from_midx = NULL;
struct multi_pack_index *to_midx = NULL;
struct odb_source_packed *packed_source;
int ret;
- static struct option options[] = {
+ struct option options[] = {
OPT_STRING(0, "base", &opts.incremental_base, N_("checksum"),
N_("base MIDX for incremental writes")),
OPT_BIT(0, "bitmap", &opts.flags, N_("write multi-pack bitmap"),
@@ -250,7 +255,7 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,
OPT_END(),
};
- repo_config(repo, git_multi_pack_index_write_config, NULL);
+ repo_config(repo, git_multi_pack_index_write_config, &opts);
trace2_cmd_mode(argv[0]);
@@ -272,7 +277,7 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,
options);
}
- packed_source = handle_object_dir_option(repo);
+ packed_source = handle_object_dir_option(repo, opts.object_dir);
m = get_multi_pack_index(packed_source);
@@ -300,6 +305,7 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,
ret = write_midx_file_compact(packed_source, from_midx, to_midx,
opts.incremental_base, opts.flags);
+ free(opts.object_dir);
return ret;
}
@@ -307,11 +313,13 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,
const char *prefix,
struct repository *repo)
{
- static struct option options[] = {
+ struct opts_multi_pack_index opts = { 0 };
+ struct option options[] = {
MULTI_PACK_INDEX_COMMON_OPTIONS(&opts),
OPT_END(),
};
struct odb_source_packed *packed_source;
+ int ret;
trace2_cmd_mode(argv[0]);
@@ -323,20 +331,25 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,
if (argc)
usage_with_options(builtin_multi_pack_index_verify_usage,
options);
- packed_source = handle_object_dir_option(repo);
+ packed_source = handle_object_dir_option(repo, opts.object_dir);
- return verify_midx_file(packed_source, opts.flags);
+ ret = verify_midx_file(packed_source, opts.flags);
+
+ free(opts.object_dir);
+ return ret;
}
static int cmd_multi_pack_index_expire(int argc, const char **argv,
const char *prefix,
struct repository *repo)
{
- static struct option options[] = {
+ struct opts_multi_pack_index opts = { 0 };
+ struct option options[] = {
MULTI_PACK_INDEX_COMMON_OPTIONS(&opts),
OPT_END(),
};
struct odb_source_packed *packed_source;
+ int ret;
trace2_cmd_mode(argv[0]);
@@ -348,22 +361,27 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv,
if (argc)
usage_with_options(builtin_multi_pack_index_expire_usage,
options);
- packed_source = handle_object_dir_option(repo);
+ packed_source = handle_object_dir_option(repo, opts.object_dir);
+
+ ret = expire_midx_packs(packed_source, opts.flags);
- return expire_midx_packs(packed_source, opts.flags);
+ free(opts.object_dir);
+ return ret;
}
static int cmd_multi_pack_index_repack(int argc, const char **argv,
const char *prefix,
struct repository *repo)
{
- static struct option options[] = {
+ struct opts_multi_pack_index opts = { 0 };
+ struct option options[] = {
OPT_UNSIGNED(0, "batch-size", &opts.batch_size,
N_("during repack, collect pack-files of smaller size into a batch that is larger than this size")),
MULTI_PACK_INDEX_COMMON_OPTIONS(&opts),
OPT_END(),
};
struct odb_source_packed *packed_source;
+ int ret;
trace2_cmd_mode(argv[0]);
@@ -376,9 +394,12 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,
if (argc)
usage_with_options(builtin_multi_pack_index_repack_usage,
options);
- packed_source = handle_object_dir_option(repo);
+ packed_source = handle_object_dir_option(repo, opts.object_dir);
+
+ ret = midx_repack(packed_source, (size_t)opts.batch_size, opts.flags);
- return midx_repack(packed_source, (size_t)opts.batch_size, opts.flags);
+ free(opts.object_dir);
+ return ret;
}
int cmd_multi_pack_index(int argc,
@@ -386,7 +407,6 @@ int cmd_multi_pack_index(int argc,
const char *prefix,
struct repository *repo)
{
- int res;
parse_opt_subcommand_fn *fn = NULL;
struct option options[] = {
OPT_SUBCOMMAND("repack", &fn, cmd_multi_pack_index_repack),
@@ -404,8 +424,5 @@ int cmd_multi_pack_index(int argc,
argc = parse_options(argc, argv, prefix, options,
builtin_multi_pack_index_usage, 0);
- res = fn(argc, argv, prefix, repo);
-
- free(opts.object_dir);
- return res;
+ return fn(argc, argv, prefix, repo);
}
--
2.56.0
Re: [PATCH 1/5] builtin/multi-pack-index: resolve default object directory lazily
Author: Justin Tobler
Date: Tue, 01 Dec 2026 16:39
Date: Tue, 01 Dec 2026 16:39
24 lines
11394 bytes
11394 bytes
On 26/12/01 11:58AM, Patrick Steinhardt wrote: > On Mon, Nov 30, 2026 at 03:54:57PM -0600, Justin Tobler wrote: > > diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c > > index c48212290cf8..1a27d523c7ab 100644 > > --- a/builtin/multi-pack-index.c > > +++ b/builtin/multi-pack-index.c > > @@ -80,7 +80,7 @@ static int parse_object_dir(const struct option *opt, const char *arg, > > char **value = opt->value; > > free(*value); > > if (unset) > > - *value = xstrdup(the_repository->objects->source->path); > > + *value = NULL; > > else > > *value = real_pathdup(arg, 1); > > return 0; > > Makes me wonder whether we could avoid allocating the value altogether > and just assign the static string? Ya, now that the option value is only set here, it should be fine to stop allocating the string. Will update in the next version. -Justin
Re: [PATCH 2/5] builtin/multi-pack-index: get rid of `the_repository`
Author: Justin Tobler
Date: Tue, 01 Dec 2026 16:46
Date: Tue, 01 Dec 2026 16:46
18 lines
11319 bytes
11319 bytes
On 26/12/01 11:58AM, Patrick Steinhardt wrote: > On Mon, Nov 30, 2026 at 03:54:58PM -0600, Justin Tobler wrote: > > There are a couple of remaining references to `the_repository` in > > git-multi-pack-index(1). The command cannot run outside of a repository, > > so these references can be trivially replaced with the repository > > passed to the subcommands. > > Right, but only in the case where `repo` is not dereferenced before we > call `parse_options()`. You do pass it to `repo_config()`, which > (somewhat misleadingly) accepts `repo == NULL`. That is correct. The repository could still be NULL here when running something like `git multi-pack-index -h` in which case would need to be handled by `parse_options()` first. I'll try to clarify the message slightly in the next version. -Justin
Re: [PATCH 3/5] builtin/multi-pack-index: drop top-level options
Author: Justin Tobler
Date: Tue, 01 Dec 2026 17:11
Date: Tue, 01 Dec 2026 17:11
68 lines
13201 bytes
13201 bytes
On 26/12/01 11:58AM, Patrick Steinhardt wrote:
> On Mon, Nov 30, 2026 at 03:54:59PM -0600, Justin Tobler wrote:
> > diff --git a/Documentation/git-multi-pack-index.adoc b/Documentation/git-multi-pack-index.adoc
> > index c6d23aeeb9a0..0dd675f3fd46 100644
> > --- a/Documentation/git-multi-pack-index.adoc
> > +++ b/Documentation/git-multi-pack-index.adoc
> > @@ -9,16 +9,16 @@ git-multi-pack-index - Write and verify multi-pack-indexes
> > SYNOPSIS
> > --------
> > [verse]
> > -'git multi-pack-index' [<options>] write [--preferred-pack=<pack>]
> > +'git multi-pack-index' write [<options>] [--preferred-pack=<pack>]
>
> Is the `[<options>]` placeholder even required now? We already list all
> the options, don't we?
Both the synopsis and usage strings still only explicitly list the
options specific to each subcommand. The common options are only denoted
via `[<options>]`. It might just be better to be explicit here though
and write out both the common options for each of the subcommands. I'll
do this in the next version.
> > diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
> > index 8528f4f513ef..2b4e2f0cce9e 100644
> > --- a/builtin/multi-pack-index.c
> > +++ b/builtin/multi-pack-index.c
> > @@ -415,7 +415,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),
> > @@ -423,7 +423,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();
> >
> > @@ -431,7 +430,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);
> >
>
> I really dislike this `parse_options_concat()` pattern. We can also
> easily replace it by defininging something like:
>
> #define MULTI_PACK_INDEX_COMMON_OPTIONS(var) \
> OPT_FOO(...), \
> OPT_BAR(...)
>
> And then you simply add it to the options at compile time. So maybe
> that's another refactoring we could add in a subsequent patch?
>
> ... Ah, you already do in your next patch. Great!
Yup! :)
-Justin
Re: [PATCH 4/5] builtin/multi-pack-index: simplify how common options are wired up
Author: Justin Tobler
Date: Tue, 01 Dec 2026 17:13
Date: Tue, 01 Dec 2026 17:13
31 lines
11893 bytes
11893 bytes
On 26/12/01 11:58AM, Patrick Steinhardt wrote:
> On Mon, Nov 30, 2026 at 03:55:00PM -0600, Justin Tobler wrote:
> > @@ -154,8 +147,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
> > const char *prefix,
> > struct repository *repo)
> > {
> > - struct option *options;
> > - static struct option builtin_multi_pack_index_write_options[] = {
> > + static struct option options[] = {
> > OPT_STRING(0, "preferred-pack", &opts.preferred_pack,
> > N_("preferred-pack"),
> > N_("pack for reuse when computing a multi-pack bitmap")),
> > @@ -172,6 +164,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
> > N_("write multi-pack index containing only given indexes")),
> > OPT_FILENAME(0, "refs-snapshot", &opts.refs_snapshot,
> > N_("refs snapshot for selecting bitmap commits")),
> > + MULTI_PACK_INDEX_COMMON_OPTIONS(&opts),
> > OPT_END(),
> > };
> > struct odb_source_packed *packed_source;
>
> I think this causes a slight change in that the common opitons are now
> at the end of these options, whereas they have been at the beginning
> beforehand. Doesn't really matter much, but it can also easily be
> avoided by adding the common options first.
Good catch. I'll move the common options to the front in the next
version.
-Justin
Re: [PATCH 5/5] builtin/multi-pack-index: de-globalize options handling
Author: Justin Tobler
Date: Tue, 01 Dec 2026 17:18
Date: Tue, 01 Dec 2026 17:18
35 lines
11817 bytes
11817 bytes
On 26/12/01 11:59AM, Patrick Steinhardt wrote: > On Mon, Nov 30, 2026 at 03:55:01PM -0600, Justin Tobler wrote: > > diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c > > index d3881aee6a11..eb5c77456b33 100644 > > --- a/builtin/multi-pack-index.c > > +++ b/builtin/multi-pack-index.c > > @@ -214,6 +216,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv, > > > > string_list_clear(&packs, 0); > > free(opts.refs_snapshot); > > + free(opts.object_dir); > > > > return ret; > > > > @@ -223,6 +226,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv, > > opts.refs_snapshot, opts.flags); > > > > free(opts.refs_snapshot); > > + free(opts.object_dir); > > return ret; > > } > > Okay. Now that the options aren't global anymore we of course have to > free everything they reference. It would have been nice though to unify > the logic a bit, either by introducing a common return path or by > introducing a function that releases the memory held on to by `opts`. Or > both. With the changes suggested for patch 1, "--object-dir=" no longer needs to be allocated, and consuently no longer needs to be freed. I'll leave the existing handling of `refs_snapshot` as-is for now. Thanks for the review, -Justin
[PATCH v2 0/5] builtin/multi-pack-index: remove global state
Author: Justin Tobler
Date: Tue, 01 Dec 2026 18:16
Date: Tue, 01 Dec 2026 18:16
523 lines
34517 bytes
34517 bytes
Greetings,
This series cleans up git-multi-pack-index(1) by getting rid of
`the_repository` and the global state used to track its options. Each
subcommand now parses its options into a local structure, and the common
options are wired up via a macro instead of allocating a combined
options array for every subcommand.
The main reason the options are global is that "--object-dir=" and
"--[no-]progress" are also accepted before the subcommand, where the
top-level builtin parses them into the same global state used by the
subcommands. Patch 3 drops support for giving these options before the
subcommand, as every subcommand already accepts both of them.
The "--[no-]progress" option was previously removed as a top-level
option in 0394f8d002 (builtin/multi-pack-index.c: disable top-level
--[no-]progress, 2021-09-20) and appears to have been inadvertently
reintroduced via 6b8fb17490 (builtin/multi-pack-index.c: make
'--progress' a common option, 2026-02-24). So I think it should be fine
to drop.
While "--object-dir=" has never previously been dropped, it appears to
exist as a top-level option for the same historical reason, from when
all options were parsed by the top-level builtin. Since the subcommands
already parse the common options themselves, it should ideally be
dropped as well. If we want to keep this top-level option though, an
alternative could be to propagate the option argument to each
subcommand. In this case, I don't think it's worth it, but happy to
change if others feel differently.
This series is built on top of 86e79b2795 (The 26th batch, 2026-11-29).
Changes since V1:
- "--object-dir=" is now parsed via `OPT_STRING()`, so the option
value no longer needs to be allocated or freed.
- Clarified in the message of patch 2 that the repository may still be
`NULL` until `parse_options()` has been called.
- The synopsis and usage strings now explicitly list the common
options instead of using the `[<options>]` placeholder.
- The common options are now added at the front of each options array,
so the order of the "-h" output stays the same.
Thanks for the review,
-Justin
Justin Tobler (5):
builtin/multi-pack-index: resolve default object directory lazily
builtin/multi-pack-index: get rid of `the_repository`
builtin/multi-pack-index: drop top-level options
builtin/multi-pack-index: simplify how common options are wired up
builtin/multi-pack-index: de-globalize options handling
Documentation/git-multi-pack-index.adoc | 23 ++--
builtin/multi-pack-index.c | 165 +++++++++---------------
t/lib-midx.sh | 2 +-
t/t5319-multi-pack-index.sh | 32 ++---
4 files changed, 91 insertions(+), 131 deletions(-)
Range-diff against v1:
1: c381afb0da59 ! 1: 3e6369b99ba3 builtin/multi-pack-index: resolve default object directory lazily
@@ Commit message
where the repository is passed in explicitly. This also removes the
need for the defensive `NULL` checks guarding the eager initialization.
+ With the default handled lazily, the callback for "--object-dir=" is
+ only left to resolve the given path via `real_pathdup()`. This is
+ unnecessary though, as `odb_source_files_find_dir()` already resolves
+ the path itself when looking up the matching object directory. Replace
+ the callback with a plain `OPT_STRING()`, which also means that the
+ option value no longer has to be allocated and freed.
+
Signed-off-by: Justin Tobler <jltobler@gmail.com>
## builtin/multi-pack-index.c ##
-@@ builtin/multi-pack-index.c: static int parse_object_dir(const struct option *opt, const char *arg,
- char **value = opt->value;
- free(*value);
- if (unset)
-- *value = xstrdup(the_repository->objects->source->path);
-+ *value = NULL;
- else
- *value = real_pathdup(arg, 1);
- return 0;
-@@ builtin/multi-pack-index.c: static int parse_object_dir(const struct option *opt, const char *arg,
+@@
+ #define USE_THE_REPOSITORY_VARIABLE
+ #include "builtin.h"
+-#include "abspath.h"
+ #include "config.h"
+ #include "environment.h"
+ #include "gettext.h"
+@@ builtin/multi-pack-index.c: static char const * const builtin_multi_pack_index_usage[] = {
+ };
+
+ static struct opts_multi_pack_index {
+- char *object_dir;
++ const char *object_dir;
+ const char *preferred_pack;
+ const char *incremental_base;
+ char *refs_snapshot;
+@@ builtin/multi-pack-index.c: static struct opts_multi_pack_index {
+ int stdin_packs;
+ } opts;
+-
+-static int parse_object_dir(const struct option *opt, const char *arg,
+- int unset)
+-{
+- char **value = opt->value;
+- free(*value);
+- if (unset)
+- *value = xstrdup(the_repository->objects->source->path);
+- else
+- *value = real_pathdup(arg, 1);
+- return 0;
+-}
+-
static struct odb_source_packed *handle_object_dir_option(struct repository *repo)
{
- struct odb_files_dir *dir = odb_source_files_find_dir(repo->objects, opts.object_dir);
@@ builtin/multi-pack-index.c: static int parse_object_dir(const struct option *opt
return dir->packed;
}
+ static struct option common_opts[] = {
+- OPT_CALLBACK(0, "object-dir", &opts.object_dir,
+- N_("directory"),
+- N_("object directory containing set of packfile and pack-index pairs"),
+- parse_object_dir),
++ OPT_STRING(0, "object-dir", &opts.object_dir, N_("directory"),
++ N_("object directory containing set of packfile and pack-index pairs")),
+ OPT_BIT(0, "progress", &opts.flags, N_("force progress reporting"),
+ MIDX_PROGRESS),
+ OPT_END(),
@@ builtin/multi-pack-index.c: int cmd_multi_pack_index(int argc,
repo_config(the_repository, git_default_config, NULL);
@@ builtin/multi-pack-index.c: 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);
+
+- free(opts.object_dir);
+ return res;
+ }
2: 673945d65de3 ! 2: 28d7916f0a24 builtin/multi-pack-index: get rid of `the_repository`
@@ Commit message
builtin/multi-pack-index: get rid of `the_repository`
There are a couple of remaining references to `the_repository` in
- git-multi-pack-index(1). The command cannot run outside of a repository,
- so these references can be trivially replaced with the repository
- passed to the subcommands.
+ git-multi-pack-index(1). Replace them with the repository that is passed
+ to the builtin and its subcommands.
+
+ Note that the repository may still be `NULL` until `parse_options()` has
+ been called. The only use of the repository before that point is
+ `repo_config()`, which handles a `NULL` repository.
Signed-off-by: Justin Tobler <jltobler@gmail.com>
@@ builtin/multi-pack-index.c
@@
-#define USE_THE_REPOSITORY_VARIABLE
#include "builtin.h"
- #include "abspath.h"
#include "config.h"
+ #include "environment.h"
@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_write(int argc, const char **argv,
opts.flags |= MIDX_WRITE_BITMAP_HASH_CACHE;
3: cc2876d6803f ! 3: 5fe18c5564c3 builtin/multi-pack-index: drop top-level options
@@ Documentation/git-multi-pack-index.adoc: git-multi-pack-index - Write and verify
--------
[verse]
-'git multi-pack-index' [<options>] write [--preferred-pack=<pack>]
-+'git multi-pack-index' write [<options>] [--preferred-pack=<pack>]
- [--[no-]bitmap] [--[no-]incremental] [--[no-]stdin-packs]
- [--refs-snapshot=<path>] [--[no-]write-chain-file]
- [--base=<checksum>]
+- [--[no-]bitmap] [--[no-]incremental] [--[no-]stdin-packs]
+- [--refs-snapshot=<path>] [--[no-]write-chain-file]
+- [--base=<checksum>]
-'git multi-pack-index' [<options>] compact [--[no-]incremental]
-+'git multi-pack-index' compact [<options>] [--[no-]incremental]
- [--[no-]bitmap] [--base=<checksum>] [--[no-]write-chain-file]
- <from> <to>
+- [--[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' verify [<options>]
-+'git multi-pack-index' expire [<options>]
-+'git multi-pack-index' repack [<options>] [--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
-----------
@@ builtin/multi-pack-index.c
#define BUILTIN_MIDX_WRITE_USAGE \
- N_("git multi-pack-index [<options>] write [--preferred-pack=<pack>]\n" \
-+ N_("git multi-pack-index write [<options>] [--preferred-pack=<pack>]\n" \
- " [--[no-]bitmap] [--[no-]incremental] [--[no-]stdin-packs]\n" \
- " [--refs-snapshot=<path>] [--[no-]write-chain-file]\n" \
- " [--base=<checksum>]")
+- " [--[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" \
-+ N_("git multi-pack-index compact [<options>] [--[no-]incremental]\n" \
- " [--[no-]bitmap] [--base=<checksum>] [--[no-]write-chain-file]\n" \
- " <from> <to>")
+- " [--[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 [<options>]")
++ 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 [<options>]")
++ 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 [<options>] [--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,
4: 1c16a0988239 ! 4: 3bb2b9a69f1c builtin/multi-pack-index: simplify how common options are wired up
@@ builtin/multi-pack-index.c: static struct odb_source_packed *handle_object_dir_o
}
-static struct option common_opts[] = {
-- OPT_CALLBACK(0, "object-dir", &opts.object_dir,
-- N_("directory"),
-- N_("object directory containing set of packfile and pack-index pairs"),
-- parse_object_dir),
+- OPT_STRING(0, "object-dir", &opts.object_dir, N_("directory"),
+- N_("object directory containing set of packfile and pack-index pairs")),
- OPT_BIT(0, "progress", &opts.flags, N_("force progress reporting"),
- MIDX_PROGRESS),
- OPT_END(),
@@ builtin/multi-pack-index.c: static struct odb_source_packed *handle_object_dir_o
- return parse_options_concat(common_opts, prev);
-}
+#define MULTI_PACK_INDEX_COMMON_OPTIONS(opts) \
-+ OPT_CALLBACK(0, "object-dir", &(opts)->object_dir, \
-+ N_("directory"), \
-+ N_("object directory containing set of packfile and pack-index pairs"), \
-+ parse_object_dir), \
++ OPT_STRING(0, "object-dir", &(opts)->object_dir, N_("directory"), \
++ N_("object directory containing set of packfile and pack-index pairs")), \
+ OPT_BIT(0, "progress", &(opts)->flags, N_("force progress reporting"), \
+ MIDX_PROGRESS)
@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_write(int argc, cons
- struct option *options;
- static struct option builtin_multi_pack_index_write_options[] = {
+ static struct option options[] = {
++ MULTI_PACK_INDEX_COMMON_OPTIONS(&opts),
OPT_STRING(0, "preferred-pack", &opts.preferred_pack,
N_("preferred-pack"),
N_("pack for reuse when computing a multi-pack bitmap")),
@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_write(int argc, const char **argv,
- N_("write multi-pack index containing only given indexes")),
- OPT_FILENAME(0, "refs-snapshot", &opts.refs_snapshot,
- N_("refs snapshot for selecting bitmap commits")),
-+ MULTI_PACK_INDEX_COMMON_OPTIONS(&opts),
- OPT_END(),
- };
- struct odb_source_packed *packed_source;
-@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_write(int argc, const char **argv,
repo_config(repo, git_multi_pack_index_write_config, NULL);
@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_compact(int argc, co
- struct option *options;
- static struct option builtin_multi_pack_index_compact_options[] = {
+ static struct option options[] = {
++ MULTI_PACK_INDEX_COMMON_OPTIONS(&opts),
OPT_STRING(0, "base", &opts.incremental_base, N_("checksum"),
N_("base MIDX for incremental writes")),
OPT_BIT(0, "bitmap", &opts.flags, N_("write multi-pack bitmap"),
@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_compact(int argc, const char **argv,
- OPT_NEGBIT(0, "write-chain-file", &opts.flags,
- N_("write the multi-pack-index chain file"),
- MIDX_WRITE_NO_CHAIN),
-+ MULTI_PACK_INDEX_COMMON_OPTIONS(&opts),
- OPT_END(),
- };
repo_config(repo, git_multi_pack_index_write_config, NULL);
@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_repack(int argc, con
- struct option *options;
- static struct option builtin_multi_pack_index_repack_options[] = {
+ static struct option options[] = {
++ MULTI_PACK_INDEX_COMMON_OPTIONS(&opts),
OPT_UNSIGNED(0, "batch-size", &opts.batch_size,
N_("during repack, collect pack-files of smaller size into a batch that is larger than this size")),
-+ MULTI_PACK_INDEX_COMMON_OPTIONS(&opts),
OPT_END(),
};
struct odb_source_packed *packed_source;
5: d8ac43810193 ! 5: 46a59a5daf52 builtin/multi-pack-index: de-globalize options handling
@@ builtin/multi-pack-index.c: static char const * const builtin_multi_pack_index_u
-static struct opts_multi_pack_index {
+struct opts_multi_pack_index {
- char *object_dir;
+ const char *object_dir;
const char *preferred_pack;
const char *incremental_base;
@@ builtin/multi-pack-index.c: static struct opts_multi_pack_index {
@@ builtin/multi-pack-index.c: static struct opts_multi_pack_index {
unsigned flags;
int stdin_packs;
-} opts;
--
+};
- static int parse_object_dir(const struct option *opt, const char *arg,
- int unset)
-@@ builtin/multi-pack-index.c: static int parse_object_dir(const struct option *opt, const char *arg,
- return 0;
- }
-
-static struct odb_source_packed *handle_object_dir_option(struct repository *repo)
+static struct odb_source_packed *handle_object_dir_option(struct repository *repo,
+ const char *object_dir)
@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_write(int argc, cons
- static struct option options[] = {
+ struct opts_multi_pack_index opts = { 0 };
+ struct option options[] = {
+ MULTI_PACK_INDEX_COMMON_OPTIONS(&opts),
OPT_STRING(0, "preferred-pack", &opts.preferred_pack,
N_("preferred-pack"),
- N_("pack for reuse when computing a multi-pack bitmap")),
@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_write(int argc, const char **argv,
opts.flags |= MIDX_WRITE_BITMAP_HASH_CACHE;
@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_write(int argc, cons
if (opts.stdin_packs) {
struct string_list packs = STRING_LIST_INIT_DUP;
-@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_write(int argc, const char **argv,
-
- string_list_clear(&packs, 0);
- free(opts.refs_snapshot);
-+ free(opts.object_dir);
-
- return ret;
-
-@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_write(int argc, const char **argv,
- opts.refs_snapshot, opts.flags);
-
- free(opts.refs_snapshot);
-+ free(opts.object_dir);
- return ret;
- }
-
@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_compact(int argc, const char **argv,
const char *prefix,
struct repository *repo)
@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_compact(int argc, co
- static struct option options[] = {
+ struct option options[] = {
+ MULTI_PACK_INDEX_COMMON_OPTIONS(&opts),
OPT_STRING(0, "base", &opts.incremental_base, N_("checksum"),
N_("base MIDX for incremental writes")),
- OPT_BIT(0, "bitmap", &opts.flags, N_("write multi-pack bitmap"),
@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_compact(int argc, const char **argv,
OPT_END(),
};
@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_compact(int argc, co
m = get_multi_pack_index(packed_source);
-@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_compact(int argc, const char **argv,
- ret = write_midx_file_compact(packed_source, from_midx, to_midx,
- opts.incremental_base, opts.flags);
-
-+ free(opts.object_dir);
- return ret;
- }
-
@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_verify(int argc, const char **argv,
const char *prefix,
struct repository *repo)
@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_verify(int argc, con
MULTI_PACK_INDEX_COMMON_OPTIONS(&opts),
OPT_END(),
};
- struct odb_source_packed *packed_source;
-+ int ret;
-
- trace2_cmd_mode(argv[0]);
-
@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_verify(int argc, const char **argv,
if (argc)
usage_with_options(builtin_multi_pack_index_verify_usage,
@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_verify(int argc, con
- packed_source = handle_object_dir_option(repo);
+ packed_source = handle_object_dir_option(repo, opts.object_dir);
-- return verify_midx_file(packed_source, opts.flags);
-+ ret = verify_midx_file(packed_source, opts.flags);
-+
-+ free(opts.object_dir);
-+ return ret;
+ return verify_midx_file(packed_source, opts.flags);
}
-
- static int cmd_multi_pack_index_expire(int argc, const char **argv,
+@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_expire(int argc, const char **argv,
const char *prefix,
struct repository *repo)
{
@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_verify(int argc, con
MULTI_PACK_INDEX_COMMON_OPTIONS(&opts),
OPT_END(),
};
- struct odb_source_packed *packed_source;
-+ int ret;
-
- trace2_cmd_mode(argv[0]);
-
@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_expire(int argc, const char **argv,
if (argc)
usage_with_options(builtin_multi_pack_index_expire_usage,
options);
- packed_source = handle_object_dir_option(repo);
+ packed_source = handle_object_dir_option(repo, opts.object_dir);
-+
-+ ret = expire_midx_packs(packed_source, opts.flags);
-- return expire_midx_packs(packed_source, opts.flags);
-+ free(opts.object_dir);
-+ return ret;
+ return expire_midx_packs(packed_source, opts.flags);
}
-
- static int cmd_multi_pack_index_repack(int argc, const char **argv,
+@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_repack(int argc, const char **argv,
const char *prefix,
struct repository *repo)
{
- static struct option options[] = {
+ struct opts_multi_pack_index opts = { 0 };
+ struct option options[] = {
+ MULTI_PACK_INDEX_COMMON_OPTIONS(&opts),
OPT_UNSIGNED(0, "batch-size", &opts.batch_size,
N_("during repack, collect pack-files of smaller size into a batch that is larger than this size")),
- MULTI_PACK_INDEX_COMMON_OPTIONS(&opts),
- OPT_END(),
- };
- struct odb_source_packed *packed_source;
-+ int ret;
-
- trace2_cmd_mode(argv[0]);
-
@@ builtin/multi-pack-index.c: static int cmd_multi_pack_index_repack(int argc, const char **argv,
if (argc)
usage_with_options(builtin_multi_pack_index_repack_usage,
options);
- packed_source = handle_object_dir_option(repo);
+ packed_source = handle_object_dir_option(repo, opts.object_dir);
-+
-+ ret = midx_repack(packed_source, (size_t)opts.batch_size, opts.flags);
-- return midx_repack(packed_source, (size_t)opts.batch_size, opts.flags);
-+ free(opts.object_dir);
-+ return ret;
+ return midx_repack(packed_source, (size_t)opts.batch_size, opts.flags);
}
-
- int cmd_multi_pack_index(int argc,
@@ builtin/multi-pack-index.c: int cmd_multi_pack_index(int argc,
const char *prefix,
struct repository *repo)
@@ builtin/multi-pack-index.c: int cmd_multi_pack_index(int argc,
- res = fn(argc, argv, prefix, repo);
-
-- free(opts.object_dir);
- return res;
+ return fn(argc, argv, prefix, repo);
}
base-commit: 86e79b2795e3ce3b0ad7685edd368574b0c8b9f2
--
2.56.0
[PATCH v2 2/5] builtin/multi-pack-index: get rid of `the_repository`
Author: Justin Tobler
Date: Tue, 01 Dec 2026 18:16
Date: Tue, 01 Dec 2026 18:16
106 lines
14126 bytes
14126 bytes
There are a couple of remaining references to `the_repository` in
git-multi-pack-index(1). Replace them with the repository that is passed
to the builtin and its subcommands.
Note that the repository may still be `NULL` until `parse_options()` has
been called. The only use of the repository before that point is
`repo_config()`, which handles a `NULL` repository.
Signed-off-by: Justin Tobler <jltobler@gmail.com>
---
builtin/multi-pack-index.c | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index ba5f326dd6ef..c1ad8ebbcc15 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -1,4 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
#include "builtin.h"
#include "config.h"
#include "environment.h"
@@ -164,7 +163,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
opts.flags |= MIDX_WRITE_BITMAP_HASH_CACHE;
- repo_config(the_repository, git_multi_pack_index_write_config, NULL);
+ repo_config(repo, git_multi_pack_index_write_config, NULL);
options = add_common_options(builtin_multi_pack_index_write_options);
@@ -270,7 +269,7 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,
options);
}
- packed_source = handle_object_dir_option(the_repository);
+ packed_source = handle_object_dir_option(repo);
FREE_AND_NULL(options);
@@ -305,7 +304,7 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,
static int cmd_multi_pack_index_verify(int argc, const char **argv,
const char *prefix,
- struct repository *repo UNUSED)
+ struct repository *repo)
{
struct option *options;
static struct option builtin_multi_pack_index_verify_options[] = {
@@ -325,7 +324,7 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,
if (argc)
usage_with_options(builtin_multi_pack_index_verify_usage,
options);
- packed_source = handle_object_dir_option(the_repository);
+ packed_source = handle_object_dir_option(repo);
FREE_AND_NULL(options);
@@ -334,7 +333,7 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,
static int cmd_multi_pack_index_expire(int argc, const char **argv,
const char *prefix,
- struct repository *repo UNUSED)
+ struct repository *repo)
{
struct option *options;
static struct option builtin_multi_pack_index_expire_options[] = {
@@ -354,7 +353,7 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv,
if (argc)
usage_with_options(builtin_multi_pack_index_expire_usage,
options);
- packed_source = handle_object_dir_option(the_repository);
+ packed_source = handle_object_dir_option(repo);
FREE_AND_NULL(options);
@@ -363,7 +362,7 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv,
static int cmd_multi_pack_index_repack(int argc, const char **argv,
const char *prefix,
- struct repository *repo UNUSED)
+ struct repository *repo)
{
struct option *options;
static struct option builtin_multi_pack_index_repack_options[] = {
@@ -386,7 +385,7 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,
if (argc)
usage_with_options(builtin_multi_pack_index_repack_usage,
options);
- packed_source = handle_object_dir_option(the_repository);
+ packed_source = handle_object_dir_option(repo);
FREE_AND_NULL(options);
@@ -412,7 +411,7 @@ int cmd_multi_pack_index(int argc,
disable_replace_refs();
- repo_config(the_repository, git_default_config, NULL);
+ repo_config(repo, git_default_config, NULL);
argc = parse_options(argc, argv, prefix, options,
builtin_multi_pack_index_usage, 0);
--
2.56.0
[PATCH v2 3/5] builtin/multi-pack-index: drop top-level options
Author: Justin Tobler
Date: Tue, 01 Dec 2026 18:16
Date: Tue, 01 Dec 2026 18:16
289 lines
23174 bytes
23174 bytes
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 <jltobler@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
[PATCH v2 4/5] builtin/multi-pack-index: simplify how common options are wired up
Author: Justin Tobler
Date: Tue, 01 Dec 2026 18:16
Date: Tue, 01 Dec 2026 18:16
184 lines
17090 bytes
17090 bytes
All git-multi-pack-index(1) subcommands accept the "--object-dir=" and
"--progress" options. To avoid duplicating these common options, a
helper function concatenates them with the options array of each
subcommand. This works, but requires a separate options array to be
allocated and freed for every subcommand.
Define the common options via a preprocessor macro instead, which each
options array can include directly. This avoids the extra allocations
and is less verbose overall.
Signed-off-by: Justin Tobler <jltobler@gmail.com>
---
builtin/multi-pack-index.c | 57 ++++++++++----------------------------
1 file changed, 15 insertions(+), 42 deletions(-)
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index e84df0c947ce..7dfae23411bc 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -87,18 +87,11 @@ static struct odb_source_packed *handle_object_dir_option(struct repository *rep
return dir->packed;
}
-static struct option common_opts[] = {
- OPT_STRING(0, "object-dir", &opts.object_dir, N_("directory"),
- N_("object directory containing set of packfile and pack-index pairs")),
- OPT_BIT(0, "progress", &opts.flags, N_("force progress reporting"),
- MIDX_PROGRESS),
- OPT_END(),
-};
-
-static struct option *add_common_options(struct option *prev)
-{
- return parse_options_concat(common_opts, prev);
-}
+#define MULTI_PACK_INDEX_COMMON_OPTIONS(opts) \
+ OPT_STRING(0, "object-dir", &(opts)->object_dir, N_("directory"), \
+ N_("object directory containing set of packfile and pack-index pairs")), \
+ OPT_BIT(0, "progress", &(opts)->flags, N_("force progress reporting"), \
+ MIDX_PROGRESS)
static int git_multi_pack_index_write_config(const char *var, const char *value,
const struct config_context *ctx UNUSED,
@@ -139,8 +132,8 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
const char *prefix,
struct repository *repo)
{
- struct option *options;
- static struct option builtin_multi_pack_index_write_options[] = {
+ static struct option options[] = {
+ MULTI_PACK_INDEX_COMMON_OPTIONS(&opts),
OPT_STRING(0, "preferred-pack", &opts.preferred_pack,
N_("preferred-pack"),
N_("pack for reuse when computing a multi-pack bitmap")),
@@ -166,8 +159,6 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
repo_config(repo, git_multi_pack_index_write_config, NULL);
- options = add_common_options(builtin_multi_pack_index_write_options);
-
trace2_cmd_mode(argv[0]);
if (isatty(2))
@@ -196,8 +187,6 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
packed_source = handle_object_dir_option(repo);
- FREE_AND_NULL(options);
-
if (opts.stdin_packs) {
struct string_list packs = STRING_LIST_INIT_DUP;
@@ -232,8 +221,8 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,
struct odb_source_packed *packed_source;
int ret;
- struct option *options;
- static struct option builtin_multi_pack_index_compact_options[] = {
+ static struct option options[] = {
+ MULTI_PACK_INDEX_COMMON_OPTIONS(&opts),
OPT_STRING(0, "base", &opts.incremental_base, N_("checksum"),
N_("base MIDX for incremental writes")),
OPT_BIT(0, "bitmap", &opts.flags, N_("write multi-pack bitmap"),
@@ -248,8 +237,6 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,
repo_config(repo, git_multi_pack_index_write_config, NULL);
- options = add_common_options(builtin_multi_pack_index_compact_options);
-
trace2_cmd_mode(argv[0]);
if (isatty(2))
@@ -272,8 +259,6 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,
packed_source = handle_object_dir_option(repo);
- FREE_AND_NULL(options);
-
m = get_multi_pack_index(packed_source);
for (cur = m; cur && !(from_midx && to_midx); cur = cur->base_midx) {
@@ -307,14 +292,12 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,
const char *prefix,
struct repository *repo)
{
- struct option *options;
- static struct option builtin_multi_pack_index_verify_options[] = {
+ static struct option options[] = {
+ MULTI_PACK_INDEX_COMMON_OPTIONS(&opts),
OPT_END(),
};
struct odb_source_packed *packed_source;
- options = add_common_options(builtin_multi_pack_index_verify_options);
-
trace2_cmd_mode(argv[0]);
if (isatty(2))
@@ -327,8 +310,6 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,
options);
packed_source = handle_object_dir_option(repo);
- FREE_AND_NULL(options);
-
return verify_midx_file(packed_source, opts.flags);
}
@@ -336,14 +317,12 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv,
const char *prefix,
struct repository *repo)
{
- struct option *options;
- static struct option builtin_multi_pack_index_expire_options[] = {
+ static struct option options[] = {
+ MULTI_PACK_INDEX_COMMON_OPTIONS(&opts),
OPT_END(),
};
struct odb_source_packed *packed_source;
- options = add_common_options(builtin_multi_pack_index_expire_options);
-
trace2_cmd_mode(argv[0]);
if (isatty(2))
@@ -356,8 +335,6 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv,
options);
packed_source = handle_object_dir_option(repo);
- FREE_AND_NULL(options);
-
return expire_midx_packs(packed_source, opts.flags);
}
@@ -365,16 +342,14 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,
const char *prefix,
struct repository *repo)
{
- struct option *options;
- static struct option builtin_multi_pack_index_repack_options[] = {
+ static struct option options[] = {
+ MULTI_PACK_INDEX_COMMON_OPTIONS(&opts),
OPT_UNSIGNED(0, "batch-size", &opts.batch_size,
N_("during repack, collect pack-files of smaller size into a batch that is larger than this size")),
OPT_END(),
};
struct odb_source_packed *packed_source;
- options = add_common_options(builtin_multi_pack_index_repack_options);
-
trace2_cmd_mode(argv[0]);
if (isatty(2))
@@ -388,8 +363,6 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,
options);
packed_source = handle_object_dir_option(repo);
- FREE_AND_NULL(options);
-
return midx_repack(packed_source, (size_t)opts.batch_size, opts.flags);
}
--
2.56.0
[PATCH v2 5/5] builtin/multi-pack-index: de-globalize options handling
Author: Justin Tobler
Date: Tue, 01 Dec 2026 18:16
Date: Tue, 01 Dec 2026 18:16
212 lines
18210 bytes
18210 bytes
The options for git-multi-pack-index(1) are stored in a global variable
even though each option is only needed by the subcommand that parses it.
The config callback for the "write" and "compact" subcommands also
accesses the options, but they can just as well be passed to it via the
callback data.
Now that `cmd_multi_pack_index()` no longer parses any of these options
itself, nothing requires them to be global anymore. Refactor each
subcommand to track its options in a local variable and pass them to the
config callback accordingly. With this change, no global state remains
in "builtin/multi-pack-index.c".
Signed-off-by: Justin Tobler <jltobler@gmail.com>
---
builtin/multi-pack-index.c | 54 ++++++++++++++++++++------------------
1 file changed, 29 insertions(+), 25 deletions(-)
diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c
index 7dfae23411bc..ac99fec7d3c5 100644
--- a/builtin/multi-pack-index.c
+++ b/builtin/multi-pack-index.c
@@ -62,7 +62,7 @@ static char const * const builtin_multi_pack_index_usage[] = {
NULL
};
-static struct opts_multi_pack_index {
+struct opts_multi_pack_index {
const char *object_dir;
const char *preferred_pack;
const char *incremental_base;
@@ -70,11 +70,11 @@ static struct opts_multi_pack_index {
unsigned long batch_size;
unsigned flags;
int stdin_packs;
-} opts;
+};
-static struct odb_source_packed *handle_object_dir_option(struct repository *repo)
+static struct odb_source_packed *handle_object_dir_option(struct repository *repo,
+ const char *object_dir)
{
- const char *object_dir = opts.object_dir;
struct odb_files_dir *dir;
if (!object_dir)
@@ -95,20 +95,22 @@ static struct odb_source_packed *handle_object_dir_option(struct repository *rep
static int git_multi_pack_index_write_config(const char *var, const char *value,
const struct config_context *ctx UNUSED,
- void *cb UNUSED)
+ void *cb_data)
{
+ struct opts_multi_pack_index *opts = cb_data;
+
if (!strcmp(var, "pack.writebitmaphashcache")) {
if (git_config_bool(var, value))
- opts.flags |= MIDX_WRITE_BITMAP_HASH_CACHE;
+ opts->flags |= MIDX_WRITE_BITMAP_HASH_CACHE;
else
- opts.flags &= ~MIDX_WRITE_BITMAP_HASH_CACHE;
+ opts->flags &= ~MIDX_WRITE_BITMAP_HASH_CACHE;
}
if (!strcmp(var, "pack.writebitmaplookuptable")) {
if (git_config_bool(var, value))
- opts.flags |= MIDX_WRITE_BITMAP_LOOKUP_TABLE;
+ opts->flags |= MIDX_WRITE_BITMAP_LOOKUP_TABLE;
else
- opts.flags &= ~MIDX_WRITE_BITMAP_LOOKUP_TABLE;
+ opts->flags &= ~MIDX_WRITE_BITMAP_LOOKUP_TABLE;
}
/*
@@ -132,7 +134,8 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
const char *prefix,
struct repository *repo)
{
- static struct option options[] = {
+ struct opts_multi_pack_index opts = { 0 };
+ struct option options[] = {
MULTI_PACK_INDEX_COMMON_OPTIONS(&opts),
OPT_STRING(0, "preferred-pack", &opts.preferred_pack,
N_("preferred-pack"),
@@ -157,7 +160,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
opts.flags |= MIDX_WRITE_BITMAP_HASH_CACHE;
- repo_config(repo, git_multi_pack_index_write_config, NULL);
+ repo_config(repo, git_multi_pack_index_write_config, &opts);
trace2_cmd_mode(argv[0]);
@@ -185,7 +188,7 @@ static int cmd_multi_pack_index_write(int argc, const char **argv,
options);
}
- packed_source = handle_object_dir_option(repo);
+ packed_source = handle_object_dir_option(repo, opts.object_dir);
if (opts.stdin_packs) {
struct string_list packs = STRING_LIST_INIT_DUP;
@@ -215,13 +218,14 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,
const char *prefix,
struct repository *repo)
{
+ struct opts_multi_pack_index opts = { 0 };
struct multi_pack_index *m, *cur;
struct multi_pack_index *from_midx = NULL;
struct multi_pack_index *to_midx = NULL;
struct odb_source_packed *packed_source;
int ret;
- static struct option options[] = {
+ struct option options[] = {
MULTI_PACK_INDEX_COMMON_OPTIONS(&opts),
OPT_STRING(0, "base", &opts.incremental_base, N_("checksum"),
N_("base MIDX for incremental writes")),
@@ -235,7 +239,7 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,
OPT_END(),
};
- repo_config(repo, git_multi_pack_index_write_config, NULL);
+ repo_config(repo, git_multi_pack_index_write_config, &opts);
trace2_cmd_mode(argv[0]);
@@ -257,7 +261,7 @@ static int cmd_multi_pack_index_compact(int argc, const char **argv,
options);
}
- packed_source = handle_object_dir_option(repo);
+ packed_source = handle_object_dir_option(repo, opts.object_dir);
m = get_multi_pack_index(packed_source);
@@ -292,7 +296,8 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,
const char *prefix,
struct repository *repo)
{
- static struct option options[] = {
+ struct opts_multi_pack_index opts = { 0 };
+ struct option options[] = {
MULTI_PACK_INDEX_COMMON_OPTIONS(&opts),
OPT_END(),
};
@@ -308,7 +313,7 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv,
if (argc)
usage_with_options(builtin_multi_pack_index_verify_usage,
options);
- packed_source = handle_object_dir_option(repo);
+ packed_source = handle_object_dir_option(repo, opts.object_dir);
return verify_midx_file(packed_source, opts.flags);
}
@@ -317,7 +322,8 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv,
const char *prefix,
struct repository *repo)
{
- static struct option options[] = {
+ struct opts_multi_pack_index opts = { 0 };
+ struct option options[] = {
MULTI_PACK_INDEX_COMMON_OPTIONS(&opts),
OPT_END(),
};
@@ -333,7 +339,7 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv,
if (argc)
usage_with_options(builtin_multi_pack_index_expire_usage,
options);
- packed_source = handle_object_dir_option(repo);
+ packed_source = handle_object_dir_option(repo, opts.object_dir);
return expire_midx_packs(packed_source, opts.flags);
}
@@ -342,7 +348,8 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,
const char *prefix,
struct repository *repo)
{
- static struct option options[] = {
+ struct opts_multi_pack_index opts = { 0 };
+ struct option options[] = {
MULTI_PACK_INDEX_COMMON_OPTIONS(&opts),
OPT_UNSIGNED(0, "batch-size", &opts.batch_size,
N_("during repack, collect pack-files of smaller size into a batch that is larger than this size")),
@@ -361,7 +368,7 @@ static int cmd_multi_pack_index_repack(int argc, const char **argv,
if (argc)
usage_with_options(builtin_multi_pack_index_repack_usage,
options);
- packed_source = handle_object_dir_option(repo);
+ packed_source = handle_object_dir_option(repo, opts.object_dir);
return midx_repack(packed_source, (size_t)opts.batch_size, opts.flags);
}
@@ -371,7 +378,6 @@ int cmd_multi_pack_index(int argc,
const char *prefix,
struct repository *repo)
{
- int res;
parse_opt_subcommand_fn *fn = NULL;
struct option options[] = {
OPT_SUBCOMMAND("repack", &fn, cmd_multi_pack_index_repack),
@@ -389,7 +395,5 @@ int cmd_multi_pack_index(int argc,
argc = parse_options(argc, argv, prefix, options,
builtin_multi_pack_index_usage, 0);
- res = fn(argc, argv, prefix, repo);
-
- return res;
+ return fn(argc, argv, prefix, repo);
}
--
2.56.0
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads