Merge branch 'ab/config-based-hooks-base' into seen
[git] / repo-settings.c
1 #include "cache.h"
2 #include "config.h"
3 #include "repository.h"
4 #include "midx.h"
5
6 #define UPDATE_DEFAULT_BOOL(s,v) do { if (s == -1) { s = v; } } while(0)
7
8 void prepare_repo_settings(struct repository *r)
9 {
10         int value;
11         char *strval;
12
13         if (r->settings.initialized)
14                 return;
15
16         /* Defaults */
17         memset(&r->settings, -1, sizeof(r->settings));
18
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);
28
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;
39
40                 free(strval);
41         }
42
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;
50         }
51
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);
55
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);
60
61         if (!repo_config_get_bool(r, "core.usebuiltinfsmonitor", &value) && value)
62                 r->settings.use_builtin_fsmonitor = 1;
63
64         if (!repo_config_get_bool(r, "feature.manyfiles", &value) && value) {
65                 UPDATE_DEFAULT_BOOL(r->settings.index_version, 4);
66                 UPDATE_DEFAULT_BOOL(r->settings.core_untracked_cache, UNTRACKED_CACHE_WRITE);
67         }
68
69         if (!repo_config_get_bool(r, "fetch.writecommitgraph", &value))
70                 r->settings.fetch_write_commit_graph = value;
71         UPDATE_DEFAULT_BOOL(r->settings.fetch_write_commit_graph, 0);
72
73         if (!repo_config_get_bool(r, "feature.experimental", &value) && value)
74                 UPDATE_DEFAULT_BOOL(r->settings.fetch_negotiation_algorithm, FETCH_NEGOTIATION_SKIPPING);
75
76         /* Hack for test programs like test-dump-untracked-cache */
77         if (ignore_untracked_cache_config)
78                 r->settings.core_untracked_cache = UNTRACKED_CACHE_KEEP;
79         else
80                 UPDATE_DEFAULT_BOOL(r->settings.core_untracked_cache, UNTRACKED_CACHE_KEEP);
81
82         UPDATE_DEFAULT_BOOL(r->settings.fetch_negotiation_algorithm, FETCH_NEGOTIATION_DEFAULT);
83
84         /*
85          * This setting guards all index reads to require a full index
86          * over a sparse index. After suitable guards are placed in the
87          * codebase around uses of the index, this setting will be
88          * removed.
89          */
90         r->settings.command_requires_full_index = 1;
91
92         /*
93          * Initialize this as off.
94          */
95         r->settings.sparse_index = 0;
96         if (!repo_config_get_bool(r, "index.sparse", &value) && value)
97                 r->settings.sparse_index = 1;
98 }