builtin: add a repository parameter for builtin functions

In order to reduce the usage of the global the_repository, add a
parameter to builtin functions that will get passed a repository
variable.

This commit uses UNUSED on most of the builtin functions, as subsequent
commits will modify the actual builtins to pass the repository parameter
down.

Signed-off-by: John Cai <johncai86@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
John Cai
2024-09-13 21:16:14 +00:00
committed by Junio C Hamano
parent 4590f2e941
commit 9b1cb5070f
127 changed files with 703 additions and 296 deletions

12
git.c
View File

@ -31,7 +31,7 @@
struct cmd_struct {
const char *cmd;
int (*fn)(int, const char **, const char *);
int (*fn)(int, const char **, const char *, struct repository *);
unsigned int option;
};
@ -441,7 +441,7 @@ static int handle_alias(int *argcp, const char ***argv)
return ret;
}
static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
static int run_builtin(struct cmd_struct *p, int argc, const char **argv, struct repository *repo)
{
int status, help;
struct stat st;
@ -479,9 +479,9 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
trace_argv_printf(argv, "trace: built-in: git");
trace2_cmd_name(p->cmd);
validate_cache_entries(the_repository->index);
status = p->fn(argc, argv, prefix);
validate_cache_entries(the_repository->index);
validate_cache_entries(repo->index);
status = p->fn(argc, argv, prefix, (p->option & RUN_SETUP)? repo : NULL);
validate_cache_entries(repo->index);
if (status)
return status;
@ -736,7 +736,7 @@ static void handle_builtin(int argc, const char **argv)
builtin = get_builtin(cmd);
if (builtin)
exit(run_builtin(builtin, argc, argv));
exit(run_builtin(builtin, argc, argv, the_repository));
strvec_clear(&args);
}