]> git.ipfire.org Git - thirdparty/git.git/commitdiff
environment: move trust_executable_bit into repo_config_values
authorTian Yuchen <cat@malon.dev>
Mon, 20 Jul 2026 10:53:34 +0000 (18:53 +0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 20 Jul 2026 14:37:05 +0000 (07:37 -0700)
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>
apply.c
environment.c
environment.h
read-cache.c
read-cache.h

diff --git a/apply.c b/apply.c
index 26286eb57b4f52bbd3b9955071c0d52fe2c7dda0..edb1502414e4be33d176e2a2c5e6e9a6c6cfb373 100644 (file)
--- a/apply.c
+++ b/apply.c
@@ -3893,7 +3893,7 @@ static int check_preimage(struct apply_state *state,
                if (*ce && !(*ce)->ce_mode)
                        BUG("ce_mode == 0 for path '%s'", old_name);
 
-               if (trust_executable_bit || !S_ISREG(st->st_mode))
+               if (repo_trust_executable_bit(state->repo) || !S_ISREG(st->st_mode))
                        st_mode = ce_mode_from_stat(state->repo, *ce, st->st_mode);
                else if (*ce)
                        st_mode = (*ce)->ce_mode;
index fc3ed8bb1c7a66ae9be342c04700478a9af7f19d..32b110c40505bee6a4bdd0723a7113e906ede566 100644 (file)
@@ -41,7 +41,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;
@@ -142,6 +141,13 @@ int is_bare_repository(void)
        return is_bare_repository_cfg && !repo_get_work_tree(the_repository);
 }
 
+int repo_trust_executable_bit(struct repository *repo)
+{
+       return repo->initialized
+               ? repo_config_values(repo)->trust_executable_bit
+               : 1;
+}
+
 int have_git_dir(void)
 {
        return startup_info->have_repository
@@ -305,7 +311,7 @@ int git_default_core_config(const char *var, const char *value,
 
        /* This needs a better name */
        if (!strcmp(var, "core.filemode")) {
-               trust_executable_bit = git_config_bool(var, value);
+               cfg->trust_executable_bit = git_config_bool(var, value);
                return 0;
        }
        if (!strcmp(var, "core.trustctime")) {
@@ -720,5 +726,6 @@ void repo_config_values_init(struct repo_config_values *cfg)
 {
        cfg->attributes_file = NULL;
        cfg->apply_sparse_checkout = 0;
+       cfg->trust_executable_bit = 1;
        cfg->branch_track = BRANCH_TRACK_REMOTE;
 }
index 9eb97b3869c9b1bf9624042dc9435e585aaf11af..c15456fc0d0b39f49b5a26ba8f1b88181f37c881 100644 (file)
@@ -91,6 +91,7 @@ struct repo_config_values {
        /* section "core" config values */
        char *attributes_file;
        int apply_sparse_checkout;
+       int trust_executable_bit;
 
        /* section "branch" config values */
        enum branch_track branch_track;
@@ -123,6 +124,8 @@ int git_default_config(const char *, const char *,
 int git_default_core_config(const char *var, const char *value,
                            const struct config_context *ctx, void *cb);
 
+int repo_trust_executable_bit(struct repository *repo);
+
 void repo_config_values_init(struct repo_config_values *cfg);
 
 /*
@@ -158,7 +161,6 @@ int is_bare_repository(void);
 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;
index a9f059174305eb402540f8b67bf105783395c09f..90789ff049edd0499dd7fc1a23a7f74291273604 100644 (file)
@@ -209,7 +209,7 @@ static unsigned int st_mode_from_ce(const struct cache_entry *ce)
        case S_IFLNK:
                return has_symlinks ? S_IFLNK : (S_IFREG | 0644);
        case S_IFREG:
-               return (ce->ce_mode & (trust_executable_bit ? 0755 : 0644)) | S_IFREG;
+               return (ce->ce_mode & (repo_trust_executable_bit(the_repository) ? 0755 : 0644)) | S_IFREG;
        case S_IFGITLINK:
                return S_IFDIR | 0755;
        case S_IFDIR:
@@ -319,7 +319,7 @@ static int ce_match_stat_basic(const struct cache_entry *ce, struct stat *st)
                /* We consider only the owner x bit to be relevant for
                 * "mode changes"
                 */
-               if (trust_executable_bit &&
+               if (repo_trust_executable_bit(the_repository) &&
                    (0100 & (ce->ce_mode ^ st->st_mode)))
                        changed |= MODE_CHANGED;
                break;
@@ -740,7 +740,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
                ce->ce_flags |= CE_INTENT_TO_ADD;
 
 
-       if (trust_executable_bit && has_symlinks) {
+       if (repo_trust_executable_bit(istate->repo) && has_symlinks) {
                ce->ce_mode = create_ce_mode(st_mode);
        } else {
                /* If there is an existing entry, pick the mode bits and type
index af8c657ecbeb48e8c520ba5bd062b7d7bd895d73..4b54cfc57c8de0c751491db83862aec2a37736ed 100644 (file)
  * This function handles degradation for filesystems that lack
  * symlink support or reliable executable bits.
  */
-static inline unsigned int ce_mode_from_stat(struct repository *repo UNUSED,
+static inline unsigned int ce_mode_from_stat(struct repository *repo,
                                             const struct cache_entry *ce,
                                             unsigned int mode)
 {
-       extern int trust_executable_bit, has_symlinks;
+       extern int has_symlinks;
        if (S_ISREG(mode) && !has_symlinks &&
            ce && S_ISLNK(ce->ce_mode))
                return ce->ce_mode;
-       if (S_ISREG(mode) && !trust_executable_bit) {
+       if (S_ISREG(mode) && !repo_trust_executable_bit(repo)) {
                if (ce && S_ISREG(ce->ce_mode))
                        return ce->ce_mode;
                return create_ce_mode(0666);