environment: move trust_executable_bit into repo_config_values

Move the global 'trust_executable_bit' configuration into the repository-specific 'repo_config_values' struct. To ensure code readability, the getter function 'repo_trust_executable_bit()' has been introduced. Callers access this configuration by passing in 'repo' when possible, and explicitly fall back to 'the_repository' the rest of time. Mentored-by: Christian Couder <christian.couder@gmail.com> Mentored-by: Ayush Chandekar <ayu.chandekar@gmail.com> Mentored-by: Olamide Caleb Bello <belkid98@gmail.com> Signed-off-by: Tian Yuchen <cat@malon.dev> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Tian Yuchen committed Jul 20, 2026 at 18:53 UTC 99c79dabb09a298863cd96398305d2957e60d022
5 files changed +19 -10
apply.c
+1 -1
@@ -3893,7 +3893,7 @@ static int check_preimage(struct apply_state *state,
3893 if (*ce && !(*ce)->ce_mode)
3894 BUG("ce_mode == 0 for path '%s'", old_name);
3895
3896 - if (trust_executable_bit || !S_ISREG(st->st_mode))
3896 + if (repo_trust_executable_bit(state->repo) || !S_ISREG(st->st_mode))
3897 st_mode = ce_mode_from_stat(state->repo, *ce, st->st_mode);
3898 else if (*ce)
3899 st_mode = (*ce)->ce_mode;
environment.c
+9 -2
@@ -41,7 +41,6 @@
41 static int pack_compression_seen;
42 static int zlib_compression_seen;
43
44 -int trust_executable_bit = 1;
44 int trust_ctime = 1;
45 int check_stat = 1;
46 int has_symlinks = 1;
@@ -142,6 +141,13 @@ int is_bare_repository(void)
141 return is_bare_repository_cfg && !repo_get_work_tree(the_repository);
142 }
143
144 +int repo_trust_executable_bit(struct repository *repo)
145 +{
146 + return repo->initialized
147 + ? repo_config_values(repo)->trust_executable_bit
148 + : 1;
149 +}
150 +
151 int have_git_dir(void)
152 {
153 return startup_info->have_repository
@@ -305,7 +311,7 @@ int git_default_core_config(const char *var, const char *value,
311
312 /* This needs a better name */
313 if (!strcmp(var, "core.filemode")) {
308 - trust_executable_bit = git_config_bool(var, value);
314 + cfg->trust_executable_bit = git_config_bool(var, value);
315 return 0;
316 }
317 if (!strcmp(var, "core.trustctime")) {
@@ -720,5 +726,6 @@ void repo_config_values_init(struct repo_config_values *cfg)
726 {
727 cfg->attributes_file = NULL;
728 cfg->apply_sparse_checkout = 0;
729 + cfg->trust_executable_bit = 1;
730 cfg->branch_track = BRANCH_TRACK_REMOTE;
731 }
environment.h
+3 -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_executable_bit;
95
96 /* section "branch" config values */
97 enum branch_track branch_track;
@@ -123,6 +124,8 @@ int git_default_config(const char *, const char *,
124 int git_default_core_config(const char *var, const char *value,
125 const struct config_context *ctx, void *cb);
126
127 +int repo_trust_executable_bit(struct repository *repo);
128 +
129 void repo_config_values_init(struct repo_config_values *cfg);
130
131 /*
@@ -158,7 +161,6 @@ int is_bare_repository(void);
161 extern char *git_work_tree_cfg;
162
163 /* Environment bits from configuration mechanism */
161 -extern int trust_executable_bit;
164 extern int trust_ctime;
165 extern int check_stat;
166 extern int has_symlinks;
read-cache.c
+3 -3
@@ -209,7 +209,7 @@ static unsigned int st_mode_from_ce(const struct cache_entry *ce)
209 case S_IFLNK:
210 return has_symlinks ? S_IFLNK : (S_IFREG | 0644);
211 case S_IFREG:
212 - return (ce->ce_mode & (trust_executable_bit ? 0755 : 0644)) | S_IFREG;
212 + return (ce->ce_mode & (repo_trust_executable_bit(the_repository) ? 0755 : 0644)) | S_IFREG;
213 case S_IFGITLINK:
214 return S_IFDIR | 0755;
215 case S_IFDIR:
@@ -319,7 +319,7 @@ static int ce_match_stat_basic(const struct cache_entry *ce, struct stat *st)
319 /* We consider only the owner x bit to be relevant for
320 * "mode changes"
321 */
322 - if (trust_executable_bit &&
322 + if (repo_trust_executable_bit(the_repository) &&
323 (0100 & (ce->ce_mode ^ st->st_mode)))
324 changed |= MODE_CHANGED;
325 break;
@@ -740,7 +740,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
740 ce->ce_flags |= CE_INTENT_TO_ADD;
741
742
743 - if (trust_executable_bit && has_symlinks) {
743 + if (repo_trust_executable_bit(istate->repo) && has_symlinks) {
744 ce->ce_mode = create_ce_mode(st_mode);
745 } else {
746 /* If there is an existing entry, pick the mode bits and type
read-cache.h
+3 -3
@@ -13,15 +13,15 @@
13 * This function handles degradation for filesystems that lack
14 * symlink support or reliable executable bits.
15 */
16 -static inline unsigned int ce_mode_from_stat(struct repository *repo UNUSED,
16 +static inline unsigned int ce_mode_from_stat(struct repository *repo,
17 const struct cache_entry *ce,
18 unsigned int mode)
19 {
20 - extern int trust_executable_bit, has_symlinks;
20 + extern int has_symlinks;
21 if (S_ISREG(mode) && !has_symlinks &&
22 ce && S_ISLNK(ce->ce_mode))
23 return ce->ce_mode;
24 - if (S_ISREG(mode) && !trust_executable_bit) {
24 + if (S_ISREG(mode) && !repo_trust_executable_bit(repo)) {
25 if (ce && S_ISREG(ce->ce_mode))
26 return ce->ce_mode;
27 return create_ce_mode(0666);