Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 325 lines (290 sloc) 8.871 kB
e1b1039 Use git config file for committer name and email info
Linus Torvalds authored
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"
a1bea2c @joshtriplett ref namespaces: infrastructure
joshtriplett authored
11 #include "refs.h"
273c703 environment.c: Fix an sparse "symbol not declared" warning
Ramsay Jones authored
12 #include "fmt-merge-msg.h"
069c053 @pclouds add GIT_SHALLOW_FILE to propagate --shallow-file to subprocesses
pclouds authored
13 #include "commit.h"
e1b1039 Use git config file for committer name and email info
Linus Torvalds authored
14
15 int trust_executable_bit = 1;
1ce4790 @raalkml Make use of stat.ctime configurable
raalkml authored
16 int trust_ctime = 1;
c08e4d5 @robinrosenberg Enable minimal stat checking
robinrosenberg authored
17 int check_stat = 1;
78a8d64 Add core.symlinks to mark filesystems that do not support symbolic li…
Johannes Sixt authored
18 int has_symlinks = 1;
dce9648 @torvalds Make the default abbrev length configurable
torvalds authored
19 int minimum_abbrev = 4, default_abbrev = 7;
0a9b88b Add 'core.ignorecase' option
Linus Torvalds authored
20 int ignore_case;
96f1e58 remove unnecessary initializations
David Rientjes authored
21 int assume_unchanged;
22 int prefer_symlink_refs;
7d1864c Introduce is_bare_repository() and core.bare configuration variable
Junio C Hamano authored
23 int is_bare_repository_cfg = -1; /* unspecified */
510c5a8 Move initialization of log_all_ref_updates
Junio C Hamano authored
24 int log_all_ref_updates = -1; /* unspecified */
1b371f5 sha1_name: make core.warnambiguousrefs the default.
Junio C Hamano authored
25 int warn_ambiguous_refs = 1;
25fba78 @peff cat-file: disable object/refname ambiguity check for batch mode
peff authored
26 int warn_on_object_refname_ambiguity = 1;
49672f2 @peff refs: introduce a "ref paranoia" flag
peff authored
27 int ref_paranoia = -1;
96f1e58 remove unnecessary initializations
David Rientjes authored
28 int repository_format_version;
1a8f274 @spearce Correct new compiler warnings in builtin-revert
spearce authored
29 const char *git_commit_encoding;
3a55602 @spearce General const correctness fixes
spearce authored
30 const char *git_log_output_encoding;
94df250 shared repository: optionally allow reading to "others".
Junio C Hamano authored
31 int shared_repository = PERM_UMASK;
96f1e58 remove unnecessary initializations
David Rientjes authored
32 const char *apply_default_whitespace;
86c91f9 @Oblomov git apply: option to ignore whitespace differences
Oblomov authored
33 const char *apply_default_ignorewhitespace;
64589a0 @gitster attr: read core.attributesfile from git_default_core_config
gitster authored
34 const char *git_attributes_file;
960ccca Custom compression levels for objects and packs
Dana How authored
35 int zlib_compression_level = Z_BEST_SPEED;
36 int core_compression_level;
37 int core_compression_seen;
aafe9fb @torvalds Add config option to enable 'fsync()' of object files
torvalds authored
38 int fsync_object_files;
8c82534 @spearce Default core.packdGitWindowSize to 1 MiB if NO_MMAP.
spearce authored
39 size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE;
40 size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT;
4874f54 Bump core.deltaBaseCacheLimit to 96m
David Kastrup authored
41 size_t delta_base_cache_limit = 96 * 1024 * 1024;
1536628 @gitster Teach core.bigfilethreashold to pack-objects
gitster authored
42 unsigned long big_file_threshold = 512 * 1024 * 1024;
872da32 @chriscool Add "const" qualifier to "char *pager_program".
chriscool authored
43 const char *pager_program;
aa086eb @matled pager: config variable pager.color
matled authored
44 int pager_use_color = 1;
ee9601e @chriscool Add "const" qualifier to "char *editor_program".
chriscool authored
45 const char *editor_program;
d3e7da8 @akruis Add a new option 'core.askpass'.
akruis authored
46 const char *askpass_program;
dfb068b @chriscool Add "const" qualifier to "char *excludes_file".
chriscool authored
47 const char *excludes_file;
fd6cce9 @eyvind Add per-repository eol normalization
eyvind authored
48 enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;
afc711b @mhagger rename read_replace_refs to check_replace_refs
mhagger authored
49 int check_replace_refs = 1;
58d121b @glandium Allow to control where the replace refs are looked for
glandium authored
50 char *git_replace_ref_base;
ec70f52 @gitster convert: rename the "eol" global variable to "core_eol"
gitster authored
51 enum eol core_eol = EOL_UNSET;
21e5ad5 @sprohaska safecrlf: Add mechanism to warn about irreversible crlf conversions
sprohaska authored
52 enum safe_crlf safe_crlf = SAFE_CRLF_WARN;
cf1b786 @gitster Use gitattributes to define per-path whitespace rule
gitster authored
53 unsigned whitespace_rule_cfg = WS_DEFAULT_RULE;
9ed36cf @jaysoffian branch: optionally setup branch.*.merge from upstream local branches
jaysoffian authored
54 enum branch_track git_branch_track = BRANCH_TRACK_REMOTE;
c998ae9 @dustin Allow tracking branches to set up rebase by default.
dustin authored
55 enum rebase_setup_type autorebase = AUTOREBASE_NEVER;
f25950f @ctiwald push: Provide situational hints for non-fast-forward errors
ctiwald authored
56 enum push_default_type push_default = PUSH_DEFAULT_UNSPECIFIED;
348df16 @dscho Rename core.unreliableHardlinks to core.createObject
dscho authored
57 #ifndef OBJECT_CREATION_MODE
58 #define OBJECT_CREATION_MODE OBJECT_CREATION_USES_HARDLINKS
be66a6c @dscho Add an option not to use link(src, dest) && unlink(src) when that is …
dscho authored
59 #endif
348df16 @dscho Rename core.unreliableHardlinks to core.createObject
dscho authored
60 enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE;
a97a746 @dscho Introduce commit notes
dscho authored
61 char *notes_ref_name;
7f3140c @dscho git repack: keep commits hidden by a graft
dscho authored
62 int grafts_replace_parents = 1;
08aefc9 @pclouds unpack-trees(): "enable" sparse checkout and load $GIT_DIR/info/spars…
pclouds authored
63 int core_apply_sparse_checkout;
898eacd @gitster fmt-merge-msg: use branch.$name.description
gitster authored
64 int merge_log_config = -1;
76759c7 @tboegi git on Mac OS and precomposed unicode
tboegi authored
65 int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
e37c132 @pclouds git wrapper: introduce startup_info struct
pclouds authored
66 struct startup_info *startup_info;
568508e @gitster bulk-checkin: replace fast-import based implementation
gitster authored
67 unsigned long pack_size_limit_cfg;
e1b1039 Use git config file for committer name and email info
Linus Torvalds authored
68
a42643a @peff read-cache: optionally disallow HFS+ .git variants
peff authored
69 #ifndef PROTECT_HFS_DEFAULT
70 #define PROTECT_HFS_DEFAULT 0
71 #endif
72 int protect_hfs = PROTECT_HFS_DEFAULT;
73
2b4c6ef @dscho read-cache: optionally disallow NTFS .git variants
dscho authored
74 #ifndef PROTECT_NTFS_DEFAULT
75 #define PROTECT_NTFS_DEFAULT 0
76 #endif
77 int protect_ntfs = PROTECT_NTFS_DEFAULT;
78
eff80a9 @gitster Allow custom "comment char"
gitster authored
79 /*
80 * The character that begins a commented line in user-editable file
81 * that is subject to stripspace.
82 */
83 char comment_line_char = '#';
84c9dc2 @pclouds commit: allow core.commentChar=auto for character auto selection
pclouds authored
84 int auto_comment_line_char;
eff80a9 @gitster Allow custom "comment char"
gitster authored
85
671c9b7 @torvalds Add cache preload facility
torvalds authored
86 /* Parallel index stat data preload? */
299e298 @shoelzer environment.c: enable core.preloadindex by default
shoelzer authored
87 int core_preload_index = 1;
671c9b7 @torvalds Add cache preload facility
torvalds authored
88
e90fdc3 @dscho Clean up work-tree handling
dscho authored
89 /* This is set by setup_git_dir_gently() and/or git_default_config() */
90 char *git_work_tree_cfg;
19757d8 Add a function to set a non-default work tree
Daniel Barkalow authored
91 static char *work_tree;
e90fdc3 @dscho Clean up work-tree handling
dscho authored
92
a1bea2c @joshtriplett ref namespaces: infrastructure
joshtriplett authored
93 static const char *namespace;
94 static size_t namespace_len;
95
c7b3a3d @pclouds $GIT_COMMON_DIR: a new environment variable
pclouds authored
96 static const char *git_dir, *git_common_dir;
7f7868e @jrn environment.c: remove unused variable
jrn authored
97 static char *git_object_dir, *git_index_file, *git_graft_file;
c7b3a3d @pclouds $GIT_COMMON_DIR: a new environment variable
pclouds authored
98 int git_db_env, git_index_env, git_graft_env, git_common_dir_env;
c5fba16 @MadCoder git_dir holds pointers to local strings, hence MUST be const.
MadCoder authored
99
48a7c1c @Oblomov Refactor list of of repo-local env vars
Oblomov authored
100 /*
2163e5d @peff cache.h: drop LOCAL_REPO_ENV_SIZE
peff authored
101 * Repository-local GIT_* environment variables; see cache.h for details.
48a7c1c @Oblomov Refactor list of of repo-local env vars
Oblomov authored
102 */
2163e5d @peff cache.h: drop LOCAL_REPO_ENV_SIZE
peff authored
103 const char * const local_repo_env[] = {
48a7c1c @Oblomov Refactor list of of repo-local env vars
Oblomov authored
104 ALTERNATE_DB_ENVIRONMENT,
105 CONFIG_ENVIRONMENT,
655e8d9 @jrn do not pass "git -c foo=bar" params to transport helpers
jrn authored
106 CONFIG_DATA_ENVIRONMENT,
48a7c1c @Oblomov Refactor list of of repo-local env vars
Oblomov authored
107 DB_ENVIRONMENT,
108 GIT_DIR_ENVIRONMENT,
109 GIT_WORK_TREE_ENVIRONMENT,
2cd83d1 @peff setup: suppress implicit "." work-tree for bare repos
peff authored
110 GIT_IMPLICIT_WORK_TREE_ENVIRONMENT,
48a7c1c @Oblomov Refactor list of of repo-local env vars
Oblomov authored
111 GRAFT_ENVIRONMENT,
112 INDEX_ENVIRONMENT,
113 NO_REPLACE_OBJECTS_ENVIRONMENT,
58d121b @glandium Allow to control where the replace refs are looked for
glandium authored
114 GIT_REPLACE_REF_BASE_ENVIRONMENT,
a6f7f9a @peff environment: add GIT_PREFIX to local_repo_env
peff authored
115 GIT_PREFIX_ENVIRONMENT,
069c053 @pclouds add GIT_SHALLOW_FILE to propagate --shallow-file to subprocesses
pclouds authored
116 GIT_SHALLOW_FILE_ENVIRONMENT,
c7b3a3d @pclouds $GIT_COMMON_DIR: a new environment variable
pclouds authored
117 GIT_COMMON_DIR_ENVIRONMENT,
48a7c1c @Oblomov Refactor list of of repo-local env vars
Oblomov authored
118 NULL
119 };
120
a1bea2c @joshtriplett ref namespaces: infrastructure
joshtriplett authored
121 static char *expand_namespace(const char *raw_namespace)
122 {
123 struct strbuf buf = STRBUF_INIT;
124 struct strbuf **components, **c;
125
126 if (!raw_namespace || !*raw_namespace)
127 return xstrdup("");
128
129 strbuf_addstr(&buf, raw_namespace);
130 components = strbuf_split(&buf, '/');
131 strbuf_reset(&buf);
132 for (c = components; *c; c++)
133 if (strcmp((*c)->buf, "/") != 0)
134 strbuf_addf(&buf, "refs/namespaces/%s", (*c)->buf);
135 strbuf_list_free(components);
8d9c501 @mhagger Change check_ref_format() to take a flags argument
mhagger authored
136 if (check_refname_format(buf.buf, 0))
a1bea2c @joshtriplett ref namespaces: infrastructure
joshtriplett authored
137 die("bad git namespace path \"%s\"", raw_namespace);
138 strbuf_addch(&buf, '/');
139 return strbuf_detach(&buf, NULL);
140 }
141
c7b3a3d @pclouds $GIT_COMMON_DIR: a new environment variable
pclouds authored
142 static char *git_path_from_env(const char *envvar, const char *git_dir,
143 const char *path, int *fromenv)
cb6c38d @peff setup_git_env(): introduce git_path_from_env() helper
peff authored
144 {
145 const char *value = getenv(envvar);
557bd83 @pclouds git_path(): be aware of file relocation in $GIT_DIR
pclouds authored
146 if (!value) {
147 char *buf = xmalloc(strlen(git_dir) + strlen(path) + 2);
148 sprintf(buf, "%s/%s", git_dir, path);
149 return buf;
150 }
151 if (fromenv)
152 *fromenv = 1;
153 return xstrdup(value);
cb6c38d @peff setup_git_env(): introduce git_path_from_env() helper
peff authored
154 }
155
e1b1039 Use git config file for committer name and email info
Linus Torvalds authored
156 static void setup_git_env(void)
157 {
31e26eb @pclouds setup.c: support multi-checkout repo setup
pclouds authored
158 struct strbuf sb = STRBUF_INIT;
487a2b7 @pclouds Make setup_git_env() resolve .git file when $GIT_DIR is not specified
pclouds authored
159 const char *gitfile;
069c053 @pclouds add GIT_SHALLOW_FILE to propagate --shallow-file to subprocesses
pclouds authored
160 const char *shallow_file;
58d121b @glandium Allow to control where the replace refs are looked for
glandium authored
161 const char *replace_ref_base;
487a2b7 @pclouds Make setup_git_env() resolve .git file when $GIT_DIR is not specified
pclouds authored
162
e1b1039 Use git config file for committer name and email info
Linus Torvalds authored
163 git_dir = getenv(GIT_DIR_ENVIRONMENT);
164 if (!git_dir)
165 git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
487a2b7 @pclouds Make setup_git_env() resolve .git file when $GIT_DIR is not specified
pclouds authored
166 gitfile = read_gitfile(git_dir);
167 git_dir = xstrdup(gitfile ? gitfile : git_dir);
31e26eb @pclouds setup.c: support multi-checkout repo setup
pclouds authored
168 if (get_common_dir(&sb, git_dir))
c7b3a3d @pclouds $GIT_COMMON_DIR: a new environment variable
pclouds authored
169 git_common_dir_env = 1;
31e26eb @pclouds setup.c: support multi-checkout repo setup
pclouds authored
170 git_common_dir = strbuf_detach(&sb, NULL);
c7b3a3d @pclouds $GIT_COMMON_DIR: a new environment variable
pclouds authored
171 git_object_dir = git_path_from_env(DB_ENVIRONMENT, git_common_dir,
172 "objects", &git_db_env);
173 git_index_file = git_path_from_env(INDEX_ENVIRONMENT, git_dir,
174 "index", &git_index_env);
175 git_graft_file = git_path_from_env(GRAFT_ENVIRONMENT, git_common_dir,
176 "info/grafts", &git_graft_env);
6476b38 @chriscool replace: use a GIT_NO_REPLACE_OBJECTS env variable
chriscool authored
177 if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT))
afc711b @mhagger rename read_replace_refs to check_replace_refs
mhagger authored
178 check_replace_refs = 0;
58d121b @glandium Allow to control where the replace refs are looked for
glandium authored
179 replace_ref_base = getenv(GIT_REPLACE_REF_BASE_ENVIRONMENT);
180 git_replace_ref_base = xstrdup(replace_ref_base ? replace_ref_base
181 : "refs/replace/");
a1bea2c @joshtriplett ref namespaces: infrastructure
joshtriplett authored
182 namespace = expand_namespace(getenv(GIT_NAMESPACE_ENVIRONMENT));
183 namespace_len = strlen(namespace);
069c053 @pclouds add GIT_SHALLOW_FILE to propagate --shallow-file to subprocesses
pclouds authored
184 shallow_file = getenv(GIT_SHALLOW_FILE_ENVIRONMENT);
185 if (shallow_file)
186 set_alternate_shallow_file(shallow_file, 0);
0bee591 @spearce Enable reflogs by default in any repository with a working directory.
spearce authored
187 }
188
7d1864c Introduce is_bare_repository() and core.bare configuration variable
Junio C Hamano authored
189 int is_bare_repository(void)
0bee591 @spearce Enable reflogs by default in any repository with a working directory.
spearce authored
190 {
e90fdc3 @dscho Clean up work-tree handling
dscho authored
191 /* if core.bare is not 'false', let's see if there is a work tree */
192 return is_bare_repository_cfg && !get_git_work_tree();
e1b1039 Use git config file for committer name and email info
Linus Torvalds authored
193 }
194
c5fba16 @MadCoder git_dir holds pointers to local strings, hence MUST be const.
MadCoder authored
195 const char *get_git_dir(void)
e1b1039 Use git config file for committer name and email info
Linus Torvalds authored
196 {
197 if (!git_dir)
198 setup_git_env();
199 return git_dir;
200 }
201
c7b3a3d @pclouds $GIT_COMMON_DIR: a new environment variable
pclouds authored
202 const char *get_git_common_dir(void)
203 {
204 return git_common_dir;
205 }
206
a1bea2c @joshtriplett ref namespaces: infrastructure
joshtriplett authored
207 const char *get_git_namespace(void)
208 {
209 if (!namespace)
210 setup_git_env();
211 return namespace;
212 }
213
214 const char *strip_namespace(const char *namespaced_ref)
215 {
5955654 @chriscool replace {pre,suf}fixcmp() with {starts,ends}_with()
chriscool authored
216 if (!starts_with(namespaced_ref, get_git_namespace()))
a1bea2c @joshtriplett ref namespaces: infrastructure
joshtriplett authored
217 return NULL;
218 return namespaced_ref + namespace_len;
219 }
220
19757d8 Add a function to set a non-default work tree
Daniel Barkalow authored
221 static int git_work_tree_initialized;
222
223 /*
224 * Note. This works only before you used a work tree. This was added
225 * primarily to support git-clone to work in a new repository it just
226 * created, and is not meant to flip between different work trees.
227 */
228 void set_git_work_tree(const char *new_work_tree)
229 {
8351836 @pclouds Remove all logic from get_git_work_tree()
pclouds authored
230 if (git_work_tree_initialized) {
e2a57aa @carlosmn Name make_*_path functions more accurately
carlosmn authored
231 new_work_tree = real_path(new_work_tree);
8351836 @pclouds Remove all logic from get_git_work_tree()
pclouds authored
232 if (strcmp(new_work_tree, work_tree))
233 die("internal error: work tree has already been set\n"
234 "Current worktree: %s\nNew worktree: %s",
235 work_tree, new_work_tree);
236 return;
237 }
19757d8 Add a function to set a non-default work tree
Daniel Barkalow authored
238 git_work_tree_initialized = 1;
e2a57aa @carlosmn Name make_*_path functions more accurately
carlosmn authored
239 work_tree = xstrdup(real_path(new_work_tree));
d95138e @pclouds setup: set env $GIT_WORK_TREE when work tree is set, like $GIT_DIR
pclouds authored
240 if (setenv(GIT_WORK_TREE_ENVIRONMENT, work_tree, 1))
241 die("could not set GIT_WORK_TREE to '%s'", work_tree);
19757d8 Add a function to set a non-default work tree
Daniel Barkalow authored
242 }
243
e90fdc3 @dscho Clean up work-tree handling
dscho authored
244 const char *get_git_work_tree(void)
245 {
246 return work_tree;
247 }
248
e1b1039 Use git config file for committer name and email info
Linus Torvalds authored
249 char *get_object_directory(void)
250 {
251 if (!git_object_dir)
252 setup_git_env();
253 return git_object_dir;
254 }
255
463db9b @jrn wrapper: move odb_* to environment.c
jrn authored
256 int odb_mkstemp(char *template, size_t limit, const char *pattern)
257 {
258 int fd;
259 /*
260 * we let the umask do its job, don't try to be more
261 * restrictive except to remove write permission.
262 */
263 int mode = 0444;
264 snprintf(template, limit, "%s/%s",
265 get_object_directory(), pattern);
266 fd = git_mkstemp_mode(template, mode);
267 if (0 <= fd)
268 return fd;
269
270 /* slow path */
271 /* some mkstemp implementations erase template on failure */
272 snprintf(template, limit, "%s/%s",
273 get_object_directory(), pattern);
274 safe_create_leading_directories(template);
275 return xmkstemp_mode(template, mode);
276 }
277
8640d49 @pclouds environment.c: fix constness for odb_pack_keep()
pclouds authored
278 int odb_pack_keep(char *name, size_t namesz, const unsigned char *sha1)
463db9b @jrn wrapper: move odb_* to environment.c
jrn authored
279 {
280 int fd;
281
282 snprintf(name, namesz, "%s/pack/pack-%s.keep",
283 get_object_directory(), sha1_to_hex(sha1));
284 fd = open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
285 if (0 <= fd)
286 return fd;
287
288 /* slow path */
289 safe_create_leading_directories(name);
290 return open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
291 }
292
e1b1039 Use git config file for committer name and email info
Linus Torvalds authored
293 char *get_index_file(void)
294 {
295 if (!git_index_file)
296 setup_git_env();
297 return git_index_file;
298 }
299
300 char *get_graft_file(void)
301 {
302 if (!git_graft_file)
303 setup_git_env();
304 return git_graft_file;
305 }
d7ac12b @dscho Add set_git_dir() function
dscho authored
306
307 int set_git_dir(const char *path)
308 {
309 if (setenv(GIT_DIR_ENVIRONMENT, path, 1))
310 return error("Could not set GIT_DIR to '%s'", path);
311 setup_git_env();
312 return 0;
313 }
a6fa599 @patnotz commit: helper methods to reduce redundant blocks of code
patnotz authored
314
315 const char *get_log_output_encoding(void)
316 {
317 return git_log_output_encoding ? git_log_output_encoding
318 : get_commit_output_encoding();
319 }
320
321 const char *get_commit_output_encoding(void)
322 {
323 return git_commit_encoding ? git_commit_encoding : "UTF-8";
324 }
Something went wrong with that request. Please try again.