environment: move "trust_ctime" into `struct repo_config_values`

The `core.trustctime` configuration is currently stored in the global variable `trust_ctime`, which makes it shared across repository instances in a single process. Store it instead in `repo_config_values`, where eagerly‑parsed repository configuration lives. `core.trustctime` is parsed eagerly because it is used in low‑level stat‑matching functions (`match_stat_data()`), where a lazy parse could cause unexpected fatal errors, result in a performance regression and complicate libification efforts. This preserves that 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> 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 18684282df3e05db3ed9b3cdafc86c97285e4fd4
3 files changed +7 -5
environment.c
+2 -2
@@ -42,7 +42,6 @@ static int pack_compression_seen;
42 static int zlib_compression_seen;
43
44 int trust_executable_bit = 1;
45 -int trust_ctime = 1;
45 int check_stat = 1;
46 int has_symlinks = 1;
47 int minimum_abbrev = 4, default_abbrev = -1;
@@ -309,7 +308,7 @@ int git_default_core_config(const char *var, const char *value,
308 return 0;
309 }
310 if (!strcmp(var, "core.trustctime")) {
312 - trust_ctime = git_config_bool(var, value);
311 + cfg->trust_ctime = git_config_bool(var, value);
312 return 0;
313 }
314 if (!strcmp(var, "core.checkstat")) {
@@ -721,4 +720,5 @@ void repo_config_values_init(struct repo_config_values *cfg)
720 cfg->attributes_file = NULL;
721 cfg->apply_sparse_checkout = 0;
722 cfg->branch_track = BRANCH_TRACK_REMOTE;
723 + cfg->trust_ctime = 1;
724 }
environment.h
+1 -1
@@ -91,6 +91,7 @@ struct repo_config_values {
91 /* section "core" config values */
92 char *attributes_file;
93 int apply_sparse_checkout;
94 + int trust_ctime;
95
96 /* section "branch" config values */
97 enum branch_track branch_track;
@@ -161,7 +162,6 @@ extern char *git_work_tree_cfg;
162
163 /* Environment bits from configuration mechanism */
164 extern int trust_executable_bit;
164 -extern int trust_ctime;
165 extern int check_stat;
166 extern int has_symlinks;
167 extern int minimum_abbrev, default_abbrev;
statinfo.c
+4 -2
@@ -3,6 +3,7 @@
3 #include "git-compat-util.h"
4 #include "environment.h"
5 #include "statinfo.h"
6 +#include "repository.h"
7
8 /*
9 * Munge st_size into an unsigned int.
@@ -63,17 +64,18 @@ void fake_lstat_data(const struct stat_data *sd, struct stat *st)
64 int match_stat_data(const struct stat_data *sd, struct stat *st)
65 {
66 int changed = 0;
67 + struct repo_config_values *cfg = repo_config_values(the_repository);
68
69 if (sd->sd_mtime.sec != (unsigned int)st->st_mtime)
70 changed |= MTIME_CHANGED;
69 - if (trust_ctime && check_stat &&
71 + if (cfg->trust_ctime && check_stat &&
72 sd->sd_ctime.sec != (unsigned int)st->st_ctime)
73 changed |= CTIME_CHANGED;
74
75 #ifdef USE_NSEC
76 if (check_stat && sd->sd_mtime.nsec != ST_MTIME_NSEC(*st))
77 changed |= MTIME_CHANGED;
76 - if (trust_ctime && check_stat &&
78 + if (cfg->trust_ctime && check_stat &&
79 sd->sd_ctime.nsec != ST_CTIME_NSEC(*st))
80 changed |= CTIME_CHANGED;
81 #endif