environment: move "sparse_expect_files_outside_of_patterns" into `struct repo_config_values`

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>

Olamide Caleb Bello committed Jun 2, 2026 at 18:09 UTC c8a32140a7d76565a6d14e8d068e2a9b1562ac95
3 files changed +8 -5
environment.c
+4 -2
@@ -70,7 +70,6 @@ enum push_default_type push_default = PUSH_DEFAULT_UNSPECIFIED;
70 #endif
71 enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE;
72 int grafts_keep_true_parents;
73 -int sparse_expect_files_outside_of_patterns;
73 unsigned long pack_size_limit_cfg;
74
75 #ifndef PROTECT_HFS_DEFAULT
@@ -550,8 +549,10 @@ int git_default_core_config(const char *var, const char *value,
549
550 static int git_default_sparse_config(const char *var, const char *value)
551 {
552 + struct repo_config_values *cfg = repo_config_values(the_repository);
553 +
554 if (!strcmp(var, "sparse.expectfilesoutsideofpatterns")) {
554 - sparse_expect_files_outside_of_patterns = git_config_bool(var, value);
555 + cfg->sparse_expect_files_outside_of_patterns = git_config_bool(var, value);
556 return 0;
557 }
558
@@ -723,4 +724,5 @@ void repo_config_values_init(struct repo_config_values *cfg)
724 cfg->pack_compression_level = Z_DEFAULT_COMPRESSION;
725 cfg->precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
726 cfg->core_sparse_checkout_cone = 0;
727 + cfg->sparse_expect_files_outside_of_patterns = 0;
728 }
environment.h
+3 -2
@@ -98,6 +98,9 @@ struct repo_config_values {
98 int precomposed_unicode;
99 int core_sparse_checkout_cone;
100
101 + /* section "sparse" config values */
102 + int sparse_expect_files_outside_of_patterns;
103 +
104 /* section "branch" config values */
105 enum branch_track branch_track;
106 };
@@ -179,8 +182,6 @@ extern unsigned long pack_size_limit_cfg;
182 extern int protect_hfs;
183 extern int protect_ntfs;
184
182 -extern int sparse_expect_files_outside_of_patterns;
183 -
185 enum rebase_setup_type {
186 AUTOREBASE_NEVER = 0,
187 AUTOREBASE_LOCAL,
sparse-index.c
+1 -1
@@ -675,7 +675,7 @@ void clear_skip_worktree_from_present_files(struct index_state *istate)
675 struct repo_config_values *cfg = repo_config_values(the_repository);
676
677 if (!cfg->apply_sparse_checkout ||
678 - sparse_expect_files_outside_of_patterns)
678 + cfg->sparse_expect_files_outside_of_patterns)
679 return;
680
681 if (clear_skip_worktree_from_present_files_sparse(istate)) {