summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e142a3c)
raw | patch | inline | side by side (parent: e142a3c)
author | Daniel Barkalow <barkalow@iabervon.org> | |
Sun, 27 Apr 2008 17:39:21 +0000 (13:39 -0400) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 5 May 2008 00:41:44 +0000 (17:41 -0700) |
This function may only be used before the work tree is used.
Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
cache.h | patch | blob | history | |
environment.c | patch | blob | history |
index 9da9179afd035cf4cc5ae403344d872950d6d3b3..aba029315cd2bbe9fe60cc0741ae4005d4552c05 100644 (file)
--- a/cache.h
+++ b/cache.h
extern char *get_graft_file(void);
extern int set_git_dir(const char *path);
extern const char *get_git_work_tree(void);
+extern void set_git_work_tree(const char *tree);
#define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
diff --git a/environment.c b/environment.c
index 6739a3f41745fe1c01dc767e09af8746d6f2815f..0bff43204971bd348f263d0f5fa756212c7ba402 100644 (file)
--- a/environment.c
+++ b/environment.c
/* This is set by setup_git_dir_gently() and/or git_default_config() */
char *git_work_tree_cfg;
-static const char *work_tree;
+static char *work_tree;
static const char *git_dir;
static char *git_object_dir, *git_index_file, *git_refs_dir, *git_graft_file;
return git_dir;
}
+static int git_work_tree_initialized;
+
+/*
+ * Note. This works only before you used a work tree. This was added
+ * primarily to support git-clone to work in a new repository it just
+ * created, and is not meant to flip between different work trees.
+ */
+void set_git_work_tree(const char *new_work_tree)
+{
+ if (is_bare_repository_cfg >= 0)
+ die("cannot set work tree after initialization");
+ 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)
{
- static int initialized = 0;
- if (!initialized) {
+ 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 = xstrdup(make_absolute_path(git_path(work_tree)));
} else if (work_tree)
work_tree = xstrdup(make_absolute_path(work_tree));
- initialized = 1;
+ git_work_tree_initialized = 1;
if (work_tree)
is_bare_repository_cfg = 0;
}