Linus Torvalds | e1b1039 | 2005-10-11 18:47:34 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 12 | char git_default_email[MAX_GITNAME]; |
| 13 | char git_default_name[MAX_GITNAME]; |
Santi Béjar | bb1ae3f | 2008-05-04 18:04:51 +0200 | [diff] [blame] | 14 | int user_ident_explicitly_given; |
Linus Torvalds | e1b1039 | 2005-10-11 18:47:34 -0700 | [diff] [blame] | 15 | int trust_executable_bit = 1; |
Alex Riesen | 1ce4790 | 2008-07-28 08:31:28 +0200 | [diff] [blame] | 16 | int trust_ctime = 1; |
Johannes Sixt | 78a8d64 | 2007-03-02 22:11:30 +0100 | [diff] [blame] | 17 | int has_symlinks = 1; |
Linus Torvalds | 0a9b88b | 2008-03-21 16:52:46 -0700 | [diff] [blame] | 18 | int ignore_case; |
David Rientjes | 96f1e58 | 2006-08-15 10:23:48 -0700 | [diff] [blame] | 19 | int assume_unchanged; |
| 20 | int prefer_symlink_refs; |
Junio C Hamano | 7d1864c | 2007-01-07 02:00:28 -0800 | [diff] [blame] | 21 | int is_bare_repository_cfg = -1; /* unspecified */ |
Junio C Hamano | 510c5a8 | 2007-01-07 01:35:34 -0800 | [diff] [blame] | 22 | int log_all_ref_updates = -1; /* unspecified */ |
Junio C Hamano | 1b371f5 | 2006-03-23 23:42:40 -0800 | [diff] [blame] | 23 | int warn_ambiguous_refs = 1; |
David Rientjes | 96f1e58 | 2006-08-15 10:23:48 -0700 | [diff] [blame] | 24 | int repository_format_version; |
Shawn O. Pearce | 1a8f274 | 2007-03-12 15:33:18 -0400 | [diff] [blame] | 25 | const char *git_commit_encoding; |
Shawn O. Pearce | 3a55602 | 2007-03-06 20:44:17 -0500 | [diff] [blame] | 26 | const char *git_log_output_encoding; |
Junio C Hamano | 94df250 | 2006-06-09 23:09:49 -0700 | [diff] [blame] | 27 | int shared_repository = PERM_UMASK; |
David Rientjes | 96f1e58 | 2006-08-15 10:23:48 -0700 | [diff] [blame] | 28 | const char *apply_default_whitespace; |
Giuseppe Bilotta | 86c91f9 | 2009-08-04 13:16:49 +0200 | [diff] [blame] | 29 | const char *apply_default_ignorewhitespace; |
Dana How | 960ccca | 2007-05-09 13:56:50 -0700 | [diff] [blame] | 30 | int zlib_compression_level = Z_BEST_SPEED; |
| 31 | int core_compression_level; |
| 32 | int core_compression_seen; |
Linus Torvalds | aafe9fb | 2008-06-18 15:18:44 -0700 | [diff] [blame] | 33 | int fsync_object_files; |
Shawn O. Pearce | 8c82534 | 2006-12-24 00:46:13 -0500 | [diff] [blame] | 34 | size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE; |
| 35 | size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT; |
Shawn O. Pearce | 18bdec1 | 2007-03-19 01:14:37 -0400 | [diff] [blame] | 36 | size_t delta_base_cache_limit = 16 * 1024 * 1024; |
Christian Couder | 872da32 | 2008-02-16 06:01:11 +0100 | [diff] [blame] | 37 | const char *pager_program; |
Matthias Lederhofer | aa086eb | 2006-07-30 00:27:43 +0200 | [diff] [blame] | 38 | int pager_use_color = 1; |
Christian Couder | ee9601e | 2008-02-16 06:01:41 +0100 | [diff] [blame] | 39 | const char *editor_program; |
Anselm Kruis | d3e7da8 | 2010-08-30 15:38:38 +0200 | [diff] [blame] | 40 | const char *askpass_program; |
Christian Couder | dfb068b | 2008-02-16 06:01:59 +0100 | [diff] [blame] | 41 | const char *excludes_file; |
Eyvind Bernhardsen | fd6cce9 | 2010-05-19 22:43:10 +0200 | [diff] [blame] | 42 | enum auto_crlf auto_crlf = AUTO_CRLF_FALSE; |
Christian Couder | dae556b | 2009-01-23 10:07:46 +0100 | [diff] [blame] | 43 | int read_replace_refs = 1; |
Eyvind Bernhardsen | 942e774 | 2010-06-04 21:29:08 +0200 | [diff] [blame] | 44 | enum eol eol = EOL_UNSET; |
Steffen Prohaska | 21e5ad5 | 2008-02-06 12:25:58 +0100 | [diff] [blame] | 45 | enum safe_crlf safe_crlf = SAFE_CRLF_WARN; |
Junio C Hamano | cf1b786 | 2007-12-06 00:14:14 -0800 | [diff] [blame] | 46 | unsigned whitespace_rule_cfg = WS_DEFAULT_RULE; |
Jay Soffian | 9ed36cf | 2008-02-19 11:24:37 -0500 | [diff] [blame] | 47 | enum branch_track git_branch_track = BRANCH_TRACK_REMOTE; |
Dustin Sallings | c998ae9 | 2008-05-10 15:36:29 -0700 | [diff] [blame] | 48 | enum rebase_setup_type autorebase = AUTOREBASE_NEVER; |
Junio C Hamano | bba0fd2 | 2009-07-18 17:19:47 -0700 | [diff] [blame] | 49 | enum push_default_type push_default = PUSH_DEFAULT_MATCHING; |
Johannes Schindelin | 348df16 | 2009-04-28 00:32:25 +0200 | [diff] [blame] | 50 | #ifndef OBJECT_CREATION_MODE |
| 51 | #define OBJECT_CREATION_MODE OBJECT_CREATION_USES_HARDLINKS |
Johannes Schindelin | be66a6c | 2009-04-25 11:57:14 +0200 | [diff] [blame] | 52 | #endif |
Johannes Schindelin | 348df16 | 2009-04-28 00:32:25 +0200 | [diff] [blame] | 53 | enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE; |
Johannes Schindelin | a97a746 | 2009-10-09 12:21:57 +0200 | [diff] [blame] | 54 | char *notes_ref_name; |
Johannes Schindelin | 7f3140c | 2009-07-23 17:33:49 +0200 | [diff] [blame] | 55 | int grafts_replace_parents = 1; |
Nguyễn Thái Ngọc Duy | 08aefc9 | 2009-08-20 20:47:08 +0700 | [diff] [blame] | 56 | int core_apply_sparse_checkout; |
Nguyễn Thái Ngọc Duy | e37c132 | 2010-08-05 21:40:35 -0500 | [diff] [blame] | 57 | struct startup_info *startup_info; |
Linus Torvalds | e1b1039 | 2005-10-11 18:47:34 -0700 | [diff] [blame] | 58 | |
Linus Torvalds | 671c9b7 | 2008-11-13 16:36:30 -0800 | [diff] [blame] | 59 | /* Parallel index stat data preload? */ |
| 60 | int core_preload_index = 0; |
| 61 | |
Johannes Schindelin | e90fdc3 | 2007-08-01 01:30:14 +0100 | [diff] [blame] | 62 | /* This is set by setup_git_dir_gently() and/or git_default_config() */ |
| 63 | char *git_work_tree_cfg; |
Daniel Barkalow | 19757d8 | 2008-04-27 13:39:21 -0400 | [diff] [blame] | 64 | static char *work_tree; |
Johannes Schindelin | e90fdc3 | 2007-08-01 01:30:14 +0100 | [diff] [blame] | 65 | |
Pierre Habouzit | c5fba16 | 2006-08-23 12:39:11 +0200 | [diff] [blame] | 66 | static const char *git_dir; |
| 67 | static char *git_object_dir, *git_index_file, *git_refs_dir, *git_graft_file; |
| 68 | |
Giuseppe Bilotta | 48a7c1c | 2010-02-25 00:34:14 +0100 | [diff] [blame] | 69 | /* |
| 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 | */ |
| 74 | const char * const local_repo_env[LOCAL_REPO_ENV_SIZE + 1] = { |
| 75 | ALTERNATE_DB_ENVIRONMENT, |
| 76 | CONFIG_ENVIRONMENT, |
Jonathan Nieder | 655e8d9 | 2010-08-24 01:41:14 -0500 | [diff] [blame] | 77 | CONFIG_DATA_ENVIRONMENT, |
Giuseppe Bilotta | 48a7c1c | 2010-02-25 00:34:14 +0100 | [diff] [blame] | 78 | 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 Torvalds | e1b1039 | 2005-10-11 18:47:34 -0700 | [diff] [blame] | 87 | static void setup_git_env(void) |
| 88 | { |
| 89 | git_dir = getenv(GIT_DIR_ENVIRONMENT); |
| 90 | if (!git_dir) |
Lars Hjemli | b44ebb1 | 2008-02-20 23:13:13 +0100 | [diff] [blame] | 91 | git_dir = read_gitfile_gently(DEFAULT_GIT_DIR_ENVIRONMENT); |
| 92 | if (!git_dir) |
Linus Torvalds | e1b1039 | 2005-10-11 18:47:34 -0700 | [diff] [blame] | 93 | 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 Riesen | a4f34cb | 2008-10-27 11:22:09 +0100 | [diff] [blame] | 108 | git_graft_file = git_pathdup("info/grafts"); |
Christian Couder | 6476b38 | 2009-11-18 07:50:58 +0100 | [diff] [blame] | 109 | if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT)) |
| 110 | read_replace_refs = 0; |
Shawn O. Pearce | 0bee591 | 2006-12-14 17:41:17 -0500 | [diff] [blame] | 111 | } |
| 112 | |
Junio C Hamano | 7d1864c | 2007-01-07 02:00:28 -0800 | [diff] [blame] | 113 | int is_bare_repository(void) |
Shawn O. Pearce | 0bee591 | 2006-12-14 17:41:17 -0500 | [diff] [blame] | 114 | { |
Johannes Schindelin | e90fdc3 | 2007-08-01 01:30:14 +0100 | [diff] [blame] | 115 | /* 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 Torvalds | e1b1039 | 2005-10-11 18:47:34 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Dmitry Potapov | d2b0708 | 2008-09-27 12:41:50 +0400 | [diff] [blame] | 119 | int have_git_dir(void) |
| 120 | { |
| 121 | return !!git_dir; |
| 122 | } |
| 123 | |
Pierre Habouzit | c5fba16 | 2006-08-23 12:39:11 +0200 | [diff] [blame] | 124 | const char *get_git_dir(void) |
Linus Torvalds | e1b1039 | 2005-10-11 18:47:34 -0700 | [diff] [blame] | 125 | { |
| 126 | if (!git_dir) |
| 127 | setup_git_env(); |
| 128 | return git_dir; |
| 129 | } |
| 130 | |
Daniel Barkalow | 19757d8 | 2008-04-27 13:39:21 -0400 | [diff] [blame] | 131 | static 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 | */ |
| 138 | void 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 Schindelin | e90fdc3 | 2007-08-01 01:30:14 +0100 | [diff] [blame] | 148 | const char *get_git_work_tree(void) |
| 149 | { |
Daniel Barkalow | 19757d8 | 2008-04-27 13:39:21 -0400 | [diff] [blame] | 150 | if (!git_work_tree_initialized) { |
Johannes Schindelin | e90fdc3 | 2007-08-01 01:30:14 +0100 | [diff] [blame] | 151 | 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 Lowe | 9db56f7 | 2008-11-10 16:07:52 -0500 | [diff] [blame] | 157 | work_tree = xstrdup(make_absolute_path(git_path("%s", work_tree))); |
Johannes Schindelin | e90fdc3 | 2007-08-01 01:30:14 +0100 | [diff] [blame] | 158 | } else if (work_tree) |
| 159 | work_tree = xstrdup(make_absolute_path(work_tree)); |
Daniel Barkalow | 19757d8 | 2008-04-27 13:39:21 -0400 | [diff] [blame] | 160 | git_work_tree_initialized = 1; |
Johannes Schindelin | e90fdc3 | 2007-08-01 01:30:14 +0100 | [diff] [blame] | 161 | if (work_tree) |
| 162 | is_bare_repository_cfg = 0; |
| 163 | } |
| 164 | return work_tree; |
| 165 | } |
| 166 | |
Linus Torvalds | e1b1039 | 2005-10-11 18:47:34 -0700 | [diff] [blame] | 167 | char *get_object_directory(void) |
| 168 | { |
| 169 | if (!git_object_dir) |
| 170 | setup_git_env(); |
| 171 | return git_object_dir; |
| 172 | } |
| 173 | |
Linus Torvalds | e1b1039 | 2005-10-11 18:47:34 -0700 | [diff] [blame] | 174 | char *get_index_file(void) |
| 175 | { |
| 176 | if (!git_index_file) |
| 177 | setup_git_env(); |
| 178 | return git_index_file; |
| 179 | } |
| 180 | |
| 181 | char *get_graft_file(void) |
| 182 | { |
| 183 | if (!git_graft_file) |
| 184 | setup_git_env(); |
| 185 | return git_graft_file; |
| 186 | } |
Johannes Schindelin | d7ac12b | 2007-08-01 01:29:38 +0100 | [diff] [blame] | 187 | |
| 188 | int 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 | } |