]> git.ipfire.org Git - thirdparty/git.git/commitdiff
env: move "sparse_expect_files_outside_of_patterns" into `repo_config_values`
authorOlamide Caleb Bello <belkid98@gmail.com>
Thu, 23 Apr 2026 16:54:31 +0000 (17:54 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sat, 25 Apr 2026 10:35:41 +0000 (19:35 +0900)
The `core.sparseCheckoutExpectFilesOutsideOfPatterns` configuration was
previously stored in a global `int` variable, making it shared across
repository instances and risking cross‑repository state leakage.

Store it instead in `repo_config_values`, where eagerly‑parsed
repository configuration lives. This option is parsed eagerly because
it controls how sparse‑checkout paths are interpreted – a fundamental
behavior that many commands rely on; a lazy parse could cause
inconsistent sparse‑checkout handling and complicate libification.
This preserves the existing behavior while tying the value to the
repository from which it was read, avoiding cross‑repository state
leakage and continuing the effort to reduce reliance on global
configuration state.

Update all references to use `repo_config_values()`.

Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
Signed-off-by: Olamide Caleb Bello <belkid98@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
environment.c
environment.h
sparse-index.c

index b0e873e9f5b9011627410df92847ade0271fde51..57587ede56a1be40fb59c6dac825c96bd41eaaee 100644 (file)
@@ -70,7 +70,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 sparse_expect_files_outside_of_patterns;
 unsigned long pack_size_limit_cfg;
 
 #ifndef PROTECT_HFS_DEFAULT
@@ -550,8 +549,10 @@ int git_default_core_config(const char *var, const char *value,
 
 static int git_default_sparse_config(const char *var, const char *value)
 {
+       struct repo_config_values *cfg = repo_config_values(the_repository);
+
        if (!strcmp(var, "sparse.expectfilesoutsideofpatterns")) {
-               sparse_expect_files_outside_of_patterns = git_config_bool(var, value);
+               cfg->sparse_expect_files_outside_of_patterns = git_config_bool(var, value);
                return 0;
        }
 
@@ -723,4 +724,5 @@ void repo_config_values_init(struct repo_config_values *cfg)
        cfg->pack_compression_level = Z_DEFAULT_COMPRESSION;
        cfg->precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
        cfg->core_sparse_checkout_cone = 0;
+       cfg->sparse_expect_files_outside_of_patterns = 0;
 }
index befad9a38876e9ce32c622eeabbfa48ddbadc1e1..609cdaa07fc8ca5a8630a55fbc6dc38c973a13b4 100644 (file)
@@ -98,6 +98,9 @@ struct repo_config_values {
        int precomposed_unicode;
        int core_sparse_checkout_cone;
 
+       /* section "sparse" config values */
+       int sparse_expect_files_outside_of_patterns;
+
        /* section "branch" config values */
        enum branch_track branch_track;
 };
@@ -179,8 +182,6 @@ extern unsigned long pack_size_limit_cfg;
 extern int protect_hfs;
 extern int protect_ntfs;
 
-extern int sparse_expect_files_outside_of_patterns;
-
 enum rebase_setup_type {
        AUTOREBASE_NEVER = 0,
        AUTOREBASE_LOCAL,
index 53cb8d64fc9b2cf792a455d1d4c07cff3e2ae026..1ed769b78d8de19a3ea1e0aaa019f81b8a8fe023 100644 (file)
@@ -675,7 +675,7 @@ void clear_skip_worktree_from_present_files(struct index_state *istate)
        struct repo_config_values *cfg = repo_config_values(the_repository);
 
        if (!cfg->apply_sparse_checkout ||
-           sparse_expect_files_outside_of_patterns)
+           cfg->sparse_expect_files_outside_of_patterns)
                return;
 
        if (clear_skip_worktree_from_present_files_sparse(istate)) {