Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 196 lines (179 sloc) 5.462 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"
11
12 char git_default_email[MAX_GITNAME];
13 char git_default_name[MAX_GITNAME];
bb1ae3f commit: Show committer if automatic
Santi Béjar authored
14 int user_ident_explicitly_given;
e1b1039 Use git config file for committer name and email info
Linus Torvalds authored
15 int trust_executable_bit = 1;
1ce4790 @raalkml Make use of stat.ctime configurable
raalkml authored
16 int trust_ctime = 1;
78a8d64 Add core.symlinks to mark filesystems that do not support symbolic li…
Johannes Sixt authored
17 int has_symlinks = 1;
0a9b88b Add 'core.ignorecase' option
Linus Torvalds authored
18 int ignore_case;
96f1e58 remove unnecessary initializations
David Rientjes authored
19 int assume_unchanged;
20 int prefer_symlink_refs;
7d1864c Introduce is_bare_repository() and core.bare configuration variable
Junio C Hamano authored
21 int is_bare_repository_cfg = -1; /* unspecified */
510c5a8 Move initialization of log_all_ref_updates
Junio C Hamano authored
22 int log_all_ref_updates = -1; /* unspecified */
1b371f5 sha1_name: make core.warnambiguousrefs the default.
Junio C Hamano authored
23 int warn_ambiguous_refs = 1;
96f1e58 remove unnecessary initializations
David Rientjes authored
24 int repository_format_version;
1a8f274 @spearce Correct new compiler warnings in builtin-revert
spearce authored
25 const char *git_commit_encoding;
3a55602 @spearce General const correctness fixes
spearce authored
26 const char *git_log_output_encoding;
94df250 shared repository: optionally allow reading to "others".
Junio C Hamano authored
27 int shared_repository = PERM_UMASK;
96f1e58 remove unnecessary initializations
David Rientjes authored
28 const char *apply_default_whitespace;
86c91f9 @Oblomov git apply: option to ignore whitespace differences
Oblomov authored
29 const char *apply_default_ignorewhitespace;
960ccca Custom compression levels for objects and packs
Dana How authored
30 int zlib_compression_level = Z_BEST_SPEED;
31 int core_compression_level;
32 int core_compression_seen;
aafe9fb @torvalds Add config option to enable 'fsync()' of object files
torvalds authored
33 int fsync_object_files;
8c82534 @spearce Default core.packdGitWindowSize to 1 MiB if NO_MMAP.
spearce authored
34 size_t packed_git_window_size = DEFAULT_PACKED_GIT_WINDOW_SIZE;
35 size_t packed_git_limit = DEFAULT_PACKED_GIT_LIMIT;
18bdec1 @spearce Limit the size of the new delta_base_cache
spearce authored
36 size_t delta_base_cache_limit = 16 * 1024 * 1024;
872da32 @chriscool Add "const" qualifier to "char *pager_program".
chriscool authored
37 const char *pager_program;
aa086eb @matled pager: config variable pager.color
matled authored
38 int pager_use_color = 1;
ee9601e @chriscool Add "const" qualifier to "char *editor_program".
chriscool authored
39 const char *editor_program;
d3e7da8 @akruis Add a new option 'core.askpass'.
akruis authored
40 const char *askpass_program;
dfb068b @chriscool Add "const" qualifier to "char *excludes_file".
chriscool authored
41 const char *excludes_file;
fd6cce9 @eyvind Add per-repository eol normalization
eyvind authored
42 enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;
dae556b @chriscool environment: add global variable to disable replacement
chriscool authored
43 int read_replace_refs = 1;
942e774 @eyvind Add "core.eol" config variable
eyvind authored
44 enum eol eol = EOL_UNSET;
21e5ad5 @sprohaska safecrlf: Add mechanism to warn about irreversible crlf conversions
sprohaska authored
45 enum safe_crlf safe_crlf = SAFE_CRLF_WARN;
cf1b786 @gitster Use gitattributes to define per-path whitespace rule
gitster authored
46 unsigned whitespace_rule_cfg = WS_DEFAULT_RULE;
9ed36cf @jaysoffian branch: optionally setup branch.*.merge from upstream local branches
jaysoffian authored
47 enum branch_track git_branch_track = BRANCH_TRACK_REMOTE;
c998ae9 @dustin Allow tracking branches to set up rebase by default.
dustin authored
48 enum rebase_setup_type autorebase = AUTOREBASE_NEVER;
bba0fd2 @gitster push: do not give big warning when no preference is configured
gitster authored
49 enum push_default_type push_default = PUSH_DEFAULT_MATCHING;
348df16 @dscho Rename core.unreliableHardlinks to core.createObject
dscho authored
50 #ifndef OBJECT_CREATION_MODE
51 #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
52 #endif
348df16 @dscho Rename core.unreliableHardlinks to core.createObject
dscho authored
53 enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE;
a97a746 @dscho Introduce commit notes
dscho authored
54 char *notes_ref_name;
7f3140c @dscho git repack: keep commits hidden by a graft
dscho authored
55 int grafts_replace_parents = 1;
08aefc9 @pclouds unpack-trees(): "enable" sparse checkout and load $GIT_DIR/info/spars…
pclouds authored
56 int core_apply_sparse_checkout;
e37c132 @pclouds git wrapper: introduce startup_info struct
pclouds authored
57 struct startup_info *startup_info;
e1b1039 Use git config file for committer name and email info
Linus Torvalds authored
58
671c9b7 @torvalds Add cache preload facility
torvalds authored
59 /* Parallel index stat data preload? */
60 int core_preload_index = 0;
61
e90fdc3 @dscho Clean up work-tree handling
dscho authored
62 /* This is set by setup_git_dir_gently() and/or git_default_config() */
63 char *git_work_tree_cfg;
19757d8 Add a function to set a non-default work tree
Daniel Barkalow authored
64 static char *work_tree;
e90fdc3 @dscho Clean up work-tree handling
dscho authored
65
c5fba16 @MadCoder git_dir holds pointers to local strings, hence MUST be const.
MadCoder authored
66 static const char *git_dir;
7f7868e @jrn environment.c: remove unused variable
jrn authored
67 static char *git_object_dir, *git_index_file, *git_graft_file;
c5fba16 @MadCoder git_dir holds pointers to local strings, hence MUST be const.
MadCoder authored
68
48a7c1c @Oblomov Refactor list of of repo-local env vars
Oblomov authored
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,
655e8d9 @jrn do not pass "git -c foo=bar" params to transport helpers
jrn authored
77 CONFIG_DATA_ENVIRONMENT,
48a7c1c @Oblomov Refactor list of of repo-local env vars
Oblomov authored
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
e1b1039 Use git config file for committer name and email info
Linus Torvalds authored
87 static void setup_git_env(void)
88 {
89 git_dir = getenv(GIT_DIR_ENVIRONMENT);
15431ca setup: make sure git_dir path is in a permanent buffer, getenv(3) case
Kirill Smelkov authored
90 git_dir = git_dir ? xstrdup(git_dir) : NULL;
06f3549 @jrn setup: make sure git dir path is in a permanent buffer
jrn authored
91 if (!git_dir) {
b44ebb1 @hjemli Add platform-independent .git "symlink"
hjemli authored
92 git_dir = read_gitfile_gently(DEFAULT_GIT_DIR_ENVIRONMENT);
06f3549 @jrn setup: make sure git dir path is in a permanent buffer
jrn authored
93 git_dir = git_dir ? xstrdup(git_dir) : NULL;
94 }
e1b1039 Use git config file for committer name and email info
Linus Torvalds authored
95 if (!git_dir)
96 git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
97 git_object_dir = getenv(DB_ENVIRONMENT);
98 if (!git_object_dir) {
99 git_object_dir = xmalloc(strlen(git_dir) + 9);
100 sprintf(git_object_dir, "%s/objects", git_dir);
101 }
102 git_index_file = getenv(INDEX_ENVIRONMENT);
103 if (!git_index_file) {
104 git_index_file = xmalloc(strlen(git_dir) + 7);
105 sprintf(git_index_file, "%s/index", git_dir);
106 }
107 git_graft_file = getenv(GRAFT_ENVIRONMENT);
108 if (!git_graft_file)
a4f34cb @raalkml Use git_pathdup instead of xstrdup(git_path(...))
raalkml authored
109 git_graft_file = git_pathdup("info/grafts");
6476b38 @chriscool replace: use a GIT_NO_REPLACE_OBJECTS env variable
chriscool authored
110 if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT))
111 read_replace_refs = 0;
0bee591 @spearce Enable reflogs by default in any repository with a working directory.
spearce authored
112 }
113
7d1864c Introduce is_bare_repository() and core.bare configuration variable
Junio C Hamano authored
114 int is_bare_repository(void)
0bee591 @spearce Enable reflogs by default in any repository with a working directory.
spearce authored
115 {
e90fdc3 @dscho Clean up work-tree handling
dscho authored
116 /* if core.bare is not 'false', let's see if there is a work tree */
117 return is_bare_repository_cfg && !get_git_work_tree();
e1b1039 Use git config file for committer name and email info
Linus Torvalds authored
118 }
119
d2b0708 @dmpot add have_git_dir() function
dmpot authored
120 int have_git_dir(void)
121 {
122 return !!git_dir;
123 }
124
c5fba16 @MadCoder git_dir holds pointers to local strings, hence MUST be const.
MadCoder authored
125 const char *get_git_dir(void)
e1b1039 Use git config file for committer name and email info
Linus Torvalds authored
126 {
127 if (!git_dir)
128 setup_git_env();
129 return git_dir;
130 }
131
19757d8 Add a function to set a non-default work tree
Daniel Barkalow authored
132 static int git_work_tree_initialized;
133
134 /*
135 * Note. This works only before you used a work tree. This was added
136 * primarily to support git-clone to work in a new repository it just
137 * created, and is not meant to flip between different work trees.
138 */
139 void set_git_work_tree(const char *new_work_tree)
140 {
141 if (is_bare_repository_cfg >= 0)
142 die("cannot set work tree after initialization");
143 git_work_tree_initialized = 1;
144 free(work_tree);
145 work_tree = xstrdup(make_absolute_path(new_work_tree));
146 is_bare_repository_cfg = 0;
147 }
148
e90fdc3 @dscho Clean up work-tree handling
dscho authored
149 const char *get_git_work_tree(void)
150 {
19757d8 Add a function to set a non-default work tree
Daniel Barkalow authored
151 if (!git_work_tree_initialized) {
e90fdc3 @dscho Clean up work-tree handling
dscho authored
152 work_tree = getenv(GIT_WORK_TREE_ENVIRONMENT);
153 /* core.bare = true overrides implicit and config work tree */
154 if (!work_tree && is_bare_repository_cfg < 1) {
155 work_tree = git_work_tree_cfg;
156 /* make_absolute_path also normalizes the path */
157 if (work_tree && !is_absolute_path(work_tree))
9db56f7 @dlowe-net Fix non-literal format in printf-style calls
dlowe-net authored
158 work_tree = xstrdup(make_absolute_path(git_path("%s", work_tree)));
e90fdc3 @dscho Clean up work-tree handling
dscho authored
159 } else if (work_tree)
160 work_tree = xstrdup(make_absolute_path(work_tree));
19757d8 Add a function to set a non-default work tree
Daniel Barkalow authored
161 git_work_tree_initialized = 1;
e90fdc3 @dscho Clean up work-tree handling
dscho authored
162 if (work_tree)
163 is_bare_repository_cfg = 0;
164 }
165 return work_tree;
166 }
167
e1b1039 Use git config file for committer name and email info
Linus Torvalds authored
168 char *get_object_directory(void)
169 {
170 if (!git_object_dir)
171 setup_git_env();
172 return git_object_dir;
173 }
174
175 char *get_index_file(void)
176 {
177 if (!git_index_file)
178 setup_git_env();
179 return git_index_file;
180 }
181
182 char *get_graft_file(void)
183 {
184 if (!git_graft_file)
185 setup_git_env();
186 return git_graft_file;
187 }
d7ac12b @dscho Add set_git_dir() function
dscho authored
188
189 int set_git_dir(const char *path)
190 {
191 if (setenv(GIT_DIR_ENVIRONMENT, path, 1))
192 return error("Could not set GIT_DIR to '%s'", path);
193 setup_git_env();
194 return 0;
195 }
Something went wrong with that request. Please try again.