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 <jlto…@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