From: Ayush Chandekar Date: Tue, 17 Jun 2025 12:06:35 +0000 (+0530) Subject: environment: move access to "core.sparsecheckoutcone" into repo_settings X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3b9232a0ade21fb865ec1bf1deb9bd3dbb220a15;p=thirdparty%2Fgit.git environment: move access to "core.sparsecheckoutcone" into repo_settings The setting "core.sparsecheckoutcone" is stored in the global `core_sparse_checkout_cone` and is populated in config.c. Refactor the code to store it in the variable `sparse_checkout_cone` in the struct `repo_settings`. It's fine not to lazily load it from the config, as the variable is used quite commonly. This change is part of an ongoing effort to eliminate global variables, improve modularity and help libify the codebase. Mentored-by: Christian Couder Mentored-by: Ghanshyam Thakkar Signed-off-by: Ayush Chandekar Signed-off-by: Junio C Hamano --- diff --git a/builtin/grep.c b/builtin/grep.c index 63342f5e36..94d6245b85 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -491,7 +491,7 @@ static int grep_submodule(struct grep_opt *opt, * dictate the behavior for the submodule, making it "forget" its * sparse-checkout state. * - * 3. "core_sparse_checkout_cone" + * 3. "sparse_checkout_cone" * ditto. * * Note that this list is not exhaustive. diff --git a/builtin/mv.c b/builtin/mv.c index 1e9f4d3eba..833fa761dd 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -573,7 +573,7 @@ remove_entry: if (ignore_sparse && the_repository->settings.sparse_checkout && - core_sparse_checkout_cone) { + the_repository->settings.sparse_checkout_cone) { /* * NEEDSWORK: we are *not* paying attention to * "out-to-out" move ( is out-of-cone and diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index 869d574a03..e65a62f250 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -71,7 +71,7 @@ static int sparse_checkout_list(int argc, const char **argv, const char *prefix, memset(&pl, 0, sizeof(pl)); - pl.use_cone_patterns = core_sparse_checkout_cone; + pl.use_cone_patterns = the_repository->settings.sparse_checkout_cone; sparse_filename = get_sparse_checkout_filename(); res = add_patterns_from_file_to_list(sparse_filename, "", 0, &pl, NULL, 0); @@ -352,7 +352,7 @@ static int write_patterns_and_update(struct pattern_list *pl) if (!fp) die_errno(_("unable to fdopen %s"), get_lock_file_path(&lk)); - if (core_sparse_checkout_cone) + if (the_repository->settings.sparse_checkout_cone) write_cone_to_file(fp, pl); else write_patterns_to_file(fp, pl); @@ -398,15 +398,15 @@ static int set_config(enum sparse_checkout_mode mode) static enum sparse_checkout_mode update_cone_mode(int *cone_mode) { /* If not specified, use previous definition of cone mode */ if (*cone_mode == -1 && the_repository->settings.sparse_checkout) - *cone_mode = core_sparse_checkout_cone; + *cone_mode = the_repository->settings.sparse_checkout_cone; /* Set cone/non-cone mode appropriately */ the_repository->settings.sparse_checkout = 1; if (*cone_mode == 1 || *cone_mode == -1) { - core_sparse_checkout_cone = 1; + the_repository->settings.sparse_checkout_cone = 1; return MODE_CONE_PATTERNS; } - core_sparse_checkout_cone = 0; + the_repository->settings.sparse_checkout_cone = 0; return MODE_ALL_PATTERNS; } @@ -572,7 +572,7 @@ static void add_patterns_from_input(struct pattern_list *pl, FILE *file) { int i; - if (core_sparse_checkout_cone) { + if (the_repository->settings.sparse_checkout_cone) { struct strbuf line = STRBUF_INIT; hashmap_init(&pl->recursive_hashmap, pl_hashmap_cmp, NULL, 0); @@ -637,7 +637,7 @@ static void add_patterns_cone_mode(int argc, const char **argv, use_stdin ? stdin : NULL); memset(&existing, 0, sizeof(existing)); - existing.use_cone_patterns = core_sparse_checkout_cone; + existing.use_cone_patterns = the_repository->settings.sparse_checkout_cone; if (add_patterns_from_file_to_list(sparse_filename, "", 0, &existing, NULL, 0)) @@ -683,7 +683,7 @@ static int modify_pattern_list(struct strvec *args, int use_stdin, switch (m) { case ADD: - if (core_sparse_checkout_cone) + if (the_repository->settings.sparse_checkout_cone) add_patterns_cone_mode(args->nr, args->v, pl, use_stdin); else add_patterns_literal(args->nr, args->v, pl, use_stdin); @@ -719,7 +719,7 @@ static void sanitize_paths(struct strvec *args, if (!args->nr) return; - if (prefix && *prefix && core_sparse_checkout_cone) { + if (prefix && *prefix && the_repository->settings.sparse_checkout_cone) { /* * The args are not pathspecs, so unfortunately we * cannot imitate how cmd_add() uses parse_pathspec(). @@ -736,10 +736,10 @@ static void sanitize_paths(struct strvec *args, if (skip_checks) return; - if (prefix && *prefix && !core_sparse_checkout_cone) + if (prefix && *prefix && !the_repository->settings.sparse_checkout_cone) die(_("please run from the toplevel directory in non-cone mode")); - if (core_sparse_checkout_cone) { + if (the_repository->settings.sparse_checkout_cone) { for (i = 0; i < args->nr; i++) { if (args->v[i][0] == '/') die(_("specify directories rather than patterns (no leading slash)")); @@ -761,7 +761,7 @@ static void sanitize_paths(struct strvec *args, if (S_ISSPARSEDIR(ce->ce_mode)) continue; - if (core_sparse_checkout_cone) + if (the_repository->settings.sparse_checkout_cone) die(_("'%s' is not a directory; to treat it as a directory anyway, rerun with --skip-checks"), args->v[i]); else warning(_("pass a leading slash before paths such as '%s' if you want a single file (see NON-CONE PROBLEMS in the git-sparse-checkout manual)."), args->v[i]); @@ -864,7 +864,7 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix, * non-cone mode, if nothing is specified, manually select just the * top-level directory (much as 'init' would do). */ - if (!core_sparse_checkout_cone && !set_opts.use_stdin && argc == 0) { + if (!the_repository->settings.sparse_checkout_cone && !set_opts.use_stdin && argc == 0) { for (int i = 0; i < default_patterns_nr; i++) strvec_push(&patterns, default_patterns[i]); } else { @@ -1042,7 +1042,7 @@ static int sparse_checkout_check_rules(int argc, const char **argv, const char * check_rules_opts.cone_mode = 1; update_cone_mode(&check_rules_opts.cone_mode); - pl.use_cone_patterns = core_sparse_checkout_cone; + pl.use_cone_patterns = the_repository->settings.sparse_checkout_cone; if (check_rules_opts.rules_file) { fp = xfopen(check_rules_opts.rules_file, "r"); add_patterns_from_input(&pl, argc, argv, fp); diff --git a/config.c b/config.c index 8fd4dd8c81..707fe0707a 100644 --- a/config.c +++ b/config.c @@ -1612,11 +1612,6 @@ static int git_default_core_config(const char *var, const char *value, return 0; } - if (!strcmp(var, "core.sparsecheckoutcone")) { - core_sparse_checkout_cone = git_config_bool(var, value); - return 0; - } - if (!strcmp(var, "core.precomposeunicode")) { precomposed_unicode = git_config_bool(var, value); return 0; diff --git a/dir.c b/dir.c index 8f0f7ca8a4..8378996b72 100644 --- a/dir.c +++ b/dir.c @@ -3459,7 +3459,7 @@ int get_sparse_checkout_patterns(struct pattern_list *pl) int res; char *sparse_filename = get_sparse_checkout_filename(); - pl->use_cone_patterns = core_sparse_checkout_cone; + pl->use_cone_patterns = the_repository->settings.sparse_checkout_cone; res = add_patterns_from_file_to_list(sparse_filename, "", 0, pl, NULL, 0); free(sparse_filename); diff --git a/environment.c b/environment.c index a379a9149e..7d46b80711 100644 --- a/environment.c +++ b/environment.c @@ -64,7 +64,6 @@ enum push_default_type push_default = PUSH_DEFAULT_UNSPECIFIED; #endif enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE; int grafts_keep_true_parents; -int core_sparse_checkout_cone; int sparse_expect_files_outside_of_patterns; int merge_log_config = -1; int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */ diff --git a/environment.h b/environment.h index 6a30512f3c..00a5b332a0 100644 --- a/environment.h +++ b/environment.h @@ -160,7 +160,6 @@ extern int precomposed_unicode; extern int protect_hfs; extern int protect_ntfs; -extern int core_sparse_checkout_cone; extern int sparse_expect_files_outside_of_patterns; enum rebase_setup_type { diff --git a/repo-settings.c b/repo-settings.c index 9270cca561..eebc1f941d 100644 --- a/repo-settings.c +++ b/repo-settings.c @@ -82,6 +82,7 @@ void prepare_repo_settings(struct repository *r) r->settings.pack_use_bitmap_boundary_traversal); repo_cfg_bool(r, "core.usereplacerefs", &r->settings.read_replace_refs, 1); repo_cfg_bool(r, "core.sparsecheckout", &r->settings.sparse_checkout, 0); + repo_cfg_bool(r, "core.sparsecheckoutcone", &r->settings.sparse_checkout_cone, 0); /* * The GIT_TEST_MULTI_PACK_INDEX variable is special in that diff --git a/repo-settings.h b/repo-settings.h index 9caa7c57a3..443e1399da 100644 --- a/repo-settings.h +++ b/repo-settings.h @@ -67,7 +67,9 @@ struct repo_settings { unsigned long big_file_threshold; char *hooks_path; + int sparse_checkout; + int sparse_checkout_cone; }; #define REPO_SETTINGS_INIT { \ .shared_repository = -1, \ diff --git a/sparse-index.c b/sparse-index.c index 2428b20634..444da8a753 100644 --- a/sparse-index.c +++ b/sparse-index.c @@ -150,7 +150,7 @@ static int index_has_unmerged_entries(struct index_state *istate) int is_sparse_index_allowed(struct index_state *istate, int flags) { - if (!istate->repo->settings.sparse_checkout || !core_sparse_checkout_cone) + if (!istate->repo->settings.sparse_checkout || !istate->repo->settings.sparse_checkout_cone) return 0; if (!(flags & SPARSE_INDEX_MEMORY_ONLY)) {