setup: stop using `the_repository` in `setup_git_directory_gently()`
Stop using `the_repository` in `setup_git_directory_gently()` and instead accept the repository as a parameter. The injection of `the_repository` is thus bumped one level higher, where callers now pass it in explicitly. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>main
parent
27b76d1862
commit
a80a8e3ea6
|
|
@ -1,6 +1,9 @@
|
|||
/*
|
||||
* GIT - The information manager from hell
|
||||
*/
|
||||
|
||||
#define USE_THE_REPOSITORY_VARIABLE
|
||||
|
||||
#include "builtin.h"
|
||||
#include "refs.h"
|
||||
#include "setup.h"
|
||||
|
|
@ -41,7 +44,7 @@ static int check_ref_format_branch(const char *arg)
|
|||
const char *name;
|
||||
int nongit;
|
||||
|
||||
setup_git_directory_gently(&nongit);
|
||||
setup_git_directory_gently(the_repository, &nongit);
|
||||
if (check_branch_ref(&sb, arg) ||
|
||||
!skip_prefix(sb.buf, "refs/heads/", &name))
|
||||
die("'%s' is not a valid branch name", arg);
|
||||
|
|
|
|||
|
|
@ -455,7 +455,7 @@ int cmd_diff(int argc,
|
|||
break;
|
||||
}
|
||||
|
||||
prefix = setup_git_directory_gently(&nongit);
|
||||
prefix = setup_git_directory_gently(the_repository, &nongit);
|
||||
|
||||
if (!nongit) {
|
||||
prepare_repo_settings(the_repository);
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ int cmd_hash_object(int argc,
|
|||
if (flags & INDEX_WRITE_OBJECT)
|
||||
prefix = setup_git_directory();
|
||||
else
|
||||
prefix = setup_git_directory_gently(&nongit);
|
||||
prefix = setup_git_directory_gently(the_repository, &nongit);
|
||||
|
||||
if (nongit && !the_hash_algo)
|
||||
repo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);
|
||||
|
|
|
|||
|
|
@ -740,7 +740,7 @@ int cmd_help(int argc,
|
|||
return 0;
|
||||
}
|
||||
|
||||
setup_git_directory_gently(&nongit);
|
||||
setup_git_directory_gently(the_repository, &nongit);
|
||||
repo_config(the_repository, git_help_config, NULL);
|
||||
|
||||
if (parsed_help_format != HELP_FORMAT_NONE)
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ int cmd_stripspace(int argc,
|
|||
usage_with_options(stripspace_usage, options);
|
||||
|
||||
if (mode == STRIP_COMMENTS || mode == COMMENT_LINES) {
|
||||
setup_git_directory_gently(&nongit);
|
||||
setup_git_directory_gently(the_repository, &nongit);
|
||||
repo_config(the_repository, git_default_config, NULL);
|
||||
}
|
||||
|
||||
|
|
|
|||
6
git.c
6
git.c
|
|
@ -84,7 +84,7 @@ static int list_cmds(const char *spec)
|
|||
* Set up the repository so we can pick up any repo-level config (like
|
||||
* completion.commands).
|
||||
*/
|
||||
setup_git_directory_gently(&nongit);
|
||||
setup_git_directory_gently(the_repository, &nongit);
|
||||
|
||||
while (*spec) {
|
||||
const char *sep = strchrnul(spec, ',');
|
||||
|
|
@ -386,7 +386,7 @@ static int handle_alias(struct strvec *args, struct string_list *expanded_aliase
|
|||
int nongit_ok;
|
||||
|
||||
/* Aliases expect GIT_PREFIX, GIT_DIR etc to be set */
|
||||
setup_git_directory_gently(&nongit_ok);
|
||||
setup_git_directory_gently(the_repository, &nongit_ok);
|
||||
|
||||
commit_pager_choice();
|
||||
|
||||
|
|
@ -480,7 +480,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv, struct
|
|||
prefix = setup_git_directory();
|
||||
no_repo = 0;
|
||||
} else if (run_setup & RUN_SETUP_GENTLY) {
|
||||
prefix = setup_git_directory_gently(&no_repo);
|
||||
prefix = setup_git_directory_gently(the_repository, &no_repo);
|
||||
} else {
|
||||
prefix = NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ int cmd_main(int argc, const char **argv)
|
|||
struct strvec index_pack_args = STRVEC_INIT;
|
||||
int ret;
|
||||
|
||||
setup_git_directory_gently(&nongit);
|
||||
setup_git_directory_gently(the_repository, &nongit);
|
||||
|
||||
while (arg < argc && argv[arg][0] == '-') {
|
||||
const char *p;
|
||||
|
|
|
|||
|
|
@ -1799,7 +1799,7 @@ int cmd_main(int argc, const char **argv)
|
|||
int nongit_ok;
|
||||
int ret;
|
||||
|
||||
setup_git_directory_gently(&nongit_ok);
|
||||
setup_git_directory_gently(the_repository, &nongit_ok);
|
||||
repo_config(the_repository, git_imap_config, &server);
|
||||
|
||||
argc = parse_options(argc, (const char **)argv, "", imap_send_options, imap_send_usage, 0);
|
||||
|
|
|
|||
|
|
@ -1557,7 +1557,7 @@ int cmd_main(int argc, const char **argv)
|
|||
int nongit;
|
||||
int ret = 1;
|
||||
|
||||
setup_git_directory_gently(&nongit);
|
||||
setup_git_directory_gently(the_repository, &nongit);
|
||||
if (argc < 2) {
|
||||
error(_("remote-curl: usage: git remote-curl <remote> [<url>]"));
|
||||
goto cleanup;
|
||||
|
|
@ -1605,7 +1605,7 @@ int cmd_main(int argc, const char **argv)
|
|||
break;
|
||||
if (starts_with(buf.buf, "fetch ")) {
|
||||
if (nongit) {
|
||||
setup_git_directory_gently(&nongit);
|
||||
setup_git_directory_gently(the_repository, &nongit);
|
||||
if (nongit)
|
||||
die(_("remote-curl: fetch attempted without a local repo"));
|
||||
}
|
||||
|
|
|
|||
36
setup.c
36
setup.c
|
|
@ -1862,7 +1862,7 @@ void set_git_work_tree(struct repository *repo, const char *new_work_tree)
|
|||
repo_set_worktree(repo, new_work_tree);
|
||||
}
|
||||
|
||||
const char *setup_git_directory_gently(int *nongit_ok)
|
||||
const char *setup_git_directory_gently(struct repository *repo, int *nongit_ok)
|
||||
{
|
||||
static struct strbuf cwd = STRBUF_INIT;
|
||||
struct strbuf dir = STRBUF_INIT, gitdir = STRBUF_INIT, report = STRBUF_INIT;
|
||||
|
|
@ -1877,7 +1877,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
|
|||
* configuration (including the per-repo config file that we
|
||||
* ignored previously).
|
||||
*/
|
||||
repo_config_clear(the_repository);
|
||||
repo_config_clear(repo);
|
||||
|
||||
/*
|
||||
* Let's assume that we are in a git repository.
|
||||
|
|
@ -1893,18 +1893,18 @@ const char *setup_git_directory_gently(int *nongit_ok)
|
|||
|
||||
switch (setup_git_directory_gently_1(&dir, &gitdir, &report, 1)) {
|
||||
case GIT_DIR_EXPLICIT:
|
||||
prefix = setup_explicit_git_dir(the_repository, gitdir.buf, &cwd, &repo_fmt, nongit_ok);
|
||||
prefix = setup_explicit_git_dir(repo, gitdir.buf, &cwd, &repo_fmt, nongit_ok);
|
||||
break;
|
||||
case GIT_DIR_DISCOVERED:
|
||||
if (dir.len < cwd.len && chdir(dir.buf))
|
||||
die(_("cannot change to '%s'"), dir.buf);
|
||||
prefix = setup_discovered_git_dir(the_repository, gitdir.buf, &cwd, dir.len,
|
||||
prefix = setup_discovered_git_dir(repo, gitdir.buf, &cwd, dir.len,
|
||||
&repo_fmt, nongit_ok);
|
||||
break;
|
||||
case GIT_DIR_BARE:
|
||||
if (dir.len < cwd.len && chdir(dir.buf))
|
||||
die(_("cannot change to '%s'"), dir.buf);
|
||||
prefix = setup_bare_git_dir(the_repository, &cwd, dir.len, &repo_fmt, nongit_ok);
|
||||
prefix = setup_bare_git_dir(repo, &cwd, dir.len, &repo_fmt, nongit_ok);
|
||||
break;
|
||||
case GIT_DIR_HIT_CEILING:
|
||||
if (!nongit_ok)
|
||||
|
|
@ -1984,30 +1984,30 @@ const char *setup_git_directory_gently(int *nongit_ok)
|
|||
startup_info->have_repository ||
|
||||
/* GIT_DIR_EXPLICIT */
|
||||
getenv(GIT_DIR_ENVIRONMENT)) {
|
||||
if (!the_repository->gitdir) {
|
||||
if (!repo->gitdir) {
|
||||
const char *gitdir = getenv(GIT_DIR_ENVIRONMENT);
|
||||
if (!gitdir)
|
||||
gitdir = DEFAULT_GIT_DIR_ENVIRONMENT;
|
||||
setup_git_env(the_repository, gitdir);
|
||||
setup_git_env(repo, gitdir);
|
||||
}
|
||||
if (startup_info->have_repository) {
|
||||
repo_set_hash_algo(the_repository, repo_fmt.hash_algo);
|
||||
repo_set_compat_hash_algo(the_repository,
|
||||
repo_set_hash_algo(repo, repo_fmt.hash_algo);
|
||||
repo_set_compat_hash_algo(repo,
|
||||
repo_fmt.compat_hash_algo);
|
||||
repo_set_ref_storage_format(the_repository,
|
||||
repo_set_ref_storage_format(repo,
|
||||
repo_fmt.ref_storage_format,
|
||||
repo_fmt.ref_storage_payload);
|
||||
the_repository->repository_format_worktree_config =
|
||||
repo->repository_format_worktree_config =
|
||||
repo_fmt.worktree_config;
|
||||
the_repository->repository_format_relative_worktrees =
|
||||
repo->repository_format_relative_worktrees =
|
||||
repo_fmt.relative_worktrees;
|
||||
the_repository->repository_format_submodule_path_cfg =
|
||||
repo->repository_format_submodule_path_cfg =
|
||||
repo_fmt.submodule_path_cfg;
|
||||
/* take ownership of repo_fmt.partial_clone */
|
||||
the_repository->repository_format_partial_clone =
|
||||
repo->repository_format_partial_clone =
|
||||
repo_fmt.partial_clone;
|
||||
repo_fmt.partial_clone = NULL;
|
||||
the_repository->repository_format_precious_objects =
|
||||
repo->repository_format_precious_objects =
|
||||
repo_fmt.precious_objects;
|
||||
}
|
||||
}
|
||||
|
|
@ -2040,13 +2040,13 @@ const char *setup_git_directory_gently(int *nongit_ok)
|
|||
format = ref_storage_format_by_name(backend);
|
||||
if (format == REF_STORAGE_FORMAT_UNKNOWN)
|
||||
die(_("unknown ref storage format: '%s'"), backend);
|
||||
repo_set_ref_storage_format(the_repository, format, payload);
|
||||
repo_set_ref_storage_format(repo, format, payload);
|
||||
|
||||
free(backend);
|
||||
free(payload);
|
||||
}
|
||||
|
||||
setup_original_cwd(the_repository);
|
||||
setup_original_cwd(repo);
|
||||
|
||||
strbuf_release(&dir);
|
||||
strbuf_release(&gitdir);
|
||||
|
|
@ -2138,7 +2138,7 @@ void check_repository_format(struct repository_format *fmt)
|
|||
*/
|
||||
const char *setup_git_directory(void)
|
||||
{
|
||||
return setup_git_directory_gently(NULL);
|
||||
return setup_git_directory_gently(the_repository, NULL);
|
||||
}
|
||||
|
||||
const char *resolve_gitdir_gently(const char *suspect, int *return_error_code)
|
||||
|
|
|
|||
2
setup.h
2
setup.h
|
|
@ -136,7 +136,7 @@ enum {
|
|||
*/
|
||||
const char *enter_repo(struct repository *repo, const char *path, unsigned flags);
|
||||
|
||||
const char *setup_git_directory_gently(int *);
|
||||
const char *setup_git_directory_gently(struct repository *repo, int *);
|
||||
const char *setup_git_directory(void);
|
||||
char *prefix_path(struct repository *repo, const char *prefix, int len, const char *path);
|
||||
char *prefix_path_gently(struct repository *repo, const char *prefix, int len, int *remaining, const char *path);
|
||||
|
|
|
|||
|
|
@ -377,7 +377,7 @@ int cmd__path_utils(int argc, const char **argv)
|
|||
const char *prefix = argv[2];
|
||||
int prefix_len = strlen(prefix);
|
||||
int nongit_ok;
|
||||
setup_git_directory_gently(&nongit_ok);
|
||||
setup_git_directory_gently(the_repository, &nongit_ok);
|
||||
while (argc > 3) {
|
||||
char *pfx = prefix_path(the_repository, prefix, prefix_len, argv[3]);
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ int cmd__subprocess(int argc, const char **argv)
|
|||
struct child_process cp = CHILD_PROCESS_INIT;
|
||||
int nogit = 0;
|
||||
|
||||
setup_git_directory_gently(&nogit);
|
||||
setup_git_directory_gently(the_repository, &nogit);
|
||||
if (nogit)
|
||||
die("No git repo found");
|
||||
if (argc > 1 && !strcmp(argv[1], "--setup-work-tree")) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue