git-cvsserver: protect against NULL in crypt(3)
[git.git] / repo-settings.c
blob0cfe8b787db26d9eaf55c31e839fc291477b879e
1 #include "cache.h"
2 #include "config.h"
3 #include "repository.h"
4 #include "midx.h"
6 #define UPDATE_DEFAULT_BOOL(s,v) do { if (s == -1) { s = v; } } while(0)
8 void prepare_repo_settings(struct repository *r)
10 int value;
11 char *strval;
13 if (r->settings.initialized)
14 return;
16 /* Defaults */
17 memset(&r->settings, -1, sizeof(r->settings));
19 if (!repo_config_get_bool(r, "core.commitgraph", &value))
20 r->settings.core_commit_graph = value;
21 if (!repo_config_get_bool(r, "commitgraph.readchangedpaths", &value))
22 r->settings.commit_graph_read_changed_paths = value;
23 if (!repo_config_get_bool(r, "gc.writecommitgraph", &value))
24 r->settings.gc_write_commit_graph = value;
25 UPDATE_DEFAULT_BOOL(r->settings.core_commit_graph, 1);
26 UPDATE_DEFAULT_BOOL(r->settings.commit_graph_read_changed_paths, 1);
27 UPDATE_DEFAULT_BOOL(r->settings.gc_write_commit_graph, 1);
29 if (!repo_config_get_int(r, "index.version", &value))
30 r->settings.index_version = value;
31 if (!repo_config_get_maybe_bool(r, "core.untrackedcache", &value)) {
32 if (value == 0)
33 r->settings.core_untracked_cache = UNTRACKED_CACHE_REMOVE;
34 else
35 r->settings.core_untracked_cache = UNTRACKED_CACHE_WRITE;
36 } else if (!repo_config_get_string(r, "core.untrackedcache", &strval)) {
37 if (!strcasecmp(strval, "keep"))
38 r->settings.core_untracked_cache = UNTRACKED_CACHE_KEEP;
40 free(strval);
43 if (!repo_config_get_string(r, "fetch.negotiationalgorithm", &strval)) {
44 if (!strcasecmp(strval, "skipping"))
45 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_SKIPPING;
46 else if (!strcasecmp(strval, "noop"))
47 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_NOOP;
48 else
49 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_DEFAULT;
52 if (!repo_config_get_bool(r, "pack.usesparse", &value))
53 r->settings.pack_use_sparse = value;
54 UPDATE_DEFAULT_BOOL(r->settings.pack_use_sparse, 1);
56 value = git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0);
57 if (value || !repo_config_get_bool(r, "core.multipackindex", &value))
58 r->settings.core_multi_pack_index = value;
59 UPDATE_DEFAULT_BOOL(r->settings.core_multi_pack_index, 1);
61 if (!repo_config_get_bool(r, "feature.manyfiles", &value) && value) {
62 UPDATE_DEFAULT_BOOL(r->settings.index_version, 4);
63 UPDATE_DEFAULT_BOOL(r->settings.core_untracked_cache, UNTRACKED_CACHE_WRITE);
66 if (!repo_config_get_bool(r, "fetch.writecommitgraph", &value))
67 r->settings.fetch_write_commit_graph = value;
68 UPDATE_DEFAULT_BOOL(r->settings.fetch_write_commit_graph, 0);
70 if (!repo_config_get_bool(r, "feature.experimental", &value) && value)
71 UPDATE_DEFAULT_BOOL(r->settings.fetch_negotiation_algorithm, FETCH_NEGOTIATION_SKIPPING);
73 /* Hack for test programs like test-dump-untracked-cache */
74 if (ignore_untracked_cache_config)
75 r->settings.core_untracked_cache = UNTRACKED_CACHE_KEEP;
76 else
77 UPDATE_DEFAULT_BOOL(r->settings.core_untracked_cache, UNTRACKED_CACHE_KEEP);
79 UPDATE_DEFAULT_BOOL(r->settings.fetch_negotiation_algorithm, FETCH_NEGOTIATION_DEFAULT);
82 * This setting guards all index reads to require a full index
83 * over a sparse index. After suitable guards are placed in the
84 * codebase around uses of the index, this setting will be
85 * removed.
87 r->settings.command_requires_full_index = 1;
90 * Initialize this as off.
92 r->settings.sparse_index = 0;
93 if (!repo_config_get_bool(r, "index.sparse", &value) && value)
94 r->settings.sparse_index = 1;