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>
main
Olamide Caleb Bello 2026-06-02 18:09:20 +01:00 committed by Junio C Hamano
parent dfa01cee1c
commit c8a32140a7
3 changed files with 8 additions and 5 deletions

View 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;
}

View 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,

View 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)) {