Derrick Stolee | 7211b9e | 2019-08-13 11:37:43 -0700 | [diff] [blame] | 1 | #include "cache.h" |
| 2 | #include "config.h" |
| 3 | #include "repository.h" |
Derrick Stolee | 18e449f | 2020-09-25 12:33:34 +0000 | [diff] [blame] | 4 | #include "midx.h" |
Jeff Hostetler | 62c7367 | 2022-03-25 18:02:51 +0000 | [diff] [blame] | 5 | #include "compat/fsmonitor/fsm-listen.h" |
Derrick Stolee | 7211b9e | 2019-08-13 11:37:43 -0700 | [diff] [blame] | 6 | |
Ævar Arnfjörð Bjarmason | 3050b6d | 2021-09-21 15:13:02 +0200 | [diff] [blame] | 7 | static void repo_cfg_bool(struct repository *r, const char *key, int *dest, |
| 8 | int def) |
| 9 | { |
| 10 | if (repo_config_get_bool(r, key, dest)) |
| 11 | *dest = def; |
| 12 | } |
Derrick Stolee | 31b1de6 | 2019-08-13 11:37:45 -0700 | [diff] [blame] | 13 | |
Taylor Blau | a92d852 | 2022-07-14 14:43:06 -0700 | [diff] [blame] | 14 | static void repo_cfg_int(struct repository *r, const char *key, int *dest, |
| 15 | int def) |
| 16 | { |
| 17 | if (repo_config_get_int(r, key, dest)) |
| 18 | *dest = def; |
| 19 | } |
| 20 | |
Derrick Stolee | 7211b9e | 2019-08-13 11:37:43 -0700 | [diff] [blame] | 21 | void prepare_repo_settings(struct repository *r) |
| 22 | { |
Ævar Arnfjörð Bjarmason | 3050b6d | 2021-09-21 15:13:02 +0200 | [diff] [blame] | 23 | int experimental; |
Derrick Stolee | 7211b9e | 2019-08-13 11:37:43 -0700 | [diff] [blame] | 24 | int value; |
Jeff King | 66eede4 | 2022-09-08 01:02:50 -0400 | [diff] [blame] | 25 | const char *strval; |
Ævar Arnfjörð Bjarmason | 3050b6d | 2021-09-21 15:13:02 +0200 | [diff] [blame] | 26 | int manyfiles; |
Derrick Stolee | 7211b9e | 2019-08-13 11:37:43 -0700 | [diff] [blame] | 27 | |
Lessley Dennington | 44c7e62 | 2021-12-06 15:55:58 +0000 | [diff] [blame] | 28 | if (!r->gitdir) |
| 29 | BUG("Cannot add settings for uninitialized repository"); |
| 30 | |
Ævar Arnfjörð Bjarmason | 3050b6d | 2021-09-21 15:13:02 +0200 | [diff] [blame] | 31 | if (r->settings.initialized++) |
Derrick Stolee | 7211b9e | 2019-08-13 11:37:43 -0700 | [diff] [blame] | 32 | return; |
| 33 | |
| 34 | /* Defaults */ |
Ævar Arnfjörð Bjarmason | 3050b6d | 2021-09-21 15:13:02 +0200 | [diff] [blame] | 35 | r->settings.index_version = -1; |
| 36 | r->settings.core_untracked_cache = UNTRACKED_CACHE_KEEP; |
Elijah Newren | 714edc6 | 2022-02-02 03:42:40 +0000 | [diff] [blame] | 37 | r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE; |
Derrick Stolee | 7211b9e | 2019-08-13 11:37:43 -0700 | [diff] [blame] | 38 | |
Ævar Arnfjörð Bjarmason | 3050b6d | 2021-09-21 15:13:02 +0200 | [diff] [blame] | 39 | /* Booleans config or default, cascades to other settings */ |
| 40 | repo_cfg_bool(r, "feature.manyfiles", &manyfiles, 0); |
| 41 | repo_cfg_bool(r, "feature.experimental", &experimental, 0); |
Derrick Stolee | 7211b9e | 2019-08-13 11:37:43 -0700 | [diff] [blame] | 42 | |
Ævar Arnfjörð Bjarmason | 3050b6d | 2021-09-21 15:13:02 +0200 | [diff] [blame] | 43 | /* Defaults modified by feature.* */ |
| 44 | if (experimental) { |
| 45 | r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_SKIPPING; |
Emily Shaffer | c695592 | 2022-10-26 17:32:45 -0400 | [diff] [blame] | 46 | r->settings.gc_cruft_packs = 1; |
Ævar Arnfjörð Bjarmason | 3050b6d | 2021-09-21 15:13:02 +0200 | [diff] [blame] | 47 | } |
| 48 | if (manyfiles) { |
| 49 | r->settings.index_version = 4; |
Derrick Stolee | 17194b1 | 2023-01-06 16:31:56 +0000 | [diff] [blame] | 50 | r->settings.index_skip_hash = 1; |
Ævar Arnfjörð Bjarmason | 3050b6d | 2021-09-21 15:13:02 +0200 | [diff] [blame] | 51 | r->settings.core_untracked_cache = UNTRACKED_CACHE_WRITE; |
| 52 | } |
| 53 | |
Taylor Blau | a92d852 | 2022-07-14 14:43:06 -0700 | [diff] [blame] | 54 | /* Commit graph config or default, does not cascade (simple) */ |
Ævar Arnfjörð Bjarmason | 3050b6d | 2021-09-21 15:13:02 +0200 | [diff] [blame] | 55 | repo_cfg_bool(r, "core.commitgraph", &r->settings.core_commit_graph, 1); |
Taylor Blau | a92d852 | 2022-07-14 14:43:06 -0700 | [diff] [blame] | 56 | repo_cfg_int(r, "commitgraph.generationversion", &r->settings.commit_graph_generation_version, 2); |
Ævar Arnfjörð Bjarmason | 3050b6d | 2021-09-21 15:13:02 +0200 | [diff] [blame] | 57 | repo_cfg_bool(r, "commitgraph.readchangedpaths", &r->settings.commit_graph_read_changed_paths, 1); |
| 58 | repo_cfg_bool(r, "gc.writecommitgraph", &r->settings.gc_write_commit_graph, 1); |
| 59 | repo_cfg_bool(r, "fetch.writecommitgraph", &r->settings.fetch_write_commit_graph, 0); |
Taylor Blau | a92d852 | 2022-07-14 14:43:06 -0700 | [diff] [blame] | 60 | |
| 61 | /* Boolean config or default, does not cascade (simple) */ |
Ævar Arnfjörð Bjarmason | 3050b6d | 2021-09-21 15:13:02 +0200 | [diff] [blame] | 62 | repo_cfg_bool(r, "pack.usesparse", &r->settings.pack_use_sparse, 1); |
| 63 | repo_cfg_bool(r, "core.multipackindex", &r->settings.core_multi_pack_index, 1); |
Ævar Arnfjörð Bjarmason | c21919f | 2021-09-21 15:13:03 +0200 | [diff] [blame] | 64 | repo_cfg_bool(r, "index.sparse", &r->settings.sparse_index, 0); |
Derrick Stolee | 17194b1 | 2023-01-06 16:31:56 +0000 | [diff] [blame] | 65 | repo_cfg_bool(r, "index.skiphash", &r->settings.index_skip_hash, r->settings.index_skip_hash); |
Ævar Arnfjörð Bjarmason | 3050b6d | 2021-09-21 15:13:02 +0200 | [diff] [blame] | 66 | |
| 67 | /* |
| 68 | * The GIT_TEST_MULTI_PACK_INDEX variable is special in that |
| 69 | * either it *or* the config sets |
| 70 | * r->settings.core_multi_pack_index if true. We don't take |
| 71 | * the environment variable if it exists (even if false) over |
| 72 | * any config, as in most other cases. |
| 73 | */ |
| 74 | if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0)) |
| 75 | r->settings.core_multi_pack_index = 1; |
| 76 | |
| 77 | /* |
| 78 | * Non-boolean config |
| 79 | */ |
Derrick Stolee | c11e996 | 2019-10-23 20:38:57 +0000 | [diff] [blame] | 80 | if (!repo_config_get_int(r, "index.version", &value)) |
Derrick Stolee | 7211b9e | 2019-08-13 11:37:43 -0700 | [diff] [blame] | 81 | r->settings.index_version = value; |
Derrick Stolee | ad0fb65 | 2019-08-13 11:37:46 -0700 | [diff] [blame] | 82 | |
Jeff King | 66eede4 | 2022-09-08 01:02:50 -0400 | [diff] [blame] | 83 | if (!repo_config_get_string_tmp(r, "core.untrackedcache", &strval)) { |
Ævar Arnfjörð Bjarmason | 3050b6d | 2021-09-21 15:13:02 +0200 | [diff] [blame] | 84 | int v = git_parse_maybe_bool(strval); |
| 85 | |
| 86 | /* |
| 87 | * If it's set to "keep", or some other non-boolean |
| 88 | * value then "v < 0". Then we do nothing and keep it |
| 89 | * at the default of UNTRACKED_CACHE_KEEP. |
| 90 | */ |
| 91 | if (v >= 0) |
| 92 | r->settings.core_untracked_cache = v ? |
| 93 | UNTRACKED_CACHE_WRITE : UNTRACKED_CACHE_REMOVE; |
Derrick Stolee | ad0fb65 | 2019-08-13 11:37:46 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Jeff King | 66eede4 | 2022-09-08 01:02:50 -0400 | [diff] [blame] | 96 | if (!repo_config_get_string_tmp(r, "fetch.negotiationalgorithm", &strval)) { |
Elijah Newren | 714edc6 | 2022-02-02 03:42:40 +0000 | [diff] [blame] | 97 | int fetch_default = r->settings.fetch_negotiation_algorithm; |
Derrick Stolee | aaf633c | 2019-08-13 11:37:48 -0700 | [diff] [blame] | 98 | if (!strcasecmp(strval, "skipping")) |
| 99 | r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_SKIPPING; |
Jonathan Tan | cbe566a | 2020-08-17 21:01:31 -0700 | [diff] [blame] | 100 | else if (!strcasecmp(strval, "noop")) |
| 101 | r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_NOOP; |
Elijah Newren | 714edc6 | 2022-02-02 03:42:40 +0000 | [diff] [blame] | 102 | else if (!strcasecmp(strval, "consecutive")) |
| 103 | r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE; |
Elijah Newren | a68c5b9 | 2022-02-02 03:42:38 +0000 | [diff] [blame] | 104 | else if (!strcasecmp(strval, "default")) |
Elijah Newren | 714edc6 | 2022-02-02 03:42:40 +0000 | [diff] [blame] | 105 | r->settings.fetch_negotiation_algorithm = fetch_default; |
Elijah Newren | a9a136c | 2022-02-02 03:42:39 +0000 | [diff] [blame] | 106 | else |
| 107 | die("unknown fetch negotiation algorithm '%s'", strval); |
Derrick Stolee | aaf633c | 2019-08-13 11:37:48 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Derrick Stolee | 3964fc2 | 2021-03-30 13:10:47 +0000 | [diff] [blame] | 110 | /* |
| 111 | * This setting guards all index reads to require a full index |
| 112 | * over a sparse index. After suitable guards are placed in the |
| 113 | * codebase around uses of the index, this setting will be |
| 114 | * removed. |
| 115 | */ |
| 116 | r->settings.command_requires_full_index = 1; |
Derrick Stolee | 7211b9e | 2019-08-13 11:37:43 -0700 | [diff] [blame] | 117 | } |