]> git.ipfire.org Git - thirdparty/git.git/blame - environment.c
The sixth batch
[thirdparty/git.git] / environment.c
CommitLineData
e1b10391
LT
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 */
e7da9385
PS
10
11#define USE_THE_REPOSITORY_VARIABLE
12
5e3f94df 13#include "git-compat-util.h"
0b027f6c 14#include "abspath.h"
e730b81d 15#include "branch.h"
73359a9b 16#include "convert.h"
b9d147fb 17#include "environment.h"
f394e093 18#include "gettext.h"
41f1a843 19#include "git-zlib.h"
c14c234f 20#include "repository.h"
b2141fc1 21#include "config.h"
a1bea2c1 22#include "refs.h"
273c7032 23#include "fmt-merge-msg.h"
069c0532 24#include "commit.h"
dbbcd44f 25#include "strvec.h"
c339932b 26#include "path.h"
8500e0de 27#include "chdir-notify.h"
e38da487 28#include "setup.h"
d48be35c 29#include "write-or-die.h"
e1b10391 30
e1b10391 31int trust_executable_bit = 1;
1ce4790b 32int trust_ctime = 1;
c08e4d5b 33int check_stat = 1;
78a8d641 34int has_symlinks = 1;
e6c587c7 35int minimum_abbrev = 4, default_abbrev = -1;
0a9b88b7 36int ignore_case;
96f1e58f 37int assume_unchanged;
7d1864ce 38int is_bare_repository_cfg = -1; /* unspecified */
25fba78d 39int warn_on_object_refname_ambiguity = 1;
067fbd41 40int repository_format_precious_objects;
1b261c20
PS
41char *git_commit_encoding;
42char *git_log_output_encoding;
9a53219f
JK
43char *apply_default_whitespace;
44char *apply_default_ignorewhitespace;
6073b3b5 45char *git_attributes_file;
960ccca6 46int zlib_compression_level = Z_BEST_SPEED;
8de7eeb5 47int pack_compression_level = Z_DEFAULT_COMPRESSION;
844a8ad4 48int fsync_object_files = -1;
412e4cae 49int use_fsync = -1;
abf38abe 50enum fsync_method fsync_method = FSYNC_METHOD_DEFAULT;
020406ea 51enum fsync_component fsync_components = FSYNC_COMPONENTS_DEFAULT;
1b261c20
PS
52char *editor_program;
53char *askpass_program;
6073b3b5 54char *excludes_file;
fd6cce9e 55enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;
ec70f52f 56enum eol core_eol = EOL_UNSET;
8462ff43 57int global_conv_flags_eol = CONV_EOL_RNDTRP_WARN;
a6cb0cc6 58char *check_roundtrip_encoding;
9ed36cfa 59enum branch_track git_branch_track = BRANCH_TRACK_REMOTE;
c998ae9b 60enum rebase_setup_type autorebase = AUTOREBASE_NEVER;
f25950f3 61enum push_default_type push_default = PUSH_DEFAULT_UNSPECIFIED;
348df166
JS
62#ifndef OBJECT_CREATION_MODE
63#define OBJECT_CREATION_MODE OBJECT_CREATION_USES_HARDLINKS
be66a6c4 64#endif
348df166 65enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE;
3a5f3087 66int grafts_keep_true_parents;
08aefc9e 67int core_apply_sparse_checkout;
879321eb 68int core_sparse_checkout_cone;
ecc7c884 69int sparse_expect_files_outside_of_patterns;
898eacd8 70int merge_log_config = -1;
76759c7d 71int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
568508e7 72unsigned long pack_size_limit_cfg;
b64d78ad
JS
73int max_allowed_tree_depth =
74#ifdef _MSC_VER
75 /*
76 * When traversing into too-deep trees, Visual C-compiled Git seems to
77 * run into some internal stack overflow detection in the
78 * `RtlpAllocateHeap()` function that is called from within
79 * `git_inflate_init()`'s call tree. The following value seems to be
80 * low enough to avoid that by letting Git exit with an error before
81 * the stack overflow can occur.
82 */
83 512;
436a4221
JS
84#elif defined(GIT_WINDOWS_NATIVE) && defined(__clang__) && defined(__aarch64__)
85 /*
86 * Similar to Visual C, it seems that on Windows/ARM64 the clang-based
87 * builds have a smaller stack space available. When running out of
88 * that stack space, a `STATUS_STACK_OVERFLOW` is produced. When the
89 * Git command was run from an MSYS2 Bash, this unfortunately results
90 * in an exit code 127. Let's prevent that by lowering the maximal
91 * tree depth; This value seems to be low enough.
92 */
93 1280;
b64d78ad
JS
94#else
95 2048;
96#endif
e1b10391 97
a42643aa
JK
98#ifndef PROTECT_HFS_DEFAULT
99#define PROTECT_HFS_DEFAULT 0
100#endif
101int protect_hfs = PROTECT_HFS_DEFAULT;
102
2b4c6efc 103#ifndef PROTECT_NTFS_DEFAULT
9102f958 104#define PROTECT_NTFS_DEFAULT 1
2b4c6efc
JS
105#endif
106int protect_ntfs = PROTECT_NTFS_DEFAULT;
107
eff80a9f
JH
108/*
109 * The character that begins a commented line in user-editable file
110 * that is subject to stripspace.
111 */
72a7d5d9 112const char *comment_line_str = "#";
648abbe2 113char *comment_line_str_to_free;
84c9dc2c 114int auto_comment_line_char;
eff80a9f 115
ff4a7493 116/* This is set by setup_git_directory_gently() and/or git_default_config() */
e90fdc39 117char *git_work_tree_cfg;
e90fdc39 118
48a7c1c4 119/*
bc5c5ec0 120 * Repository-local GIT_* environment variables; see environment.h for details.
48a7c1c4 121 */
2163e5db 122const char * const local_repo_env[] = {
48a7c1c4
GB
123 ALTERNATE_DB_ENVIRONMENT,
124 CONFIG_ENVIRONMENT,
655e8d9c 125 CONFIG_DATA_ENVIRONMENT,
d8d77153 126 CONFIG_COUNT_ENVIRONMENT,
48a7c1c4
GB
127 DB_ENVIRONMENT,
128 GIT_DIR_ENVIRONMENT,
129 GIT_WORK_TREE_ENVIRONMENT,
2cd83d10 130 GIT_IMPLICIT_WORK_TREE_ENVIRONMENT,
48a7c1c4
GB
131 GRAFT_ENVIRONMENT,
132 INDEX_ENVIRONMENT,
133 NO_REPLACE_OBJECTS_ENVIRONMENT,
58d121b2 134 GIT_REPLACE_REF_BASE_ENVIRONMENT,
a6f7f9a3 135 GIT_PREFIX_ENVIRONMENT,
069c0532 136 GIT_SHALLOW_FILE_ENVIRONMENT,
c7b3a3d2 137 GIT_COMMON_DIR_ENVIRONMENT,
48a7c1c4
GB
138 NULL
139};
140
b9d147fb 141const char *getenv_safe(struct strvec *argv, const char *name)
357a03eb
NTND
142{
143 const char *value = getenv(name);
144
145 if (!value)
146 return NULL;
147
ef8d7ac4 148 strvec_push(argv, value);
d70a9eb6 149 return argv->v[argv->nr - 1];
357a03eb
NTND
150}
151
7d1864ce 152int is_bare_repository(void)
0bee5918 153{
e90fdc39 154 /* if core.bare is not 'false', let's see if there is a work tree */
edc2c926 155 return is_bare_repository_cfg && !repo_get_work_tree(the_repository);
e1b10391
LT
156}
157
b9605bc4
JK
158int have_git_dir(void)
159{
160 return startup_info->have_repository
c14c234f 161 || the_repository->gitdir;
b9605bc4
JK
162}
163
a1bea2c1
JT
164const char *get_git_namespace(void)
165{
c22d183b
PS
166 static const char *namespace;
167
168 struct strbuf buf = STRBUF_INIT;
169 struct strbuf **components, **c;
170 const char *raw_namespace;
171
172 if (namespace)
173 return namespace;
174
175 raw_namespace = getenv(GIT_NAMESPACE_ENVIRONMENT);
176 if (!raw_namespace || !*raw_namespace) {
177 namespace = "";
178 return namespace;
179 }
180
181 strbuf_addstr(&buf, raw_namespace);
182 components = strbuf_split(&buf, '/');
183 strbuf_reset(&buf);
184 for (c = components; *c; c++)
185 if (strcmp((*c)->buf, "/") != 0)
186 strbuf_addf(&buf, "refs/namespaces/%s", (*c)->buf);
187 strbuf_list_free(components);
188 if (check_refname_format(buf.buf, 0))
189 die(_("bad git namespace path \"%s\""), raw_namespace);
190 strbuf_addch(&buf, '/');
191
192 namespace = strbuf_detach(&buf, NULL);
193
194 return namespace;
a1bea2c1
JT
195}
196
197const char *strip_namespace(const char *namespaced_ref)
198{
bf08c8cf
BW
199 const char *out;
200 if (skip_prefix(namespaced_ref, get_git_namespace(), &out))
201 return out;
202 return NULL;
a1bea2c1
JT
203}
204
a6fa5992
PN
205const char *get_log_output_encoding(void)
206{
207 return git_log_output_encoding ? git_log_output_encoding
208 : get_commit_output_encoding();
209}
210
211const char *get_commit_output_encoding(void)
212{
213 return git_commit_encoding ? git_commit_encoding : "UTF-8";
214}
7875acb6 215
27344d6a
JK
216int use_optional_locks(void)
217{
218 return git_env_bool(GIT_OPTIONAL_LOCKS_ENVIRONMENT, 1);
219}
a2cd709d
AR
220
221int print_sha1_ellipsis(void)
222{
223 /*
224 * Determine if the calling environment contains the variable
225 * GIT_PRINT_SHA1_ELLIPSIS set to "yes".
226 */
227 static int cached_result = -1; /* unknown */
228
229 if (cached_result < 0) {
230 const char *v = getenv("GIT_PRINT_SHA1_ELLIPSIS");
231 cached_result = (v && !strcasecmp(v, "yes"));
232 }
233 return cached_result;
234}