Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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