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

@@ -249,7 +249,8 @@ static int do_clear_stash(void)
ref_stash, &obj, 0);
}
static int clear_stash(int argc, const char **argv, const char *prefix)
static int clear_stash(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{
struct option options[] = {
OPT_END()
@@ -652,7 +653,8 @@ restore_untracked:
return ret;
}
static int apply_stash(int argc, const char **argv, const char *prefix)
static int apply_stash(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{
int ret = -1;
int quiet = 0;
@@ -726,7 +728,8 @@ static int get_stash_info_assert(struct stash_info *info, int argc,
return 0;
}
static int drop_stash(int argc, const char **argv, const char *prefix)
static int drop_stash(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{
int ret = -1;
int quiet = 0;
@@ -748,7 +751,8 @@ cleanup:
return ret;
}
static int pop_stash(int argc, const char **argv, const char *prefix)
static int pop_stash(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{
int ret = -1;
int index = 0;
@@ -778,7 +782,8 @@ cleanup:
return ret;
}
static int branch_stash(int argc, const char **argv, const char *prefix)
static int branch_stash(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{
int ret = -1;
const char *branch = NULL;
@@ -816,7 +821,8 @@ cleanup:
return ret;
}
static int list_stash(int argc, const char **argv, const char *prefix)
static int list_stash(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{
struct child_process cp = CHILD_PROCESS_INIT;
struct option options[] = {
@@ -889,7 +895,8 @@ static void diff_include_untracked(const struct stash_info *info, struct diff_op
do_diff_cache(&info->b_commit, diff_opt);
}
static int show_stash(int argc, const char **argv, const char *prefix)
static int show_stash(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{
int i;
int ret = -1;
@@ -1017,7 +1024,8 @@ static int do_store_stash(const struct object_id *w_commit, const char *stash_ms
return 0;
}
static int store_stash(int argc, const char **argv, const char *prefix)
static int store_stash(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{
int quiet = 0;
const char *stash_msg = NULL;
@@ -1491,7 +1499,8 @@ done:
return ret;
}
static int create_stash(int argc, const char **argv, const char *prefix UNUSED)
static int create_stash(int argc, const char **argv, const char *prefix UNUSED,
struct repository *repo UNUSED)
{
int ret;
struct strbuf stash_msg_buf = STRBUF_INIT;
@@ -1827,12 +1836,14 @@ static int push_stash(int argc, const char **argv, const char *prefix,
return ret;
}
static int push_stash_unassumed(int argc, const char **argv, const char *prefix)
static int push_stash_unassumed(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{
return push_stash(argc, argv, prefix, 0);
}
static int save_stash(int argc, const char **argv, const char *prefix)
static int save_stash(int argc, const char **argv, const char *prefix,
struct repository *repo UNUSED)
{
int keep_index = -1;
int only_staged = 0;
@@ -1878,7 +1889,7 @@ static int save_stash(int argc, const char **argv, const char *prefix)
int cmd_stash(int argc,
const char **argv,
const char *prefix,
struct repository *repo UNUSED)
struct repository *repo)
{
pid_t pid = getpid();
const char *index_file;
@@ -1916,9 +1927,9 @@ int cmd_stash(int argc,
(uintmax_t)pid);
if (fn)
return !!fn(argc, argv, prefix);
return !!fn(argc, argv, prefix, repo);
else if (!argc)
return !!push_stash_unassumed(0, NULL, prefix);
return !!push_stash_unassumed(0, NULL, prefix, repo);
/* Assume 'stash push' */
strvec_push(&args, "push");