Code

bundle, fast-import: detect write failure
[git.git] / environment.c
index f83fb9e44806c03cde06eede7888a4dcb901c5c3..18a1c4eec49bfddcb81d6669c83f8f97a218d7bf 100644 (file)
@@ -31,9 +31,15 @@ size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE;
 size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT;
 size_t delta_base_cache_limit = 16 * 1024 * 1024;
 char *pager_program;
-int pager_in_use;
 int pager_use_color = 1;
+char *editor_program;
+char *excludes_file;
 int auto_crlf = 0;     /* 1: both ways, -1: only when adding git objects */
+unsigned whitespace_rule_cfg = WS_DEFAULT_RULE;
+
+/* This is set by setup_git_dir_gently() and/or git_default_config() */
+char *git_work_tree_cfg;
+static const char *work_tree;
 
 static const char *git_dir;
 static char *git_object_dir, *git_index_file, *git_refs_dir, *git_graft_file;
@@ -62,15 +68,8 @@ static void setup_git_env(void)
 
 int is_bare_repository(void)
 {
-       const char *dir, *s;
-       if (0 <= is_bare_repository_cfg)
-               return is_bare_repository_cfg;
-
-       dir = get_git_dir();
-       if (!strcmp(dir, DEFAULT_GIT_DIR_ENVIRONMENT))
-               return 0;
-       s = strrchr(dir, '/');
-       return !s || strcmp(s + 1, DEFAULT_GIT_DIR_ENVIRONMENT);
+       /* if core.bare is not 'false', let's see if there is a work tree */
+       return is_bare_repository_cfg && !get_git_work_tree();
 }
 
 const char *get_git_dir(void)
@@ -80,6 +79,26 @@ const char *get_git_dir(void)
        return git_dir;
 }
 
+const char *get_git_work_tree(void)
+{
+       static int initialized = 0;
+       if (!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(work_tree)));
+               } else if (work_tree)
+                       work_tree = xstrdup(make_absolute_path(work_tree));
+               initialized = 1;
+               if (work_tree)
+                       is_bare_repository_cfg = 0;
+       }
+       return work_tree;
+}
+
 char *get_object_directory(void)
 {
        if (!git_object_dir)
@@ -107,3 +126,11 @@ char *get_graft_file(void)
                setup_git_env();
        return git_graft_file;
 }
+
+int set_git_dir(const char *path)
+{
+       if (setenv(GIT_DIR_ENVIRONMENT, path, 1))
+               return error("Could not set GIT_DIR to '%s'", path);
+       setup_git_env();
+       return 0;
+}