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.
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
11 #define USE_THE_REPOSITORY_VARIABLE
13 #include "git-compat-util.h"
17 #include "environment.h"
20 #include "repository.h"
23 #include "fmt-merge-msg.h"
27 #include "chdir-notify.h"
29 #include "write-or-die.h"
31 int trust_executable_bit
= 1;
35 int minimum_abbrev
= 4, default_abbrev
= -1;
38 int is_bare_repository_cfg
= -1; /* unspecified */
39 int warn_on_object_refname_ambiguity
= 1;
40 int repository_format_precious_objects
;
41 char *git_commit_encoding
;
42 char *git_log_output_encoding
;
43 char *apply_default_whitespace
;
44 char *apply_default_ignorewhitespace
;
45 char *git_attributes_file
;
46 int zlib_compression_level
= Z_BEST_SPEED
;
47 int pack_compression_level
= Z_DEFAULT_COMPRESSION
;
48 int fsync_object_files
= -1;
50 enum fsync_method fsync_method
= FSYNC_METHOD_DEFAULT
;
51 enum fsync_component fsync_components
= FSYNC_COMPONENTS_DEFAULT
;
53 char *askpass_program
;
55 enum auto_crlf auto_crlf
= AUTO_CRLF_FALSE
;
56 enum eol core_eol
= EOL_UNSET
;
57 int global_conv_flags_eol
= CONV_EOL_RNDTRP_WARN
;
58 char *check_roundtrip_encoding
;
59 enum branch_track git_branch_track
= BRANCH_TRACK_REMOTE
;
60 enum rebase_setup_type autorebase
= AUTOREBASE_NEVER
;
61 enum push_default_type push_default
= PUSH_DEFAULT_UNSPECIFIED
;
62 #ifndef OBJECT_CREATION_MODE
63 #define OBJECT_CREATION_MODE OBJECT_CREATION_USES_HARDLINKS
65 enum object_creation_mode object_creation_mode
= OBJECT_CREATION_MODE
;
66 int grafts_keep_true_parents
;
67 int core_apply_sparse_checkout
;
68 int core_sparse_checkout_cone
;
69 int sparse_expect_files_outside_of_patterns
;
70 int merge_log_config
= -1;
71 int precomposed_unicode
= -1; /* see probe_utf8_pathname_composition() */
72 unsigned long pack_size_limit_cfg
;
73 int max_allowed_tree_depth
=
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.
84 #elif defined(GIT_WINDOWS_NATIVE) && defined(__clang__) && defined(__aarch64__)
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.
98 #ifndef PROTECT_HFS_DEFAULT
99 #define PROTECT_HFS_DEFAULT 0
101 int protect_hfs
= PROTECT_HFS_DEFAULT
;
103 #ifndef PROTECT_NTFS_DEFAULT
104 #define PROTECT_NTFS_DEFAULT 1
106 int protect_ntfs
= PROTECT_NTFS_DEFAULT
;
109 * The character that begins a commented line in user-editable file
110 * that is subject to stripspace.
112 const char *comment_line_str
= "#";
113 char *comment_line_str_to_free
;
114 int auto_comment_line_char
;
116 /* This is set by setup_git_directory_gently() and/or git_default_config() */
117 char *git_work_tree_cfg
;
120 * Repository-local GIT_* environment variables; see environment.h for details.
122 const char * const local_repo_env
[] = {
123 ALTERNATE_DB_ENVIRONMENT
,
125 CONFIG_DATA_ENVIRONMENT
,
126 CONFIG_COUNT_ENVIRONMENT
,
129 GIT_WORK_TREE_ENVIRONMENT
,
130 GIT_IMPLICIT_WORK_TREE_ENVIRONMENT
,
133 NO_REPLACE_OBJECTS_ENVIRONMENT
,
134 GIT_REPLACE_REF_BASE_ENVIRONMENT
,
135 GIT_PREFIX_ENVIRONMENT
,
136 GIT_SHALLOW_FILE_ENVIRONMENT
,
137 GIT_COMMON_DIR_ENVIRONMENT
,
141 const char *getenv_safe(struct strvec
*argv
, const char *name
)
143 const char *value
= getenv(name
);
148 strvec_push(argv
, value
);
149 return argv
->v
[argv
->nr
- 1];
152 int is_bare_repository(void)
154 /* if core.bare is not 'false', let's see if there is a work tree */
155 return is_bare_repository_cfg
&& !repo_get_work_tree(the_repository
);
158 int have_git_dir(void)
160 return startup_info
->have_repository
161 || the_repository
->gitdir
;
164 const char *get_git_namespace(void)
166 static const char *namespace;
168 struct strbuf buf
= STRBUF_INIT
;
169 struct strbuf
**components
, **c
;
170 const char *raw_namespace
;
175 raw_namespace
= getenv(GIT_NAMESPACE_ENVIRONMENT
);
176 if (!raw_namespace
|| !*raw_namespace
) {
181 strbuf_addstr(&buf
, raw_namespace
);
182 components
= strbuf_split(&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
, '/');
192 namespace = strbuf_detach(&buf
, NULL
);
197 const char *strip_namespace(const char *namespaced_ref
)
200 if (skip_prefix(namespaced_ref
, get_git_namespace(), &out
))
205 const char *get_log_output_encoding(void)
207 return git_log_output_encoding
? git_log_output_encoding
208 : get_commit_output_encoding();
211 const char *get_commit_output_encoding(void)
213 return git_commit_encoding
? git_commit_encoding
: "UTF-8";
216 int use_optional_locks(void)
218 return git_env_bool(GIT_OPTIONAL_LOCKS_ENVIRONMENT
, 1);
221 int print_sha1_ellipsis(void)
224 * Determine if the calling environment contains the variable
225 * GIT_PRINT_SHA1_ELLIPSIS set to "yes".
227 static int cached_result
= -1; /* unknown */
229 if (cached_result
< 0) {
230 const char *v
= getenv("GIT_PRINT_SHA1_ELLIPSIS");
231 cached_result
= (v
&& !strcasecmp(v
, "yes"));
233 return cached_result
;