Skip to contentSkip to conversation

Refactor 'trust_executable_bit' to repository-scoped setting

PATCH In review drona 4 participants 11 messages Mar 1 – Mar 9 1 message not in the archive

lore
Share & tools
lore

drona

author
#0 lore raw

PATCH 1/1 Refactor 'trust_executable_bit' to repository-scoped setting

From: Dorna Raj Gyawali <[email protected]>

Currently, 'trust_executable_bit' is a global variable in environment.c, which controls how executable bits are interpreted when creating/updating cache entries.

This patch moves 'trust_executable_bit' into 'struct repo_settings', making it a repository-scoped configuration. All references in files have been updated to use 'the_repository->settings.trust_executable_bit'.

Why this is a good candidate:
- It's a self-contained global variable that only affects file mode logic.
- Low risk: changes only impact mode calculations and related apply/update operations.
- Makes Git codebase more maintainable and prepares for future multi-repo support.

- Manual sanity check with a test repo confirms executable bits behave correctly.

---
 apply.c                |  4 ++--
 builtin/update-index.c |  2 +-
 diff-lib.c             | 10 +++++-----
 environment.c          |  3 +--
 environment.h          |  1 -
 read-cache.c           | 10 +++++-----
 read-cache.h           | 11 +++++++----
 repo-settings.h        |  6 +++++-
 8 files changed, 26 insertions(+), 21 deletions(-)
apply.c +2 -2
index d044c95d50..2bcb22a4bc 100644
@@ -3838,8 +3838,8 @@ 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))
-			st_mode = ce_mode_from_stat(*ce, st->st_mode);
+		if (the_repository->settings.trust_executable_bit  || !S_ISREG(st->st_mode))
+			st_mode = ce_mode_from_stat(the_repository, *ce, st->st_mode);
 		else if (*ce)
 			st_mode = (*ce)->ce_mode;
 		else
