builtin: pass repository to sub commands

In 9b1cb5070f (builtin: add a repository parameter for builtin
functions, 2024-09-13) the repository was passed down to all builtin
commands. This allowed the repository to be passed down to lower layers
without depending on the global `the_repository` variable.

Continue this work by also passing down the repository parameter from
the command to sub-commands. This will help pass down the repository to
other subsystems and cleanup usage of global variables like
'the_repository' and 'the_hash_algo'.

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Karthik Nayak
2024-11-25 15:55:30 +01:00
committed by Junio C Hamano
parent 6ea2d9d271
commit 6f33d8e255
17 changed files with 239 additions and 135 deletions

View File

@ -1561,7 +1561,8 @@ static int task_option_parse(const struct option *opt UNUSED,
return 0;
}
static int maintenance_run(int argc, const char **argv, const char *prefix)
static int maintenance_run(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{
int i;
struct maintenance_run_opts opts = MAINTENANCE_RUN_OPTS_INIT;
@ -1623,7 +1624,8 @@ static char const * const builtin_maintenance_register_usage[] = {
NULL
};
static int maintenance_register(int argc, const char **argv, const char *prefix)
static int maintenance_register(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{
char *config_file = NULL;
struct option options[] = {
@ -1687,7 +1689,8 @@ static char const * const builtin_maintenance_unregister_usage[] = {
NULL
};
static int maintenance_unregister(int argc, const char **argv, const char *prefix)
static int maintenance_unregister(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{
int force = 0;
char *config_file = NULL;
@ -2917,7 +2920,8 @@ static const char *const builtin_maintenance_start_usage[] = {
NULL
};
static int maintenance_start(int argc, const char **argv, const char *prefix)
static int maintenance_start(int argc, const char **argv, const char *prefix,
struct repository *repo)
{
struct maintenance_start_opts opts = { 0 };
struct option options[] = {
@ -2940,7 +2944,7 @@ static int maintenance_start(int argc, const char **argv, const char *prefix)
if (update_background_schedule(&opts, 1))
die(_("failed to set up maintenance schedule"));
if (maintenance_register(ARRAY_SIZE(register_args)-1, register_args, NULL))
if (maintenance_register(ARRAY_SIZE(register_args)-1, register_args, NULL, repo))
warning(_("failed to add repo to global config"));
return 0;
}
@ -2950,7 +2954,8 @@ static const char *const builtin_maintenance_stop_usage[] = {
NULL
};
static int maintenance_stop(int argc, const char **argv, const char *prefix)
static int maintenance_stop(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{
struct option options[] = {
OPT_END()
@ -2970,7 +2975,7 @@ static const char * const builtin_maintenance_usage[] = {
int cmd_maintenance(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
struct repository *repo)
{
parse_opt_subcommand_fn *fn = NULL;
struct option builtin_maintenance_options[] = {
@ -2984,5 +2989,5 @@ int cmd_maintenance(int argc,
argc = parse_options(argc, argv, prefix, builtin_maintenance_options,
builtin_maintenance_usage, 0);
return fn(argc, argv, prefix);
return fn(argc, argv, prefix, repo);
}