summaryrefslogtreecommitdiff
path: root/environment.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2010-11-26 22:32:40 +0700
committerJunio C Hamano <gitster@pobox.com>2010-12-22 14:34:24 -0800
commit835183603b4aed84797f60c91c5ebd79be7b2e11 (patch)
tree26185e62bc8382a154dad39d39ca544c43b79f77 /environment.c
parentb3f66fd3e3abeb9183f33f023727e3a53868849d (diff)
downloadgit-835183603b4aed84797f60c91c5ebd79be7b2e11.tar.gz
Remove all logic from get_git_work_tree()
This logic is now only used by cmd_init_db(). setup_* functions do not rely on it any more. Move all the logic to cmd_init_db() and turn get_git_work_tree() into a simple function. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'environment.c')
-rw-r--r--environment.c32
1 files changed, 8 insertions, 24 deletions
diff --git a/environment.c b/environment.c
index d811049a7d..149c132304 100644
--- a/environment.c
+++ b/environment.c
@@ -137,36 +137,20 @@ static int git_work_tree_initialized;
*/
void set_git_work_tree(const char *new_work_tree)
{
+ if (git_work_tree_initialized) {
+ new_work_tree = make_absolute_path(new_work_tree);
+ if (strcmp(new_work_tree, work_tree))
+ die("internal error: work tree has already been set\n"
+ "Current worktree: %s\nNew worktree: %s",
+ work_tree, new_work_tree);
+ return;
+ }
git_work_tree_initialized = 1;
- free(work_tree);
work_tree = xstrdup(make_absolute_path(new_work_tree));
- is_bare_repository_cfg = 0;
}
const char *get_git_work_tree(void)
{
- if (startup_info && !startup_info->setup_explicit) {
- if (is_bare_repository_cfg == 1)
- return NULL;
- if (work_tree)
- is_bare_repository_cfg = 0;
- return work_tree;
- }
-
- if (!git_work_tree_initialized) {
- work_tree = getenv(GIT_WORK_TREE_ENVIRONMENT);
- /* core.bare = true overrides implicit and config work tree */
- if (!work_tree && is_bare_repository_cfg < 1) {
- work_tree = git_work_tree_cfg;
- /* make_absolute_path also normalizes the path */
- if (work_tree && !is_absolute_path(work_tree))
- work_tree = xstrdup(make_absolute_path(git_path("%s", work_tree)));
- } else if (work_tree)
- work_tree = xstrdup(make_absolute_path(work_tree));
- git_work_tree_initialized = 1;
- if (work_tree)
- is_bare_repository_cfg = 0;
- }
return work_tree;
}