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"
19 #include "repository.h"
22 #include "fmt-merge-msg.h"
26 #include "chdir-notify.h"
28 #include "write-or-die.h"
30 int trust_executable_bit
= 1;
34 int minimum_abbrev
= 4, default_abbrev
= -1;
37 int is_bare_repository_cfg
= -1; /* unspecified */
38 int warn_on_object_refname_ambiguity
= 1;
39 int repository_format_precious_objects
;
40 char *git_commit_encoding
;
41 char *git_log_output_encoding
;
42 char *apply_default_whitespace
;
43 char *apply_default_ignorewhitespace
;
44 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
;
52 size_t packed_git_window_size
= DEFAULT_PACKED_GIT_WINDOW_SIZE
;
53 size_t packed_git_limit
= DEFAULT_PACKED_GIT_LIMIT
;
54 size_t delta_base_cache_limit
= 96 * 1024 * 1024;
55 unsigned long big_file_threshold
= 512 * 1024 * 1024;
57 char *askpass_program
;
59 enum auto_crlf auto_crlf
= AUTO_CRLF_FALSE
;
60 enum eol core_eol
= EOL_UNSET
;
61 int global_conv_flags_eol
= CONV_EOL_RNDTRP_WARN
;
62 char *check_roundtrip_encoding
;
63 enum branch_track git_branch_track
= BRANCH_TRACK_REMOTE
;
64 enum rebase_setup_type autorebase
= AUTOREBASE_NEVER
;
65 enum push_default_type push_default
= PUSH_DEFAULT_UNSPECIFIED
;
66 #ifndef OBJECT_CREATION_MODE
67 #define OBJECT_CREATION_MODE OBJECT_CREATION_USES_HARDLINKS
69 enum object_creation_mode object_creation_mode
= OBJECT_CREATION_MODE
;
70 int grafts_keep_true_parents
;
71 int core_apply_sparse_checkout
;
72 int core_sparse_checkout_cone
;
73 int sparse_expect_files_outside_of_patterns
;
74 int merge_log_config
= -1;
75 int precomposed_unicode
= -1; /* see probe_utf8_pathname_composition() */
76 unsigned long pack_size_limit_cfg
;
77 int max_allowed_tree_depth
=
80 * When traversing into too-deep trees, Visual C-compiled Git seems to
81 * run into some internal stack overflow detection in the
82 * `RtlpAllocateHeap()` function that is called from within
83 * `git_inflate_init()`'s call tree. The following value seems to be
84 * low enough to avoid that by letting Git exit with an error before
85 * the stack overflow can occur.
92 #ifndef PROTECT_HFS_DEFAULT
93 #define PROTECT_HFS_DEFAULT 0
95 int protect_hfs
= PROTECT_HFS_DEFAULT
;
97 #ifndef PROTECT_NTFS_DEFAULT
98 #define PROTECT_NTFS_DEFAULT 1
100 int protect_ntfs
= PROTECT_NTFS_DEFAULT
;
103 * The character that begins a commented line in user-editable file
104 * that is subject to stripspace.
106 const char *comment_line_str
= "#";
107 char *comment_line_str_to_free
;
108 int auto_comment_line_char
;
110 /* Parallel index stat data preload? */
111 int core_preload_index
= 1;
113 /* This is set by setup_git_dir_gently() and/or git_default_config() */
114 char *git_work_tree_cfg
;
117 * Repository-local GIT_* environment variables; see environment.h for details.
119 const char * const local_repo_env
[] = {
120 ALTERNATE_DB_ENVIRONMENT
,
122 CONFIG_DATA_ENVIRONMENT
,
123 CONFIG_COUNT_ENVIRONMENT
,
126 GIT_WORK_TREE_ENVIRONMENT
,
127 GIT_IMPLICIT_WORK_TREE_ENVIRONMENT
,
130 NO_REPLACE_OBJECTS_ENVIRONMENT
,
131 GIT_REPLACE_REF_BASE_ENVIRONMENT
,
132 GIT_PREFIX_ENVIRONMENT
,
133 GIT_SHALLOW_FILE_ENVIRONMENT
,
134 GIT_COMMON_DIR_ENVIRONMENT
,
138 const char *getenv_safe(struct strvec
*argv
, const char *name
)
140 const char *value
= getenv(name
);
145 strvec_push(argv
, value
);
146 return argv
->v
[argv
->nr
- 1];
149 int is_bare_repository(void)
151 /* if core.bare is not 'false', let's see if there is a work tree */
152 return is_bare_repository_cfg
&& !repo_get_work_tree(the_repository
);
155 int have_git_dir(void)
157 return startup_info
->have_repository
158 || the_repository
->gitdir
;
161 const char *get_git_namespace(void)
163 static const char *namespace;
165 struct strbuf buf
= STRBUF_INIT
;
166 struct strbuf
**components
, **c
;
167 const char *raw_namespace
;
172 raw_namespace
= getenv(GIT_NAMESPACE_ENVIRONMENT
);
173 if (!raw_namespace
|| !*raw_namespace
) {
178 strbuf_addstr(&buf
, raw_namespace
);
179 components
= strbuf_split(&buf
, '/');
181 for (c
= components
; *c
; c
++)
182 if (strcmp((*c
)->buf
, "/") != 0)
183 strbuf_addf(&buf
, "refs/namespaces/%s", (*c
)->buf
);
184 strbuf_list_free(components
);
185 if (check_refname_format(buf
.buf
, 0))
186 die(_("bad git namespace path \"%s\""), raw_namespace
);
187 strbuf_addch(&buf
, '/');
189 namespace = strbuf_detach(&buf
, NULL
);
194 const char *strip_namespace(const char *namespaced_ref
)
197 if (skip_prefix(namespaced_ref
, get_git_namespace(), &out
))
202 const char *get_log_output_encoding(void)
204 return git_log_output_encoding
? git_log_output_encoding
205 : get_commit_output_encoding();
208 const char *get_commit_output_encoding(void)
210 return git_commit_encoding
? git_commit_encoding
: "UTF-8";
213 static int the_shared_repository
= PERM_UMASK
;
214 static int need_shared_repository_from_config
= 1;
216 void set_shared_repository(int value
)
218 the_shared_repository
= value
;
219 need_shared_repository_from_config
= 0;
222 int get_shared_repository(void)
224 if (need_shared_repository_from_config
) {
225 const char *var
= "core.sharedrepository";
227 if (!git_config_get_value(var
, &value
))
228 the_shared_repository
= git_config_perm(var
, value
);
229 need_shared_repository_from_config
= 0;
231 return the_shared_repository
;
234 void reset_shared_repository(void)
236 need_shared_repository_from_config
= 1;
239 int use_optional_locks(void)
241 return git_env_bool(GIT_OPTIONAL_LOCKS_ENVIRONMENT
, 1);
244 int print_sha1_ellipsis(void)
247 * Determine if the calling environment contains the variable
248 * GIT_PRINT_SHA1_ELLIPSIS set to "yes".
250 static int cached_result
= -1; /* unknown */
252 if (cached_result
< 0) {
253 const char *v
= getenv("GIT_PRINT_SHA1_ELLIPSIS");
254 cached_result
= (v
&& !strcasecmp(v
, "yes"));
256 return cached_result
;