]> git.ipfire.org Git - thirdparty/git.git/commitdiff
environment: move access to "core.sparsecheckoutcone" into repo_settings
authorAyush Chandekar <ayu.chandekar@gmail.com>
Tue, 17 Jun 2025 12:06:35 +0000 (17:36 +0530)
committerJunio C Hamano <gitster@pobox.com>
Tue, 17 Jun 2025 15:29:46 +0000 (08:29 -0700)
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 <christian.couder@gmail.com>
Mentored-by: Ghanshyam Thakkar <shyamthakkar001@gmail.com>
Signed-off-by: Ayush Chandekar <ayu.chandekar@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/grep.c
builtin/mv.c
builtin/sparse-checkout.c
config.c
dir.c
environment.c
environment.h
repo-settings.c
repo-settings.h
sparse-index.c

index 63342f5e36b63e3a2153b8f6b4871a3cd4315eaf..94d6245b8518c4d508a1c5cca1bc350c2d94f613 100644 (file)
@@ -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.
index 1e9f4d3eba1e21c4b75dc2f83653f93792210535..833fa761ddec8ba328514d9fc6a2303bd074f9ca 100644 (file)
@@ -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 (<source> is out-of-cone and
index 869d574a03e27d3ae785738a1c9694763ebd32bc..e65a62f2507a7dc8ebfd97d445a2cec99893ae0b 100644 (file)
@@ -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);
index 8fd4dd8c81d06417180d10500d32d83cdccd94a3..707fe0707a342ab72d9efa7e0d68827a4e037751 100644 (file)
--- 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 8f0f7ca8a4a1f4256c6e42fdc7ff0c2496694375..8378996b72d4272dfaee47de53466f3f009dd78c 100644 (file)
--- 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);
index a379a9149e4a9a0d371dc1cc50c87a4968cb0c15..7d46b807112eb48871b9ec0c6be16da10cbfb1a7 100644 (file)
@@ -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() */
index 6a30512f3cf98a336b4db3d2085d44100381c4e2..00a5b332a024e11152fd12a873a1550189cdf924 100644 (file)
@@ -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 {
index 9270cca561ef6a76e1839f1fdfeb034d34d8ce82..eebc1f941d9b831d4223fd0001680a832167ae9d 100644 (file)
@@ -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
index 9caa7c57a3924d9bb03e33142c3e17beece1fa10..443e1399daf1fb5418bd7b7167e032857c095022 100644 (file)
@@ -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, \
index 2428b20634ca33fb7a997b6971476d1e42552fba..444da8a75304742bd757e0295dd5b0129cc6e527 100644 (file)
@@ -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)) {