From c14c234f22e0656a61f5718baf155118e6e609c9 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Thu, 22 Jun 2017 11:43:33 -0700 Subject: environment: place key repository state in the_repository Migrate 'git_dir', 'git_common_dir', 'git_object_dir', 'git_index_file', 'git_graft_file', and 'namespace' to be stored in 'the_repository'. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- setup.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'setup.c') diff --git a/setup.c b/setup.c index b477faa442..860507e1fd 100644 --- a/setup.c +++ b/setup.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "repository.h" #include "config.h" #include "dir.h" #include "string-list.h" @@ -398,6 +399,11 @@ void setup_work_tree(void) if (getenv(GIT_WORK_TREE_ENVIRONMENT)) setenv(GIT_WORK_TREE_ENVIRONMENT, ".", 1); + /* + * NEEDSWORK: this call can essentially be set_git_dir(get_git_dir()) + * which can cause some problems when trying to free the old value of + * gitdir. + */ set_git_dir(remove_leading_path(git_dir, work_tree)); initialized = 1; } @@ -1108,8 +1114,15 @@ const char *setup_git_directory_gently(int *nongit_ok) * the user has set GIT_DIR. It may be beneficial to disallow bogus * GIT_DIR values at some point in the future. */ - if (startup_info->have_repository || getenv(GIT_DIR_ENVIRONMENT)) - setup_git_env(); + if (startup_info->have_repository || getenv(GIT_DIR_ENVIRONMENT)) { + if (!the_repository->gitdir) { + const char *gitdir = getenv(GIT_DIR_ENVIRONMENT); + if (!gitdir) + gitdir = DEFAULT_GIT_DIR_ENVIRONMENT; + repo_set_gitdir(the_repository, gitdir); + setup_git_env(); + } + } strbuf_release(&dir); strbuf_release(&gitdir); -- cgit v1.2.3