]> git.ipfire.org Git - thirdparty/git.git/commitdiff
environment: move "trust_ctime" into `struct repo_config_values`
authorOlamide Caleb Bello <belkid98@gmail.com>
Thu, 23 Apr 2026 16:54:25 +0000 (17:54 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sat, 25 Apr 2026 10:35:41 +0000 (19:35 +0900)
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 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>
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
statinfo.c

index fc3ed8bb1c7a66ae9be342c04700478a9af7f19d..0a9067729e5025c9591d48e7a8fe7dfd5421913b 100644 (file)
@@ -42,7 +42,6 @@ static int pack_compression_seen;
 static int zlib_compression_seen;
 
 int trust_executable_bit = 1;
-int trust_ctime = 1;
 int check_stat = 1;
 int has_symlinks = 1;
 int minimum_abbrev = 4, default_abbrev = -1;
@@ -309,7 +308,7 @@ int git_default_core_config(const char *var, const char *value,
                return 0;
        }
        if (!strcmp(var, "core.trustctime")) {
-               trust_ctime = git_config_bool(var, value);
+               cfg->trust_ctime = git_config_bool(var, value);
                return 0;
        }
        if (!strcmp(var, "core.checkstat")) {
@@ -721,4 +720,5 @@ void repo_config_values_init(struct repo_config_values *cfg)
        cfg->attributes_file = NULL;
        cfg->apply_sparse_checkout = 0;
        cfg->branch_track = BRANCH_TRACK_REMOTE;
+       cfg->trust_ctime = 1;
 }
index 123a71cdc8d14ed3386b925bac2827ff52f554b2..64d537686eed17dc962773fd8f8aaf24f764b2ae 100644 (file)
@@ -91,6 +91,7 @@ struct repo_config_values {
        /* section "core" config values */
        char *attributes_file;
        int apply_sparse_checkout;
+       int trust_ctime;
 
        /* section "branch" config values */
        enum branch_track branch_track;
@@ -161,7 +162,6 @@ extern char *git_work_tree_cfg;
 
 /* Environment bits from configuration mechanism */
 extern int trust_executable_bit;
-extern int trust_ctime;
 extern int check_stat;
 extern int has_symlinks;
 extern int minimum_abbrev, default_abbrev;
index 30a164b0e68cf82b1b18bd944ff347ab5dc3b7b9..4fc12053f40b20727cb97e15dac77a0bd30055f2 100644 (file)
@@ -3,6 +3,7 @@
 #include "git-compat-util.h"
 #include "environment.h"
 #include "statinfo.h"
+#include "repository.h"
 
 /*
  * Munge st_size into an unsigned int.
@@ -63,17 +64,18 @@ void fake_lstat_data(const struct stat_data *sd, struct stat *st)
 int match_stat_data(const struct stat_data *sd, struct stat *st)
 {
        int changed = 0;
+       struct repo_config_values *cfg = repo_config_values(the_repository);
 
        if (sd->sd_mtime.sec != (unsigned int)st->st_mtime)
                changed |= MTIME_CHANGED;
-       if (trust_ctime && check_stat &&
+       if (cfg->trust_ctime && check_stat &&
            sd->sd_ctime.sec != (unsigned int)st->st_ctime)
                changed |= CTIME_CHANGED;
 
 #ifdef USE_NSEC
        if (check_stat && sd->sd_mtime.nsec != ST_MTIME_NSEC(*st))
                changed |= MTIME_CHANGED;
-       if (trust_ctime && check_stat &&
+       if (cfg->trust_ctime && check_stat &&
            sd->sd_ctime.nsec != ST_CTIME_NSEC(*st))
                changed |= CTIME_CHANGED;
 #endif