blob: 2d0c3153791d7cceffb12f50dd5a7716b8c0a8c0 [file] [log] [blame]
Linus Torvaldse1b10392005-10-11 18:47:34 -07001/*
2 * We put all the git config variables in this same object
3 * file, so that programs can link against the config parser
4 * without having to link against all the rest of git.
5 *
6 * In particular, no need to bring in libz etc unless needed,
7 * even if you might want to know where the git directory etc
8 * are.
9 */
10#include "cache.h"
11
12char git_default_email[MAX_GITNAME];
13char git_default_name[MAX_GITNAME];
Santi Béjarbb1ae3f2008-05-04 18:04:51 +020014int user_ident_explicitly_given;
Linus Torvaldse1b10392005-10-11 18:47:34 -070015int trust_executable_bit = 1;
Alex Riesen1ce47902008-07-28 08:31:28 +020016int trust_ctime = 1;
Johannes Sixt78a8d642007-03-02 22:11:30 +010017int has_symlinks = 1;
Linus Torvalds0a9b88b2008-03-21 16:52:46 -070018int ignore_case;
David Rientjes96f1e582006-08-15 10:23:48 -070019int assume_unchanged;
20int prefer_symlink_refs;
Junio C Hamano7d1864c2007-01-07 02:00:28 -080021int is_bare_repository_cfg = -1; /* unspecified */
Junio C Hamano510c5a82007-01-07 01:35:34 -080022int log_all_ref_updates = -1; /* unspecified */
Junio C Hamano1b371f52006-03-23 23:42:40 -080023int warn_ambiguous_refs = 1;
David Rientjes96f1e582006-08-15 10:23:48 -070024int repository_format_version;
Shawn O. Pearce1a8f2742007-03-12 15:33:18 -040025const char *git_commit_encoding;
Shawn O. Pearce3a556022007-03-06 20:44:17 -050026const char *git_log_output_encoding;
Junio C Hamano94df2502006-06-09 23:09:49 -070027int shared_repository = PERM_UMASK;
David Rientjes96f1e582006-08-15 10:23:48 -070028const char *apply_default_whitespace;
Giuseppe Bilotta86c91f92009-08-04 13:16:49 +020029const char *apply_default_ignorewhitespace;
Dana How960ccca2007-05-09 13:56:50 -070030int zlib_compression_level = Z_BEST_SPEED;
31int core_compression_level;
32int core_compression_seen;
Linus Torvaldsaafe9fb2008-06-18 15:18:44 -070033int fsync_object_files;
Shawn O. Pearce8c825342006-12-24 00:46:13 -050034size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE;
35size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT;
Shawn O. Pearce18bdec12007-03-19 01:14:37 -040036size_t delta_base_cache_limit = 16 * 1024 * 1024;
Christian Couder872da322008-02-16 06:01:11 +010037const char *pager_program;
Matthias Lederhoferaa086eb2006-07-30 00:27:43 +020038int pager_use_color = 1;
Christian Couderee9601e2008-02-16 06:01:41 +010039const char *editor_program;
Anselm Kruisd3e7da82010-08-30 15:38:38 +020040const char *askpass_program;
Christian Couderdfb068b2008-02-16 06:01:59 +010041const char *excludes_file;
Eyvind Bernhardsenfd6cce92010-05-19 22:43:10 +020042enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;
Christian Couderdae556b2009-01-23 10:07:46 +010043int read_replace_refs = 1;
Eyvind Bernhardsen942e7742010-06-04 21:29:08 +020044enum eol eol = EOL_UNSET;
Steffen Prohaska21e5ad52008-02-06 12:25:58 +010045enum safe_crlf safe_crlf = SAFE_CRLF_WARN;
Junio C Hamanocf1b7862007-12-06 00:14:14 -080046unsigned whitespace_rule_cfg = WS_DEFAULT_RULE;
Jay Soffian9ed36cf2008-02-19 11:24:37 -050047enum branch_track git_branch_track = BRANCH_TRACK_REMOTE;
Dustin Sallingsc998ae92008-05-10 15:36:29 -070048enum rebase_setup_type autorebase = AUTOREBASE_NEVER;
Junio C Hamanobba0fd22009-07-18 17:19:47 -070049enum push_default_type push_default = PUSH_DEFAULT_MATCHING;
Johannes Schindelin348df162009-04-28 00:32:25 +020050#ifndef OBJECT_CREATION_MODE
51#define OBJECT_CREATION_MODE OBJECT_CREATION_USES_HARDLINKS
Johannes Schindelinbe66a6c2009-04-25 11:57:14 +020052#endif
Johannes Schindelin348df162009-04-28 00:32:25 +020053enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE;
Johannes Schindelina97a7462009-10-09 12:21:57 +020054char *notes_ref_name;
Johannes Schindelin7f3140c2009-07-23 17:33:49 +020055int grafts_replace_parents = 1;
Nguyễn Thái Ngọc Duy08aefc92009-08-20 20:47:08 +070056int core_apply_sparse_checkout;
Nguyễn Thái Ngọc Duye37c1322010-08-05 21:40:35 -050057struct startup_info *startup_info;
Linus Torvaldse1b10392005-10-11 18:47:34 -070058
Linus Torvalds671c9b72008-11-13 16:36:30 -080059/* Parallel index stat data preload? */
60int core_preload_index = 0;
61
Johannes Schindeline90fdc32007-08-01 01:30:14 +010062/* This is set by setup_git_dir_gently() and/or git_default_config() */
63char *git_work_tree_cfg;
Daniel Barkalow19757d82008-04-27 13:39:21 -040064static char *work_tree;
Johannes Schindeline90fdc32007-08-01 01:30:14 +010065
Pierre Habouzitc5fba162006-08-23 12:39:11 +020066static const char *git_dir;
67static char *git_object_dir, *git_index_file, *git_refs_dir, *git_graft_file;
68
Giuseppe Bilotta48a7c1c2010-02-25 00:34:14 +010069/*
70 * Repository-local GIT_* environment variables
71 * Remember to update local_repo_env_size in cache.h when
72 * the size of the list changes
73 */
74const char * const local_repo_env[LOCAL_REPO_ENV_SIZE + 1] = {
75 ALTERNATE_DB_ENVIRONMENT,
76 CONFIG_ENVIRONMENT,
Jonathan Nieder655e8d92010-08-24 01:41:14 -050077 CONFIG_DATA_ENVIRONMENT,
Giuseppe Bilotta48a7c1c2010-02-25 00:34:14 +010078 DB_ENVIRONMENT,
79 GIT_DIR_ENVIRONMENT,
80 GIT_WORK_TREE_ENVIRONMENT,
81 GRAFT_ENVIRONMENT,
82 INDEX_ENVIRONMENT,
83 NO_REPLACE_OBJECTS_ENVIRONMENT,
84 NULL
85};
86
Linus Torvaldse1b10392005-10-11 18:47:34 -070087static void setup_git_env(void)
88{
89 git_dir = getenv(GIT_DIR_ENVIRONMENT);
90 if (!git_dir)
Lars Hjemlib44ebb12008-02-20 23:13:13 +010091 git_dir = read_gitfile_gently(DEFAULT_GIT_DIR_ENVIRONMENT);
92 if (!git_dir)
Linus Torvaldse1b10392005-10-11 18:47:34 -070093 git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
94 git_object_dir = getenv(DB_ENVIRONMENT);
95 if (!git_object_dir) {
96 git_object_dir = xmalloc(strlen(git_dir) + 9);
97 sprintf(git_object_dir, "%s/objects", git_dir);
98 }
99 git_refs_dir = xmalloc(strlen(git_dir) + 6);
100 sprintf(git_refs_dir, "%s/refs", git_dir);
101 git_index_file = getenv(INDEX_ENVIRONMENT);
102 if (!git_index_file) {
103 git_index_file = xmalloc(strlen(git_dir) + 7);
104 sprintf(git_index_file, "%s/index", git_dir);
105 }
106 git_graft_file = getenv(GRAFT_ENVIRONMENT);
107 if (!git_graft_file)
Alex Riesena4f34cb2008-10-27 11:22:09 +0100108 git_graft_file = git_pathdup("info/grafts");
Christian Couder6476b382009-11-18 07:50:58 +0100109 if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT))
110 read_replace_refs = 0;
Shawn O. Pearce0bee5912006-12-14 17:41:17 -0500111}
112
Junio C Hamano7d1864c2007-01-07 02:00:28 -0800113int is_bare_repository(void)
Shawn O. Pearce0bee5912006-12-14 17:41:17 -0500114{
Johannes Schindeline90fdc32007-08-01 01:30:14 +0100115 /* if core.bare is not 'false', let's see if there is a work tree */
116 return is_bare_repository_cfg && !get_git_work_tree();
Linus Torvaldse1b10392005-10-11 18:47:34 -0700117}
118
Dmitry Potapovd2b07082008-09-27 12:41:50 +0400119int have_git_dir(void)
120{
121 return !!git_dir;
122}
123
Pierre Habouzitc5fba162006-08-23 12:39:11 +0200124const char *get_git_dir(void)
Linus Torvaldse1b10392005-10-11 18:47:34 -0700125{
126 if (!git_dir)
127 setup_git_env();
128 return git_dir;
129}
130
Daniel Barkalow19757d82008-04-27 13:39:21 -0400131static int git_work_tree_initialized;
132
133/*
134 * Note. This works only before you used a work tree. This was added
135 * primarily to support git-clone to work in a new repository it just
136 * created, and is not meant to flip between different work trees.
137 */
138void set_git_work_tree(const char *new_work_tree)
139{
140 if (is_bare_repository_cfg >= 0)
141 die("cannot set work tree after initialization");
142 git_work_tree_initialized = 1;
143 free(work_tree);
144 work_tree = xstrdup(make_absolute_path(new_work_tree));
145 is_bare_repository_cfg = 0;
146}
147
Johannes Schindeline90fdc32007-08-01 01:30:14 +0100148const char *get_git_work_tree(void)
149{
Daniel Barkalow19757d82008-04-27 13:39:21 -0400150 if (!git_work_tree_initialized) {
Johannes Schindeline90fdc32007-08-01 01:30:14 +0100151 work_tree = getenv(GIT_WORK_TREE_ENVIRONMENT);
152 /* core.bare = true overrides implicit and config work tree */
153 if (!work_tree && is_bare_repository_cfg < 1) {
154 work_tree = git_work_tree_cfg;
155 /* make_absolute_path also normalizes the path */
156 if (work_tree && !is_absolute_path(work_tree))
Daniel Lowe9db56f72008-11-10 16:07:52 -0500157 work_tree = xstrdup(make_absolute_path(git_path("%s", work_tree)));
Johannes Schindeline90fdc32007-08-01 01:30:14 +0100158 } else if (work_tree)
159 work_tree = xstrdup(make_absolute_path(work_tree));
Daniel Barkalow19757d82008-04-27 13:39:21 -0400160 git_work_tree_initialized = 1;
Johannes Schindeline90fdc32007-08-01 01:30:14 +0100161 if (work_tree)
162 is_bare_repository_cfg = 0;
163 }
164 return work_tree;
165}
166
Linus Torvaldse1b10392005-10-11 18:47:34 -0700167char *get_object_directory(void)
168{
169 if (!git_object_dir)
170 setup_git_env();
171 return git_object_dir;
172}
173
Linus Torvaldse1b10392005-10-11 18:47:34 -0700174char *get_index_file(void)
175{
176 if (!git_index_file)
177 setup_git_env();
178 return git_index_file;
179}
180
181char *get_graft_file(void)
182{
183 if (!git_graft_file)
184 setup_git_env();
185 return git_graft_file;
186}
Johannes Schindelind7ac12b2007-08-01 01:29:38 +0100187
188int set_git_dir(const char *path)
189{
190 if (setenv(GIT_DIR_ENVIRONMENT, path, 1))
191 return error("Could not set GIT_DIR to '%s'", path);
192 setup_git_env();
193 return 0;
194}