1 #include "git-compat-util.h"
3 #include "repo-settings.h"
4 #include "repository.h"
6 #include "pack-objects.h"
8 static void repo_cfg_bool(struct repository
*r
, const char *key
, int *dest
,
11 if (repo_config_get_bool(r
, key
, dest
))
15 static void repo_cfg_int(struct repository
*r
, const char *key
, int *dest
,
18 if (repo_config_get_int(r
, key
, dest
))
22 void prepare_repo_settings(struct repository
*r
)
24 const struct repo_settings defaults
= REPO_SETTINGS_INIT
;
29 int read_changed_paths
;
30 unsigned long ulongval
;
33 BUG("Cannot add settings for uninitialized repository");
35 if (r
->settings
.initialized
)
38 memcpy(&r
->settings
, &defaults
, sizeof(defaults
));
39 r
->settings
.initialized
++;
41 /* Booleans config or default, cascades to other settings */
42 repo_cfg_bool(r
, "feature.manyfiles", &manyfiles
, 0);
43 repo_cfg_bool(r
, "feature.experimental", &experimental
, 0);
45 /* Defaults modified by feature.* */
47 r
->settings
.fetch_negotiation_algorithm
= FETCH_NEGOTIATION_SKIPPING
;
48 r
->settings
.pack_use_bitmap_boundary_traversal
= 1;
49 r
->settings
.pack_use_multi_pack_reuse
= 1;
52 r
->settings
.index_version
= 4;
53 r
->settings
.index_skip_hash
= 1;
54 r
->settings
.core_untracked_cache
= UNTRACKED_CACHE_WRITE
;
57 /* Commit graph config or default, does not cascade (simple) */
58 repo_cfg_bool(r
, "core.commitgraph", &r
->settings
.core_commit_graph
, 1);
59 repo_cfg_int(r
, "commitgraph.generationversion", &r
->settings
.commit_graph_generation_version
, 2);
60 repo_cfg_bool(r
, "commitgraph.readchangedpaths", &read_changed_paths
, 1);
61 repo_cfg_int(r
, "commitgraph.changedpathsversion",
62 &r
->settings
.commit_graph_changed_paths_version
,
63 read_changed_paths
? -1 : 0);
64 repo_cfg_bool(r
, "gc.writecommitgraph", &r
->settings
.gc_write_commit_graph
, 1);
65 repo_cfg_bool(r
, "fetch.writecommitgraph", &r
->settings
.fetch_write_commit_graph
, 0);
67 /* Boolean config or default, does not cascade (simple) */
68 repo_cfg_bool(r
, "pack.usesparse", &r
->settings
.pack_use_sparse
, 1);
69 repo_cfg_bool(r
, "core.multipackindex", &r
->settings
.core_multi_pack_index
, 1);
70 repo_cfg_bool(r
, "index.sparse", &r
->settings
.sparse_index
, 0);
71 repo_cfg_bool(r
, "index.skiphash", &r
->settings
.index_skip_hash
, r
->settings
.index_skip_hash
);
72 repo_cfg_bool(r
, "pack.readreverseindex", &r
->settings
.pack_read_reverse_index
, 1);
73 repo_cfg_bool(r
, "pack.usebitmapboundarytraversal",
74 &r
->settings
.pack_use_bitmap_boundary_traversal
,
75 r
->settings
.pack_use_bitmap_boundary_traversal
);
76 repo_cfg_bool(r
, "core.usereplacerefs", &r
->settings
.read_replace_refs
, 1);
79 * The GIT_TEST_MULTI_PACK_INDEX variable is special in that
80 * either it *or* the config sets
81 * r->settings.core_multi_pack_index if true. We don't take
82 * the environment variable if it exists (even if false) over
83 * any config, as in most other cases.
85 if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX
, 0))
86 r
->settings
.core_multi_pack_index
= 1;
91 if (!repo_config_get_int(r
, "index.version", &value
))
92 r
->settings
.index_version
= value
;
94 if (!repo_config_get_string_tmp(r
, "core.untrackedcache", &strval
)) {
95 int v
= git_parse_maybe_bool(strval
);
98 * If it's set to "keep", or some other non-boolean
99 * value then "v < 0". Then we do nothing and keep it
100 * at the default of UNTRACKED_CACHE_KEEP.
103 r
->settings
.core_untracked_cache
= v
?
104 UNTRACKED_CACHE_WRITE
: UNTRACKED_CACHE_REMOVE
;
107 if (!repo_config_get_string_tmp(r
, "fetch.negotiationalgorithm", &strval
)) {
108 int fetch_default
= r
->settings
.fetch_negotiation_algorithm
;
109 if (!strcasecmp(strval
, "skipping"))
110 r
->settings
.fetch_negotiation_algorithm
= FETCH_NEGOTIATION_SKIPPING
;
111 else if (!strcasecmp(strval
, "noop"))
112 r
->settings
.fetch_negotiation_algorithm
= FETCH_NEGOTIATION_NOOP
;
113 else if (!strcasecmp(strval
, "consecutive"))
114 r
->settings
.fetch_negotiation_algorithm
= FETCH_NEGOTIATION_CONSECUTIVE
;
115 else if (!strcasecmp(strval
, "default"))
116 r
->settings
.fetch_negotiation_algorithm
= fetch_default
;
118 die("unknown fetch negotiation algorithm '%s'", strval
);
122 * This setting guards all index reads to require a full index
123 * over a sparse index. After suitable guards are placed in the
124 * codebase around uses of the index, this setting will be
127 r
->settings
.command_requires_full_index
= 1;
129 if (!repo_config_get_ulong(r
, "core.deltabasecachelimit", &ulongval
))
130 r
->settings
.delta_base_cache_limit
= ulongval
;
132 if (!repo_config_get_ulong(r
, "core.packedgitwindowsize", &ulongval
)) {
133 int pgsz_x2
= getpagesize() * 2;
135 /* This value must be multiple of (pagesize * 2) */
139 r
->settings
.packed_git_window_size
= ulongval
* pgsz_x2
;
142 if (!repo_config_get_ulong(r
, "core.packedgitlimit", &ulongval
))
143 r
->settings
.packed_git_limit
= ulongval
;
146 enum log_refs_config
repo_settings_get_log_all_ref_updates(struct repository
*repo
)
150 if (!repo_config_get_string_tmp(repo
, "core.logallrefupdates", &value
)) {
151 if (value
&& !strcasecmp(value
, "always"))
152 return LOG_REFS_ALWAYS
;
153 else if (git_config_bool("core.logallrefupdates", value
))
154 return LOG_REFS_NORMAL
;
156 return LOG_REFS_NONE
;
159 return LOG_REFS_UNSET
;
162 int repo_settings_get_warn_ambiguous_refs(struct repository
*repo
)
164 prepare_repo_settings(repo
);
165 if (repo
->settings
.warn_ambiguous_refs
< 0)
166 repo_cfg_bool(repo
, "core.warnambiguousrefs",
167 &repo
->settings
.warn_ambiguous_refs
, 1);
168 return repo
->settings
.warn_ambiguous_refs
;