builtin/update-index.c +1 -1
index 8a5907767b..7917bd286f 100644
@@ -293,7 +293,7 @@ static int add_one_path(const struct cache_entry *old, const char *path, int len
 	ce->ce_flags = create_ce_flags(0);
 	ce->ce_namelen = len;
 	fill_stat_cache_info(the_repository->index, ce, st);
-	ce->ce_mode = ce_mode_from_stat(old, st->st_mode);
+	ce->ce_mode = ce_mode_from_stat(the_repository, old, st->st_mode);
 
 	if (index_path(the_repository->index, &ce->oid, path, st,
 		       info_only ? 0 : INDEX_WRITE_OBJECT)) {
diff-lib.c +5 -5
index ae91027a02..894358c8b0 100644
@@ -160,7 +160,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
 
 			changed = check_removed(ce, &st);
 			if (!changed)
-				wt_mode = ce_mode_from_stat(ce, st.st_mode);
+				wt_mode = ce_mode_from_stat(the_repository, ce, st.st_mode);
 			else {
 				if (changed < 0) {
 					perror(ce->name);
@@ -193,7 +193,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
 					num_compare_stages++;
 					oidcpy(&dpath->parent[stage - 2].oid,
 					       &nce->oid);
-					dpath->parent[stage-2].mode = ce_mode_from_stat(nce, mode);
+					dpath->parent[stage-2].mode = ce_mode_from_stat(the_repository,nce, mode);
 					dpath->parent[stage-2].status =
 						DIFF_STATUS_MODIFIED;
 				}
@@ -262,7 +262,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
 				continue;
 			} else if (revs->diffopt.ita_invisible_in_index &&
 				   ce_intent_to_add(ce)) {
-				newmode = ce_mode_from_stat(ce, st.st_mode);
+				newmode = ce_mode_from_stat(the_repository, ce, st.st_mode);
 				diff_addremove(&revs->diffopt, '+', newmode,
 					       null_oid(the_hash_algo), 0, ce->name, 0);
 				continue;
@@ -270,7 +270,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
 
 			changed = match_stat_with_submodule(&revs->diffopt, ce, &st,
 							    ce_option, &dirty_submodule);
-			newmode = ce_mode_from_stat(ce, st.st_mode);
+			newmode = ce_mode_from_stat(the_repository, ce, st.st_mode);
 		}
 
 		if (!changed && !dirty_submodule) {
@@ -338,7 +338,7 @@ static int get_stat_data(const struct cache_entry *ce,
 		changed = match_stat_with_submodule(diffopt, ce, &st,
 						    0, dirty_submodule);
 		if (changed) {
-			mode = ce_mode_from_stat(ce, st.st_mode);
+			mode = ce_mode_from_stat(the_repository, ce, st.st_mode);
 			oid = null_oid(the_hash_algo);
 		}
 	}
environment.c +1 -2
index 0026eb2274..861ef084dc 100644
@@ -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;
@@ -306,7 +305,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);
+		the_repository->settings.trust_executable_bit = git_config_bool(var, value);
 		return 0;
 	}
 	if (!strcmp(var, "core.trustctime")) {
environment.h +0 -1
index 27f657af04..7f3437f369 100644
@@ -144,7 +144,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;
read-cache.c +5 -5
index 0c07c3aef7..b1fcb9e1a0 100644
@@ -201,13 +201,13 @@ void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, st
 
 static unsigned int st_mode_from_ce(const struct cache_entry *ce)
 {
-	extern int trust_executable_bit, has_symlinks;
+	extern int has_symlinks;
 
 	switch (ce->ce_mode & S_IFMT) {
 	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 & (the_repository->settings.trust_executable_bit ? 0755 : 0644)) | S_IFREG;
 	case S_IFGITLINK:
 		return S_IFDIR | 0755;
 	case S_IFDIR:
@@ -317,7 +317,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 (the_repository->settings.trust_executable_bit &&
 		    (0100 & (ce->ce_mode ^ st->st_mode)))
 			changed |= MODE_CHANGED;
 		break;
@@ -738,7 +738,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 (the_repository->settings.trust_executable_bit && has_symlinks) {
 		ce->ce_mode = create_ce_mode(st_mode);
 	} else {
 		/* If there is an existing entry, pick the mode bits and type
@@ -748,7 +748,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
 		int pos = index_name_pos_also_unmerged(istate, path, namelen);
 
 		ent = (0 <= pos) ? istate->cache[pos] : NULL;
-		ce->ce_mode = ce_mode_from_stat(ent, st_mode);
+		ce->ce_mode = ce_mode_from_stat(the_repository, ent, st_mode);
 	}
 
 	/* When core.ignorecase=true, determine if a directory of the same name but differing
read-cache.h +7 -4
index 043da1f1aa..4e88d476aa 100644
@@ -4,15 +4,18 @@
 #include "read-cache-ll.h"
 #include "object.h"
 #include "pathspec.h"
+#include "repository.h"
 
-static inline unsigned int ce_mode_from_stat(const struct cache_entry *ce,
-					     unsigned int mode)
+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 (!has_symlinks && S_ISREG(mode) &&
 	    ce && S_ISLNK(ce->ce_mode))
 		return ce->ce_mode;
-	if (!trust_executable_bit && S_ISREG(mode)) {
+	if (!repo->settings.trust_executable_bit && S_ISREG(mode)) {
 		if (ce && S_ISREG(ce->ce_mode))
 			return ce->ce_mode;
 		return create_ce_mode(0666);
repo-settings.h +5 -1
index cad9c3f0cc..a12e763f4f 100644
@@ -48,7 +48,10 @@ struct repo_settings {
 	 * replace_refs_enabled() for more details.
 	 */
 	int read_replace_refs;
-
+	
+	/* Whether to trust executable bit on filesystem (core.filemode) */
+	int trust_executable_bit;
+	
 	struct fsmonitor_settings *fsmonitor; /* lazily loaded */
 
 	int index_version;
@@ -74,6 +77,7 @@ struct repo_settings {
 #define REPO_SETTINGS_INIT { \
 	.shared_repository = -1, \
 	.index_version = -1, \
+	.trust_executable_bit = 1, \
 	.core_untracked_cache = UNTRACKED_CACHE_KEEP, \
 	.fetch_negotiation_algorithm = FETCH_NEGOTIATION_CONSECUTIVE, \
 	.warn_ambiguous_refs = -1, \
Signature · 1 line
2.43.0
#1 lore raw

Hi drona,

Quoted 3 lines · drona

This patch moves 'trust_executable_bit' into 'struct repo_settings', making it a repository-scoped configuration. All references in files have been updated to use 'the_repository->settings.trust_executable_bit'.

The original intent of this patch should be sound.

Quoted 26 lines

Why this is a good candidate:
- It's a self-contained global variable that only affects file mode logic.
- Low risk: changes only impact mode calculations and related apply/update operations.
- Makes Git codebase more maintainable and prepares for future multi-repo support.

- Manual sanity check with a test repo confirms executable bits behave correctly.

---
  apply.c                |  4 ++--
  builtin/update-index.c |  2 +-
  diff-lib.c             | 10 +++++-----
  environment.c          |  3 +--
  environment.h          |  1 -
  read-cache.c           | 10 +++++-----
  read-cache.h           | 11 +++++++----
  repo-settings.h        |  6 +++++-
  8 files changed, 26 insertions(+), 21 deletions(-)
apply.c +0 -0
index d044c95d50..2bcb22a4bc 100644

apply.c static int check_preimage(struct apply_state *state, · line 3845

Quoted 10 lines
apply.c +2 -2
@@ -3838,8 +3838,8 @@ 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))
-			st_mode = ce_mode_from_stat(*ce, st->st_mode);
+		if (the_repository->settings.trust_executable_bit  || !S_ISREG(st->st_mode))
+			st_mode = ce_mode_from_stat(the_repository, *ce, st->st_mode);
  		else if (*ce)
  			st_mode = (*ce)->ce_mode;
  		else

You can run git diff --check before committing. There's an extra space here.

Quoted 67 lines
builtin/update-index.c +1 -1
index 8a5907767b..7917bd286f 100644
@@ -293,7 +293,7 @@ static int add_one_path(const struct cache_entry *old, const char *path, int len
  	ce->ce_flags = create_ce_flags(0);
  	ce->ce_namelen = len;
  	fill_stat_cache_info(the_repository->index, ce, st);
-	ce->ce_mode = ce_mode_from_stat(old, st->st_mode);
+	ce->ce_mode = ce_mode_from_stat(the_repository, old, st->st_mode);
 
  	if (index_path(the_repository->index, &ce->oid, path, st,
  		       info_only ? 0 : INDEX_WRITE_OBJECT)) {
diff-lib.c +5 -5
index ae91027a02..894358c8b0 100644
@@ -160,7 +160,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
 
  			changed = check_removed(ce, &st);
  			if (!changed)
-				wt_mode = ce_mode_from_stat(ce, st.st_mode);
+				wt_mode = ce_mode_from_stat(the_repository, ce, st.st_mode);
  			else {
  				if (changed < 0) {
  					perror(ce->name);
@@ -193,7 +193,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
  					num_compare_stages++;
  					oidcpy(&dpath->parent[stage - 2].oid,
  					       &nce->oid);
-					dpath->parent[stage-2].mode = ce_mode_from_stat(nce, mode);
+					dpath->parent[stage-2].mode = ce_mode_from_stat(the_repository,nce, mode);
  					dpath->parent[stage-2].status =
  						DIFF_STATUS_MODIFIED;
  				}
@@ -262,7 +262,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
  				continue;
  			} else if (revs->diffopt.ita_invisible_in_index &&
  				   ce_intent_to_add(ce)) {
-				newmode = ce_mode_from_stat(ce, st.st_mode);
+				newmode = ce_mode_from_stat(the_repository, ce, st.st_mode);
  				diff_addremove(&revs->diffopt, '+', newmode,
  					       null_oid(the_hash_algo), 0, ce->name, 0);
  				continue;
@@ -270,7 +270,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
 
  			changed = match_stat_with_submodule(&revs->diffopt, ce, &st,
  							    ce_option, &dirty_submodule);
-			newmode = ce_mode_from_stat(ce, st.st_mode);
+			newmode = ce_mode_from_stat(the_repository, ce, st.st_mode);
  		}
 
  		if (!changed && !dirty_submodule) {
@@ -338,7 +338,7 @@ static int get_stat_data(const struct cache_entry *ce,
  		changed = match_stat_with_submodule(diffopt, ce, &st,
  						    0, dirty_submodule);
  		if (changed) {
-			mode = ce_mode_from_stat(ce, st.st_mode);
+			mode = ce_mode_from_stat(the_repository, ce, st.st_mode);
  			oid = null_oid(the_hash_algo);
  		}
  	}
environment.c +0 -0
index 0026eb2274..861ef084dc 100644

environment.c line 46

Quoted 7 lines
environment.c +0 -1
@@ -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;

But the_repository itself is a global variable, isn't it?

If you understand what “removing global variables” means, you should grasp the direction we're heading:

	passing global variables -> passing context

For example, in

environment.c void run_diff_files(struct rev_info *revs, unsigned int option) · line 163

Quoted 6 lines
environment.c +1 -1
@@ -160,7 +160,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
 
  			changed = check_removed(ce, &st);
  			if (!changed)
-				wt_mode = ce_mode_from_stat(ce, st.st_mode);
+				wt_mode = ce_mode_from_stat(the_repository, ce, st.st_mode);
				perror(ce->name);

A more appropriate of passing value could be something like:

wt_mode = ce_mode_from_stat(revs->repo, ce, st.st_mode)

environment.c int git_default_core_config(const char *var, const char *value, · line 311

Quoted 9 lines
environment.c +1 -1
@@ -306,7 +305,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);
+		the_repository->settings.trust_executable_bit = git_config_bool(var, value);
  		return 0;
  	}
  	if (!strcmp(var, "core.trustctime")) {

I didn't think it through, but my gut tells me there might be some weird variable overwriting issues here.

But more importantly, I feel that the changes here somewhat undermine lazy loading behavior. Variables in repo_settings are lazy-loaded, meaning you cannot read their values via actions like repo->settings.trust_executable_bit because they are not loaded until needed. The function prepare_repo_settings(repo) should be called to load the values.

However, the change here appears to manually assign a value during the global config parsing phase. I believe this is incorrect.

For more information you can look through https://lore.kernel.org/all/48821a3848bef25c13038be8377ad73e7c17a924.1771258573.git.belkid98@gmail.com/

Regards,

Yuchen

author
#2 lore raw

PATCH 1/1 Make 'trust_executable_bit' repository-scoped

In reply to drona

From: Dorna Raj Gyawali <[email protected]>

- Moved 'trust_executable_bit' from a global variable to struct repo_settings.
- Updated all calls to ce_mode_from_stat() to pass the repository.
- Updated environment.c to set the repository's trust_executable_bit when reading core.filemode.
- Fixed apply.c, update-index.c, diff-lib.c, and read-cache.c to reference the_repository->settings.trust_executable_bit.
- Added prepare_repo_settings() call in diff-lib.c to ensure repo settings are loaded.

This change makes executable-bit handling repository-scoped and prepares the code for multi-repo support.

---
 apply.c       | 2 +-
 diff-lib.c    | 9 +++++----
 environment.c | 1 +
 3 files changed, 7 insertions(+), 5 deletions(-)
apply.c +1 -1
index f9fd7b0030..1677ddca15 100644
@@ -3838,7 +3838,7 @@ static int check_preimage(struct apply_state *state,
 		if (*ce && !(*ce)->ce_mode)
 			BUG("ce_mode == 0 for path '%s'", old_name);
 
-		if (the_repository->settings.trust_executable_bit  || !S_ISREG(st->st_mode))
+		if (the_repository->settings.trust_executable_bit || !S_ISREG(st->st_mode))
 			st_mode = ce_mode_from_stat(the_repository, *ce, st->st_mode);
 		else if (*ce)
 			st_mode = (*ce)->ce_mode;
diff-lib.c +5 -4
index 894358c8b0..276efef407 100644
@@ -108,6 +108,7 @@ static int match_stat_with_submodule(struct diff_options *diffopt,
 
 void run_diff_files(struct rev_info *revs, unsigned int option)
 {
+	prepare_repo_settings(revs->repo);
 	int entries, i;
 	int diff_unmerged_stage = revs->max_count;
 	unsigned ce_option = ((option & DIFF_RACY_IS_MODIFIED)
@@ -160,7 +161,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
 
 			changed = check_removed(ce, &st);
 			if (!changed)
-				wt_mode = ce_mode_from_stat(the_repository, ce, st.st_mode);
+				wt_mode = ce_mode_from_stat(revs->repo, ce, st.st_mode);
 			else {
 				if (changed < 0) {
 					perror(ce->name);
@@ -193,7 +194,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
 					num_compare_stages++;
 					oidcpy(&dpath->parent[stage - 2].oid,
 					       &nce->oid);
-					dpath->parent[stage-2].mode = ce_mode_from_stat(the_repository,nce, mode);
+					dpath->parent[stage-2].mode = ce_mode_from_stat(revs->repo, nce, mode);
 					dpath->parent[stage-2].status =
 						DIFF_STATUS_MODIFIED;
 				}
@@ -262,7 +263,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
 				continue;
 			} else if (revs->diffopt.ita_invisible_in_index &&
 				   ce_intent_to_add(ce)) {
-				newmode = ce_mode_from_stat(the_repository, ce, st.st_mode);
+				newmode = ce_mode_from_stat(revs->repo, ce, st.st_mode);
 				diff_addremove(&revs->diffopt, '+', newmode,
 					       null_oid(the_hash_algo), 0, ce->name, 0);
 				continue;
@@ -270,7 +271,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
 
 			changed = match_stat_with_submodule(&revs->diffopt, ce, &st,
 							    ce_option, &dirty_submodule);
-			newmode = ce_mode_from_stat(the_repository, ce, st.st_mode);
+			newmode = ce_mode_from_stat(revs->repo, ce, st.st_mode);
 		}
 
 		if (!changed && !dirty_submodule) {
environment.c +1 -0
index 591683ce8c..9d12c5fa56 100644
@@ -304,6 +304,7 @@ int git_default_core_config(const char *var, const char *value,
 
 	/* 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;
 	}
Signature · 1 line
2.43.0
author
#3 lore raw

PATCH v2 1/1 Make 'trust_executable_bit' repository-scoped

In reply to drona

From: Dorna Raj Gyawali <[email protected]>

- Moved 'trust_executable_bit' from a global variable to struct repo_settings.
- Updated all calls to ce_mode_from_stat() to pass the repository.
- Updated environment.c to set the repository's trust_executable_bit when reading core.filemode.
- Fixed apply.c, update-index.c, diff-lib.c, and read-cache.c to reference the_repository->settings.trust_executable_bit.
- Added prepare_repo_settings() call in diff-lib.c to ensure repo settings are loaded.

This change makes executable-bit handling repository-scoped and prepares the code for multi-repo support.

---
 apply.c       | 2 +-
 diff-lib.c    | 9 +++++----
 environment.c | 1 +
 3 files changed, 7 insertions(+), 5 deletions(-)
apply.c +1 -1
index f9fd7b0030..1677ddca15 100644
@@ -3838,7 +3838,7 @@ static int check_preimage(struct apply_state *state,
 		if (*ce && !(*ce)->ce_mode)
 			BUG("ce_mode == 0 for path '%s'", old_name);
 
-		if (the_repository->settings.trust_executable_bit  || !S_ISREG(st->st_mode))
+		if (the_repository->settings.trust_executable_bit || !S_ISREG(st->st_mode))
 			st_mode = ce_mode_from_stat(the_repository, *ce, st->st_mode);
 		else if (*ce)
 			st_mode = (*ce)->ce_mode;
diff-lib.c +5 -4
index 894358c8b0..276efef407 100644
@@ -108,6 +108,7 @@ static int match_stat_with_submodule(struct diff_options *diffopt,
 
 void run_diff_files(struct rev_info *revs, unsigned int option)
 {
+	prepare_repo_settings(revs->repo);
 	int entries, i;
 	int diff_unmerged_stage = revs->max_count;
 	unsigned ce_option = ((option & DIFF_RACY_IS_MODIFIED)
@@ -160,7 +161,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
 
 			changed = check_removed(ce, &st);
 			if (!changed)
-				wt_mode = ce_mode_from_stat(the_repository, ce, st.st_mode);
+				wt_mode = ce_mode_from_stat(revs->repo, ce, st.st_mode);
 			else {
 				if (changed < 0) {
 					perror(ce->name);
@@ -193,7 +194,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
 					num_compare_stages++;
 					oidcpy(&dpath->parent[stage - 2].oid,
 					       &nce->oid);
-					dpath->parent[stage-2].mode = ce_mode_from_stat(the_repository,nce, mode);
+					dpath->parent[stage-2].mode = ce_mode_from_stat(revs->repo, nce, mode);
 					dpath->parent[stage-2].status =
 						DIFF_STATUS_MODIFIED;
 				}
@@ -262,7 +263,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
 				continue;
 			} else if (revs->diffopt.ita_invisible_in_index &&
 				   ce_intent_to_add(ce)) {
-				newmode = ce_mode_from_stat(the_repository, ce, st.st_mode);
+				newmode = ce_mode_from_stat(revs->repo, ce, st.st_mode);
 				diff_addremove(&revs->diffopt, '+', newmode,
 					       null_oid(the_hash_algo), 0, ce->name, 0);
 				continue;
@@ -270,7 +271,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
 
 			changed = match_stat_with_submodule(&revs->diffopt, ce, &st,
 							    ce_option, &dirty_submodule);
-			newmode = ce_mode_from_stat(the_repository, ce, st.st_mode);
+			newmode = ce_mode_from_stat(revs->repo, ce, st.st_mode);
 		}
 
 		if (!changed && !dirty_submodule) {
environment.c +1 -0
index 591683ce8c..9d12c5fa56 100644
@@ -304,6 +304,7 @@ int git_default_core_config(const char *var, const char *value,
 
 	/* 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;
 	}
Signature · 1 line
2.43.0
author
#4 lore raw

PATCH v2 1/1 Make 'trust_executable_bit' repository-scoped

In reply to drona

From: Dorna Raj Gyawali <[email protected]>

- Moved 'trust_executable_bit' from a global variable to struct repo_settings.
- Updated all calls to ce_mode_from_stat() to pass the repository.
- Updated environment.c to set the repository's trust_executable_bit when reading core.filemode.
- Fixed apply.c, update-index.c, diff-lib.c, and read-cache.c to reference the_repository->settings.trust_executable_bit.
- Added prepare_repo_settings() call in diff-lib.c to ensure repo settings are loaded.

This change makes executable-bit handling repository-scoped and prepares the code for multi-repo support.

---
 apply.c       | 2 +-
 diff-lib.c    | 9 +++++----
 environment.c | 1 +
 3 files changed, 7 insertions(+), 5 deletions(-)
apply.c +1 -1
index f9fd7b0030..1677ddca15 100644
@@ -3838,7 +3838,7 @@ static int check_preimage(struct apply_state *state,
 		if (*ce && !(*ce)->ce_mode)
 			BUG("ce_mode == 0 for path '%s'", old_name);
 
-		if (the_repository->settings.trust_executable_bit  || !S_ISREG(st->st_mode))
+		if (the_repository->settings.trust_executable_bit || !S_ISREG(st->st_mode))
 			st_mode = ce_mode_from_stat(the_repository, *ce, st->st_mode);
 		else if (*ce)
 			st_mode = (*ce)->ce_mode;
diff-lib.c +5 -4
index 894358c8b0..276efef407 100644
@@ -108,6 +108,7 @@ static int match_stat_with_submodule(struct diff_options *diffopt,
 
 void run_diff_files(struct rev_info *revs, unsigned int option)
 {
+	prepare_repo_settings(revs->repo);
 	int entries, i;
 	int diff_unmerged_stage = revs->max_count;
 	unsigned ce_option = ((option & DIFF_RACY_IS_MODIFIED)
@@ -160,7 +161,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
 
 			changed = check_removed(ce, &st);
 			if (!changed)
-				wt_mode = ce_mode_from_stat(the_repository, ce, st.st_mode);
+				wt_mode = ce_mode_from_stat(revs->repo, ce, st.st_mode);
 			else {
 				if (changed < 0) {
 					perror(ce->name);
@@ -193,7 +194,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
 					num_compare_stages++;
 					oidcpy(&dpath->parent[stage - 2].oid,
 					       &nce->oid);
-					dpath->parent[stage-2].mode = ce_mode_from_stat(the_repository,nce, mode);
+					dpath->parent[stage-2].mode = ce_mode_from_stat(revs->repo, nce, mode);
 					dpath->parent[stage-2].status =
 						DIFF_STATUS_MODIFIED;
 				}
@@ -262,7 +263,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
 				continue;
 			} else if (revs->diffopt.ita_invisible_in_index &&
 				   ce_intent_to_add(ce)) {
-				newmode = ce_mode_from_stat(the_repository, ce, st.st_mode);
+				newmode = ce_mode_from_stat(revs->repo, ce, st.st_mode);
 				diff_addremove(&revs->diffopt, '+', newmode,
 					       null_oid(the_hash_algo), 0, ce->name, 0);
 				continue;
@@ -270,7 +271,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
 
 			changed = match_stat_with_submodule(&revs->diffopt, ce, &st,
 							    ce_option, &dirty_submodule);
-			newmode = ce_mode_from_stat(the_repository, ce, st.st_mode);
+			newmode = ce_mode_from_stat(revs->repo, ce, st.st_mode);
 		}
 
 		if (!changed && !dirty_submodule) {
environment.c +1 -0
index 591683ce8c..9d12c5fa56 100644
@@ -304,6 +304,7 @@ int git_default_core_config(const char *var, const char *value,
 
 	/* 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;
 	}
Signature · 1 line
2.43.0

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw

Re: [PATCH v2] Make 'trust_executable_bit' repository-scoped

Quoted 25 lines

Hi drona,

Thanks for the update! Just a quick heads-up: it looks like you forgot to CC Junio ([email protected]) on this iteration. Additionally, I think it's a good practice to respond to reviews before sending new patches. What do you think?

environment.c int git_default_core_config(const char *var, const char *value, · line 310

Quoted 6 lines
environment.c +1 -0
 	if (!strcmp(var, "core.filemode")) {
+		prepare_repo_settings(the_repository);
 		the_repository->settings.trust_executable_bit = 

git_config_bool(var, value);

environment.c +0 -0
 		return 0;
 	}

Regarding the code, calling 'prepare_repo_settings()' inside 'git_default_core_config()' defeats the purpose of lazy-loading, doesn't it?

if (!strcmp(var, "core.filemode")) {
	prepare_repo_settings(the_repository);
	the_repository->settings.trust_executable_bit = git_config_bool(var, 
value);
	return 0;
}
Quoted 8 lines

I think the standard practice is to drop the variable from 'environment.c' completely and read it directly inside 'repo-settings.c: prepare_repo_settings()' using 'repo_config_get_bool()'.

Regards,

Yuchen

I accidentally clicked the wrong option and didn't select Reply All.

I'll CC Junio on this message.

Regards,

Yuchen

#7 lore raw

Re: [PATCH v2] Make 'trust_executable_bit' repository-scoped

Hi Yuchen,

Thanks for the review and for pointing that out.

You're right that calling prepare_repo_settings() inside git_default_core_config() defeats the purpose of lazy loading. I'll update the patch accordingly by removing the handling from environment.c and reading core.filemode directly in repo-settings.c using repo_config_get_bool().

Also, I'm new to contributing to Git, so thank you for the guidance and patience while I learn.

Thanks again for the help.

Regards,
Drona

#8 lore raw

Re: [PATCH v2] Make 'trust_executable_bit' repository-scoped

Hi drona,

Quoted 4 lines · Junio C Hamano

There were discussions on pros and cons moving global recipients of configuration values into a dynamically allocated strucrure... and excellent pieces of advice have been given by Phillip Wood. If anything, a change like this should ask for input from him.

That makes sense. I think you should CC him whenever you've thoroughly polished the patch or when you encounter unresolved issues.

Quoted 3 lines

This "v2" applies to a mythical codebase where trust_executable_bit is somehow a member in the settings structure, which I do not think we have.

Given Junio's observation, it seems this iteration is targeting an incorrect or non-existent codebase structure.

I'll hold off on further reviews of the specific implementation details until the base codebase issue is sorted out and the structural design (incorporating Phillip's previous advice) is settled.

Looking forward to the updated version!

Thanks,

Yuchen

#9 lore raw

Re: [PATCH v2] Make 'trust_executable_bit' repository-scoped

Quoted 16 lines · Tian Yuchen

Hi drona,

Quoted 4 lines · Junio C Hamano

There were discussions on pros and cons moving global recipients of configuration values into a dynamically allocated strucrure... and excellent pieces of advice have been given by Phillip Wood. If anything, a change like this should ask for input from him.

That makes sense. I think you should CC him whenever you've thoroughly polished the patch or when you encounter unresolved issues.

Quoted 3 lines

This "v2" applies to a mythical codebase where trust_executable_bit is somehow a member in the settings structure, which I do not think we have.

Quoted 6 lines

Given Junio's observation, it seems this iteration is targeting an incorrect or non-existent codebase structure.

I'll hold off on further reviews of the specific implementation details until the base codebase issue is sorted out and the structural design (incorporating Phillip's previous advice) is settled.

I think what the author called v2 was actually [2/N] where the previous version was treated as [1/N] of the same series. The line I noticed was strange in my response is probably correcting what the previous one did, which is not what we want to see. It probably is similar to https://lore.kernel.org/git/[email protected]/

We prefer the patch authors to pretend to be a perfect developer who never made any mistakes while writing their series.

This unfortunately is a recurring theme among new developers.

https://lore.kernel.org/git/[email protected]/
https://lore.kernel.org/git/[email protected]/
https://lore.kernel.org/git/[email protected]/

#10 lore raw

Re: [PATCH v2] Make 'trust_executable_bit' repository-scoped

In reply to [email protected]
Quoted 4 lines · [email protected] writes:
Quoted 4 lines

Hi drona,

Thanks for the update! Just a quick heads-up: it looks like you forgot to CC Junio ([email protected]) on this iteration.

No strong need to Cc the maintainer when the patch is not ready to be applied, even though it may be nice. I'll be seeing it either way as I rarely look at my mailbox and use the mailing list archive at lore.kernel.org my primary source of Git patches anyway.

There were discussions on pros and cons moving global recipients of configuration values into a dynamically allocated strucrure, which can change when they are parsed and when bad values in them result in warnings, depending on the way the change is done, and excellent pieces of advice have been given by Phillip Wood. If anything, a change like this should ask for input from him.

Quoted 2 lines
Quoted 2 lines

Additionally, I think it's a good practice to respond to reviews before sending new patches.

Absolutely.

Quoted 18 lines
Quoted 18 lines

environment.c int git_default_core_config(const char *var, const char *value, · line 310

Quoted 6 lines
environment.c +1 -0
 	if (!strcmp(var, "core.filemode")) {
+		prepare_repo_settings(the_repository);
 		the_repository->settings.trust_executable_bit = 

git_config_bool(var, value);

environment.c +0 -0
 		return 0;
 	}

Regarding the code, calling 'prepare_repo_settings()' inside 'git_default_core_config()' defeats the purpose of lazy-loading, doesn't it?

if (!strcmp(var, "core.filemode")) {
	prepare_repo_settings(the_repository);
	the_repository->settings.trust_executable_bit = git_config_bool(var, 
value);
	return 0;
}
Quoted 4 lines
Quoted 4 lines

I think the standard practice is to drop the variable from 'environment.c' completely and read it directly inside 'repo-settings.c: prepare_repo_settings()' using 'repo_config_get_bool()'.

This "v2" applies to a mythical codebase where trust_executable_bit is somehow a member in the settings structure, which I do not think we have.

#11 lore raw

Re: [PATCH v2] Make 'trust_executable_bit' repository-scoped

Hi Junio,

I have sent a new updated series of changes that aligns with the actual code structure.
There was some confusion regarding work flow by my side. I am still learning..

Thanks for earlier review and guidance.

Best regards,
dorna

Quoted 52 lines · Junio C Hamano
Quoted 4 lines · [email protected] writes:
Quoted 4 lines

Hi drona,

Thanks for the update! Just a quick heads-up: it looks like you forgot to CC Junio ([email protected]) on this iteration.

No strong need to Cc the maintainer when the patch is not ready to be applied, even though it may be nice. I'll be seeing it either way as I rarely look at my mailbox and use the mailing list archive at lore.kernel.org my primary source of Git patches anyway.

There were discussions on pros and cons moving global recipients of configuration values into a dynamically allocated strucrure, which can change when they are parsed and when bad values in them result in warnings, depending on the way the change is done, and excellent pieces of advice have been given by Phillip Wood. If anything, a change like this should ask for input from him.

Quoted 2 lines
Quoted 2 lines

Additionally, I think it's a good practice to respond to reviews before sending new patches.

Absolutely.

Quoted 18 lines
Quoted 18 lines
Quoted 6 lines
    if (!strcmp(var, "core.filemode")) {
+           prepare_repo_settings(the_repository);
            the_repository->settings.trust_executable_bit =
git_config_bool(var, value);
            return 0;
    }

Regarding the code, calling 'prepare_repo_settings()' inside 'git_default_core_config()' defeats the purpose of lazy-loading, doesn't it?

if (!strcmp(var, "core.filemode")) {
     prepare_repo_settings(the_repository);
     the_repository->settings.trust_executable_bit = git_config_bool(var,
value);
     return 0;
}
Quoted 4 lines
Quoted 4 lines

I think the standard practice is to drop the variable from 'environment.c' completely and read it directly inside 'repo-settings.c: prepare_repo_settings()' using 'repo_config_get_bool()'.

This "v2" applies to a mythical codebase where trust_executable_bit is somehow a member in the settings structure, which I do not think we have.