Subject: [PATCH 3/3] repo-settings: lazy-load core.filemode in prepare_repo_settings

From: drona <[email-masked]>
Date: Mon, 9 Mar 2026 22:57:16 +0545

From: Dorna Raj Gyawali <[email-masked]>

- Removed direct handling of core.filemode from environment.c.
- Moved trust_executable_bit assignment to prepare_repo_settings() in repo-settings.c
  using repo_config_get_bool().
- Updated all references in apply.c, update-index.c, diff-lib.c, and read-cache.c
  to use the_repository->settings.trust_executable_bit.
- Ensures repository-scoped settings and preserves lazy-loading semantics.
- No changes needed in git_default_core_config().

Signed-off-by: Dorna Raj Gyawali <[email-masked]>
---
 environment.c   | 6 ------
 repo-settings.c | 3 +++
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/environment.c b/environment.c
index 9d12c5fa56..efec0758b7 100644
--- a/environment.c
+++ b/environment.c
@@ -302,12 +302,6 @@ int git_default_core_config(const char *var, const char *value,
 {
 	struct repo_config_values *cfg = repo_config_values(the_repository);
 
-	/* This needs a better name */
-	if (!strcmp(var, "core.filemode")) {
-		prepare_repo_settings(the_repository);
-		the_repository->settings.trust_executable_bit = git_config_bool(var, value);
-		return 0;
-	}
 	if (!strcmp(var, "core.trustctime")) {
 		trust_ctime = git_config_bool(var, value);
 		return 0;
diff --git a/repo-settings.c b/repo-settings.c
index 208e09ff17..0e44825a18 100644
--- a/repo-settings.c
+++ b/repo-settings.c
@@ -85,6 +85,9 @@ void prepare_repo_settings(struct repository *r)
 		      r->settings.pack_use_bitmap_boundary_traversal);
 	repo_cfg_bool(r, "core.usereplacerefs", &r->settings.read_replace_refs, 1);
 
+	/* Lazy-load core.filemode here */
+	repo_cfg_bool(r, "core.filemode", &r->settings.trust_executable_bit, 1);
+
 	/*
 	 * The GIT_TEST_MULTI_PACK_INDEX variable is special in that
 	 * either it *or* the config sets
-- 
2.43.0