Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/repo-settings.c # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / repo-settings.c` 219 lines ยท 7343 bytes Raw Blame History 1 #include "git-compat-util.h" 2 #include "config.h" 3 #include "repo-settings.h" 4 #include "repository.h" 5 #include "midx.h" 6 #include "pack-objects.h" 7 #include "setup.h" 8 9 static void repo_cfg_bool(struct repository *r, const char *key, int *dest, 10 int def) 11 { 12 if (repo_config_get_bool(r, key, dest)) 13 *dest = def; 14 } 15 16 static void repo_cfg_int(struct repository *r, const char *key, int *dest, 17 int def) 18 { 19 if (repo_config_get_int(r, key, dest)) 20 *dest = def; 21 } 22 23 static void repo_cfg_ulong(struct repository *r, const char *key, unsigned long *dest, 24 unsigned long def) 25 { 26 if (repo_config_get_ulong(r, key, dest)) 27 *dest = def; 28 } 29 30 void prepare_repo_settings(struct repository *r) 31 { 32 int experimental; 33 int value; 34 const char *strval; 35 int manyfiles; 36 int read_changed_paths; 37 unsigned long ulongval; 38 39 if (!r->gitdir) 40 BUG("Cannot add settings for uninitialized repository"); 41 42 if (r->settings.initialized) 43 return; 44 45 repo_settings_clear(r); 46 r->settings.initialized++; 47 48 /* Booleans config or default, cascades to other settings */ 49 repo_cfg_bool(r, "feature.manyfiles", &manyfiles, 0); 50 repo_cfg_bool(r, "feature.experimental", &experimental, 0); 51 52 /* Defaults modified by feature.* */ 53 if (experimental) { 54 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_SKIPPING; 55 r->settings.pack_use_bitmap_boundary_traversal = 1; 56 r->settings.pack_use_multi_pack_reuse = 1; 57 r->settings.pack_use_path_walk = 1; 58 } 59 if (manyfiles) { 60 r->settings.index_version = 4; 61 r->settings.index_skip_hash = 1; 62 r->settings.core_untracked_cache = UNTRACKED_CACHE_WRITE; 63 r->settings.pack_use_path_walk = 1; 64 } 65 66 /* Commit graph config or default, does not cascade (simple) */ 67 repo_cfg_bool(r, "core.commitgraph", &r->settings.core_commit_graph, 1); 68 repo_cfg_int(r, "commitgraph.generationversion", &r->settings.commit_graph_generation_version, 2); 69 repo_cfg_bool(r, "commitgraph.readchangedpaths", &read_changed_paths, 1); 70 repo_cfg_int(r, "commitgraph.changedpathsversion", 71 &r->settings.commit_graph_changed_paths_version, 72 read_changed_paths ? -1 : 0); 73 repo_cfg_bool(r, "gc.writecommitgraph", &r->settings.gc_write_commit_graph, 1); 74 repo_cfg_bool(r, "fetch.writecommitgraph", &r->settings.fetch_write_commit_graph, 0); 75 76 /* Boolean config or default, does not cascade (simple) */ 77 repo_cfg_bool(r, "pack.usesparse", &r->settings.pack_use_sparse, 1); 78 repo_cfg_bool(r, "pack.usepathwalk", &r->settings.pack_use_path_walk, 0); 79 repo_cfg_bool(r, "core.multipackindex", &r->settings.core_multi_pack_index, 1); 80 repo_cfg_bool(r, "index.sparse", &r->settings.sparse_index, 0); 81 repo_cfg_bool(r, "index.skiphash", &r->settings.index_skip_hash, r->settings.index_skip_hash); 82 repo_cfg_bool(r, "pack.readreverseindex", &r->settings.pack_read_reverse_index, 1); 83 repo_cfg_bool(r, "pack.usebitmapboundarytraversal", 84 &r->settings.pack_use_bitmap_boundary_traversal, 85 r->settings.pack_use_bitmap_boundary_traversal); 86 repo_cfg_bool(r, "core.usereplacerefs", &r->settings.read_replace_refs, 1); 87 88 /* 89 * The GIT_TEST_MULTI_PACK_INDEX variable is special in that 90 * either it *or* the config sets 91 * r->settings.core_multi_pack_index if true. We don't take 92 * the environment variable if it exists (even if false) over 93 * any config, as in most other cases. 94 */ 95 if (git_env_bool(GIT_TEST_MULTI_PACK_INDEX, 0)) 96 r->settings.core_multi_pack_index = 1; 97 98 /* 99 * Non-boolean config 100 */ 101 if (!repo_config_get_int(r, "index.version", &value)) 102 r->settings.index_version = value; 103 repo_cfg_int(r, "core.maxtreedepth", 104 &r->settings.max_allowed_tree_depth, 105 DEFAULT_MAX_ALLOWED_TREE_DEPTH); 106 107 if (!repo_config_get_string_tmp(r, "core.untrackedcache", &strval)) { 108 int v = git_parse_maybe_bool(strval); 109 110 /* 111 * If it's set to "keep", or some other non-boolean 112 * value then "v < 0". Then we do nothing and keep it 113 * at the default of UNTRACKED_CACHE_KEEP. 114 */ 115 if (v >= 0) 116 r->settings.core_untracked_cache = v ? 117 UNTRACKED_CACHE_WRITE : UNTRACKED_CACHE_REMOVE; 118 } 119 120 if (!repo_config_get_string_tmp(r, "fetch.negotiationalgorithm", &strval)) { 121 int fetch_default = r->settings.fetch_negotiation_algorithm; 122 if (!strcasecmp(strval, "skipping")) 123 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_SKIPPING; 124 else if (!strcasecmp(strval, "noop")) 125 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_NOOP; 126 else if (!strcasecmp(strval, "consecutive")) 127 r->settings.fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE; 128 else if (!strcasecmp(strval, "default")) 129 r->settings.fetch_negotiation_algorithm = fetch_default; 130 else 131 die("unknown fetch negotiation algorithm '%s'", strval); 132 } 133 134 /* 135 * This setting guards all index reads to require a full index 136 * over a sparse index. After suitable guards are placed in the 137 * codebase around uses of the index, this setting will be 138 * removed. 139 */ 140 r->settings.command_requires_full_index = 1; 141 142 if (!repo_config_get_ulong(r, "core.deltabasecachelimit", &ulongval)) 143 r->settings.delta_base_cache_limit = ulongval; 144 145 if (!repo_config_get_ulong(r, "core.packedgitwindowsize", &ulongval)) { 146 int pgsz_x2 = getpagesize() * 2; 147 148 /* This value must be multiple of (pagesize * 2) */ 149 ulongval /= pgsz_x2; 150 if (ulongval < 1) 151 ulongval = 1; 152 r->settings.packed_git_window_size = ulongval * pgsz_x2; 153 } 154 155 if (!repo_config_get_ulong(r, "core.packedgitlimit", &ulongval)) 156 r->settings.packed_git_limit = ulongval; 157 } 158 159 void repo_settings_clear(struct repository *r) 160 { 161 struct repo_settings empty = REPO_SETTINGS_INIT; 162 FREE_AND_NULL(r->settings.fsmonitor); 163 FREE_AND_NULL(r->settings.hooks_path); 164 r->settings = empty; 165 } 166 167 unsigned long repo_settings_get_big_file_threshold(struct repository *repo) 168 { 169 if (!repo->settings.big_file_threshold) 170 repo_cfg_ulong(repo, "core.bigfilethreshold", 171 &repo->settings.big_file_threshold, 512 * 1024 * 1024); 172 return repo->settings.big_file_threshold; 173 } 174 175 void repo_settings_set_big_file_threshold(struct repository *repo, unsigned long value) 176 { 177 repo->settings.big_file_threshold = value; 178 } 179 180 int repo_settings_get_warn_ambiguous_refs(struct repository *repo) 181 { 182 prepare_repo_settings(repo); 183 if (repo->settings.warn_ambiguous_refs < 0) 184 repo_cfg_bool(repo, "core.warnambiguousrefs", 185 &repo->settings.warn_ambiguous_refs, 1); 186 return repo->settings.warn_ambiguous_refs; 187 } 188 189 const char *repo_settings_get_hooks_path(struct repository *repo) 190 { 191 if (!repo->settings.hooks_path) 192 repo_config_get_pathname(repo, "core.hookspath", &repo->settings.hooks_path); 193 return repo->settings.hooks_path; 194 } 195 196 int repo_settings_get_shared_repository(struct repository *repo) 197 { 198 if (!repo->settings.shared_repository_initialized) { 199 const char *var = "core.sharedrepository"; 200 const char *value; 201 if (!repo_config_get_value(repo, var, &value)) 202 repo->settings.shared_repository = git_config_perm(var, value); 203 else 204 repo->settings.shared_repository = PERM_UMASK; 205 repo->settings.shared_repository_initialized = 1; 206 } 207 return repo->settings.shared_repository; 208 } 209 210 void repo_settings_set_shared_repository(struct repository *repo, int value) 211 { 212 repo->settings.shared_repository = value; 213 repo->settings.shared_repository_initialized = 1; 214 } 215 216 void repo_settings_reset_shared_repository(struct repository *repo) 217 { 218 repo->settings.shared_repository_initialized = 0; 219 }