environment.c: migrate 'trust_executable_bit' into 'repo_config_values'
cover environment.c: migrate 'trust_executable_bit' into 'repo_config_values'
The 'core.filemode' configuration, which is stored as a global variable 'trust_executable_bit', is a core filesystem capability flag.
Move it into 'repo_config_values' to tie it to the specific repository instance it was read from. Eager parsing is maintained because this flag is heavily consulted in hot paths.
To avoid falling back to 'the_repository', refactor the signatures of helper functions:
- ce_mode_from_stat()
- st_mode_from_ce()
- fake_lstat()
- check_removed()
These functions now accept a 'struct index_state *istate', ensuring the correct context is seamlessly passed down to the lowest levels.
Note: 'repo_config_values()' still does not support any 'struct repository' other than 'the_repository'. In other words, this series of patches is laying the groundwork for the eventual elimination of 'the_repository'.
Previous related work:
- [PATCH 2/6] config: add trust_executable_bit to global config
- [PATCH] Refactor 'trust_executable_bit' to repository-scoped setting (This series of patches was unsuccessful because the target location selected was 'struct repo_settings', which our analysis indicated was not the optimal choice. For further details, please see: [1])
[1] https://lore.kernel.org/git/837b5360b40f992351f489a0ae05fedf49884c6e.1685716420.git.gitgitgadget@gmail.com/
[2] https://lore.kernel.org/git/[email protected]/
[3] https://lore.kernel.org/git/[email protected]/
Tian Yuchen (4):
read-cache: remove redundant extern declarations
read-cache: move 'ce_mode_from_stat()' to 'read-cache.c'
environment: move 'trust_executable_bit' into repo_config_values
read-cache: pass 'istate' to stat/mode helper functions
apply.c | 6 ++++-- builtin/update-index.c | 2 +- diff-lib.c | 20 +++++++++--------- environment.c | 4 ++-- environment.h | 2 +- read-cache-ll.h | 2 +- read-cache.c | 47 ++++++++++++++++++++++++++++++++---------- read-cache.h | 17 +++------------ 8 files changed, 58 insertions(+), 42 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/4 read-cache: remove redundant extern declarations
The 'read-cache.c' file already includes 'environment.h', which provides the extern declarations for variables like 'trust_executable_bit' and 'has_symlinks'.
Remove the redundant extern declarations inside 'st_mode_from_ce()' to clean up the code.
--- read-cache.c | 2 -- 1 file changed, 2 deletions(-)
read-cache.c +0 -2
@@ -204,8 +204,6 @@ void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, ststatic unsigned int st_mode_from_ce (const struct cache_entry *ce) { -extern int trust_executable_bit, has_symlinks; -switch (ce->ce_mode &S_IFMT ) {case S_IFLNK :return has_symlinks ?S_IFLNK : (S_IFREG |0644 );
Signature · 1 line
2.43.0
PATCH 2/4 read-cache: move 'ce_mode_from_stat()' to 'read-cache.c'
In reply to Tian YuchenThe ce_mode_from_stat() function is declared as a static inline function in 'read-cache.h'. As we want to migrate configuration variables, this helper function will need access to corresponding repository-specific configuration logic. Move the implementation to 'read-cache.c' to cleanly encapsulate its dependencies.
Note that the 'extern int trust_executable_bit, has_symlinks;' line is discarded because it's not necessary when the function lives in "read-cache.c".
--- read-cache.c | 13 +++++++++++++ read-cache.h | 16 ++-------------- 2 files changed, 15 insertions(+), 14 deletions(-)
read-cache.c +13 -0
@@ -202,6 +202,19 @@ void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, st } } +unsigned int ce_mode_from_stat (const struct cache_entry *ce,unsigned int mode) +{ +if (!has_symlinks &&S_ISREG (mode) && + ce &&S_ISLNK (ce->ce_mode)) +return ce->ce_mode; +if (!trust_executable_bit &&S_ISREG (mode)) { +if (ce &&S_ISREG (ce->ce_mode)) +return ce->ce_mode; +return create_ce_mode (0666 ); + } +return create_ce_mode (mode); +} +static unsigned int st_mode_from_ce (const struct cache_entry *ce) {switch (ce->ce_mode &S_IFMT ) {
read-cache.h +2 -14
@@ -5,20 +5,8 @@#include "object.h" #include "pathspec.h" -static inline unsigned int ce_mode_from_stat (const struct cache_entry *ce, -unsigned int mode) -{ -extern int trust_executable_bit, 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 (ce &&S_ISREG (ce->ce_mode)) -return ce->ce_mode; -return create_ce_mode (0666 ); - } -return create_ce_mode (mode); -} +unsigned int ce_mode_from_stat (const struct cache_entry *ce, +unsigned int mode);static inline int ce_to_dtype (const struct cache_entry *ce) {
Signature · 1 line
2.43.0
Re: [PATCH v1 2/4] read-cache: move 'ce_mode_from_stat()' to 'read-cache.c'
Quoted 14 lines · Tian Yuchen
read-cache.h +0
-6@@ -5,20 +5,8 @@#include "object.h" #include "pathspec.h" -static inline unsigned int ce_mode_from_stat (const struct cache_entry *ce, -unsigned int mode) -{ -extern int trust_executable_bit, has_symlinks; -if (!has_symlinks &&S_ISREG (mode) && - ce &&S_ISLNK (ce->ce_mode))
read-cache.h line 9
Quoted 10 lines
read-cache.h +2
-8-return ce->ce_mode; -if (!trust_executable_bit &&S_ISREG (mode)) { -if (ce &&S_ISREG (ce->ce_mode)) -return ce->ce_mode; -return create_ce_mode (0666 ); - } -return create_ce_mode (mode); -} +unsigned int ce_mode_from_stat (const struct cache_entry *ce, +unsigned int mode);
This is moving goalposts a bit, so please feel free to ignore: should we maybe add a small comment what the function does while at it?
Patrick
Re: [PATCH v1 2/4] read-cache: move 'ce_mode_from_stat()' to 'read-cache.c'
Quoted 2 lines · Patrick Steinhardt
This is moving goalposts a bit, so please feel free to ignore: should we maybe add a small comment what the function does while at it?
Yes indeed, the original commit message looks a bit bare, I’ll add to it in the next reroll. Thanks!
Regards, yuchen
PATCH 3/4 environment: move 'trust_executable_bit' into repo_config_values
In reply to Tian YuchenMove the global 'trust_executable_bit' configuration into the repository-specific 'repo_config_values' struct.
For now, associated functions in read-cache.c access this configuration by explicitly falling back to 'the_repository'.
--- apply.c | 4 +++- environment.c | 4 ++-- environment.h | 2 +- read-cache.c | 15 +++++++++++---- 4 files changed, 17 insertions(+), 8 deletions(-)
apply.c +3 -1
@@ -3890,10 +3890,12 @@ static int check_preimage(struct apply_state *state, }if (!state->cached && !previous) { +struct repo_config_values *cfg =repo_config_values (the_repository); +if (*ce && !(*ce)->ce_mode)BUG ("ce_mode == 0 for path '%s'" , old_name); -if (trust_executable_bit || !S_ISREG (st->st_mode)) +if (cfg->trust_executable_bit || !S_ISREG (st->st_mode)) st_mode =ce_mode_from_stat (*ce, st->st_mode);else if (*ce) st_mode = (*ce)->ce_mode;
environment.c +2 -2
@@ -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 ;
@@ -305,7 +304,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 +719,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 ; }
environment.h +1 -1
@@ -90,6 +90,7 @@ struct repository;struct repo_config_values {/* section "core" config values */ char *attributes_file; +int trust_executable_bit;int apply_sparse_checkout;/* section "branch" config values */
@@ -160,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;
read-cache.c +11 -4
@@ -204,10 +204,12 @@ void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, stunsigned int ce_mode_from_stat (const struct cache_entry *ce,unsigned int mode) { +struct repo_config_values *cfg =repo_config_values (the_repository); +if (!has_symlinks &&S_ISREG (mode) && ce &&S_ISLNK (ce->ce_mode))return ce->ce_mode; -if (!trust_executable_bit &&S_ISREG (mode)) { +if (!cfg->trust_executable_bit &&S_ISREG (mode)) {if (ce &&S_ISREG (ce->ce_mode))return ce->ce_mode;return create_ce_mode (0666 );
@@ -217,11 +219,13 @@ unsigned int ce_mode_from_stat(const struct cache_entry *ce, unsigned int mode)static unsigned int st_mode_from_ce (const struct cache_entry *ce) { +struct repo_config_values *cfg =repo_config_values (the_repository); +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 & (cfg->trust_executable_bit ?0755 :0644 )) |S_IFREG ;case S_IFGITLINK :return S_IFDIR |0755 ;case S_IFDIR :
@@ -321,6 +325,7 @@ static int ce_modified_check_fs(struct index_state *istate,static int ce_match_stat_basic (const struct cache_entry *ce,struct stat *st) {unsigned int changed =0 ; +struct repo_config_values *cfg =repo_config_values (the_repository);if (ce->ce_flags &CE_REMOVE )return MODE_CHANGED |DATA_CHANGED |TYPE_CHANGED ;
@@ -331,7 +336,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 (cfg->trust_executable_bit && (0100 & (ce->ce_mode ^ st->st_mode))) changed |=MODE_CHANGED ;break ;
@@ -732,6 +737,8 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st, (intent_only ? ADD_CACHE_NEW_ONLY : 0));unsigned hash_flags = pretend ?0 :INDEX_WRITE_OBJECT ; +struct repo_config_values *cfg =repo_config_values (the_repository); +if (flags &ADD_CACHE_RENORMALIZE ) hash_flags |=INDEX_RENORMALIZE ;
@@ -752,7 +759,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 (cfg->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
Signature · 1 line
2.43.0
Re: [PATCH v1 3/4] environment: move 'trust_executable_bit' into repo_config_values
environment.c void repo_config_values_init(struct repo_config_values *cfg) · line 722
Quoted 5 lines · Tian Yuchen
environment.c +1
-0@@ -720,5 +719,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 ;
Here trust_executable_bit is processed after apply_sparse_checkout ...
environment.h struct repository; · line 94
Quoted 12 lines
environment.c +0
-0cfg->branch_track =BRANCH_TRACK_REMOTE ; }environment.h +1
-0@@ -90,6 +90,7 @@ struct repository;struct repo_config_values {/* section "core" config values */ char *attributes_file; +int trust_executable_bit;int apply_sparse_checkout;
... but here it is before apply_sparse_checkout.
I think it would make more sense to put trust_executable_bit after apply_sparse_checkout here.
Quoted 1 line
environment.h +0
-0/* section "branch" config values */
Re: [PATCH v1 3/4] environment: move 'trust_executable_bit' into repo_config_values
In reply to Tian YuchenQuoted 26 lines · Tian Yuchen
apply.c +3
-1@@ -3890,10 +3890,12 @@ static int check_preimage(struct apply_state *state, }if (!state->cached && !previous) { +struct repo_config_values *cfg =repo_config_values (the_repository); +if (*ce && !(*ce)->ce_mode)BUG ("ce_mode == 0 for path '%s'" , old_name); -if (trust_executable_bit || !S_ISREG (st->st_mode)) +if (cfg->trust_executable_bit || !S_ISREG (st->st_mode)) st_mode =ce_mode_from_stat (*ce, st->st_mode);else if (*ce) st_mode = (*ce)->ce_mode;read-cache.c +0
-0@@ -204,10 +204,12 @@ void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, stunsigned int ce_mode_from_stat (const struct cache_entry *ce,unsigned int mode) {
read-cache.c void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, st · line 215
Quoted 10 lines
read-cache.c +3
-1+struct repo_config_values *cfg =repo_config_values (the_repository); +if (!has_symlinks &&S_ISREG (mode) && ce &&S_ISLNK (ce->ce_mode))return ce->ce_mode; -if (!trust_executable_bit &&S_ISREG (mode)) { +if (!cfg->trust_executable_bit &&S_ISREG (mode)) {if (ce &&S_ISREG (ce->ce_mode))return ce->ce_mode;return create_ce_mode (0666 );
How hot are the code paths that call into this helper function? In the original under some condition, it was possible to return without even consulting the trust_executable_bit variable, but in the updated code, the helper unconditionally makes a call to the repo_config_values() helper function even before it knows it needs to know the value of trust_executable_bit.
Quoted 5 lines
read-cache.c +1
-0@@ -217,11 +219,13 @@ unsigned int ce_mode_from_stat(const struct cache_entry *ce, unsigned int mode)static unsigned int st_mode_from_ce (const struct cache_entry *ce) { +struct repo_config_values *cfg =repo_config_values (the_repository);
read-cache.c unsigned int ce_mode_from_stat(const struct cache_entry *ce, unsigned int mode) · line 231
Quoted 10 lines
read-cache.c +2
-1+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 & (cfg->trust_executable_bit ?0755 :0644 )) |S_IFREG ;case S_IFGITLINK :return S_IFDIR |0755 ;case S_IFDIR :
Ditto.
Quoted 9 lines
read-cache.c +1
-0@@ -321,6 +325,7 @@ static int ce_modified_check_fs(struct index_state *istate,static int ce_match_stat_basic (const struct cache_entry *ce,struct stat *st) {unsigned int changed =0 ; +struct repo_config_values *cfg =repo_config_values (the_repository);if (ce->ce_flags &CE_REMOVE )return MODE_CHANGED |DATA_CHANGED |TYPE_CHANGED ;
read-cache.c static int ce_match_stat_basic(const struct cache_entry *ce, struct stat *st) · line 342
Quoted 8 lines
read-cache.c +1
-1@@ -331,7 +336,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 (cfg->trust_executable_bit && (0100 & (ce->ce_mode ^ st->st_mode))) changed |=MODE_CHANGED ;break ;
Ditto.
read-cache.c int add_to_index(struct index_state *istate, const char *path, struct stat *st, · line 741
Quoted 6 lines
read-cache.c +2
-0@@ -732,6 +737,8 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st, (intent_only ? ADD_CACHE_NEW_ONLY : 0));unsigned hash_flags = pretend ?0 :INDEX_WRITE_OBJECT ; +struct repo_config_values *cfg =repo_config_values (the_repository); +
Lose the excess blank line before the new declaration.
read-cache.c int add_to_index(struct index_state *istate, const char *path, struct stat *st, · line 765
Quoted 12 lines
read-cache.c +1
-1if (flags &ADD_CACHE_RENORMALIZE ) hash_flags |=INDEX_RENORMALIZE ;@@ -752,7 +759,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 (cfg->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
Almost all of these places that care about trust_executable_bit also cares about has_symlinks. I wonder if they should be converted to repo-local settings in the same series.
Re: [PATCH v1 3/4] environment: move 'trust_executable_bit' into repo_config_values
Hi Junio,
Thanks for the feedback!
Quoted 37 lines · Junio C Hamano
Quoted 35 lines · Tian Yuchen
apply.c +3
-1@@ -3890,10 +3890,12 @@ static int check_preimage(struct apply_state *state, }if (!state->cached && !previous) { +struct repo_config_values *cfg =repo_config_values (the_repository); +if (*ce && !(*ce)->ce_mode)BUG ("ce_mode == 0 for path '%s'" , old_name); -if (trust_executable_bit || !S_ISREG (st->st_mode)) +if (cfg->trust_executable_bit || !S_ISREG (st->st_mode)) st_mode =ce_mode_from_stat (*ce, st->st_mode);else if (*ce) st_mode = (*ce)->ce_mode;read-cache.c +3
-1@@ -204,10 +204,12 @@ void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, stunsigned int ce_mode_from_stat (const struct cache_entry *ce,unsigned int mode) { +struct repo_config_values *cfg =repo_config_values (the_repository); +if (!has_symlinks &&S_ISREG (mode) && ce &&S_ISLNK (ce->ce_mode))return ce->ce_mode; -if (!trust_executable_bit &&S_ISREG (mode)) { +if (!cfg->trust_executable_bit &&S_ISREG (mode)) {if (ce &&S_ISREG (ce->ce_mode))return ce->ce_mode;
Quoted 8 lines
read-cache.c void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, st · line 215
Quoted 1 line
read-cache.c +0
-0return create_ce_mode (0666 );How hot are the code paths that call into this helper function? In the original under some condition, it was possible to return without even consulting the
trust_executable_bitvariable, but in the updated code, the helper unconditionally makes a call to therepo_config_values()helper function even before it knows it needs to know the value oftrust_executable_bit.
That sounds reasonable to me. I’ll adjust the conditional logic in some of the statements so that they short-circuit appropriately to avoid performance overhead.
Quoted 55 lines
Quoted 6 lines
read-cache.c +1
-0@@ -217,11 +219,13 @@ unsigned int ce_mode_from_stat(const struct cache_entry *ce, unsigned int mode)static unsigned int st_mode_from_ce (const struct cache_entry *ce) { +struct repo_config_values *cfg =repo_config_values (the_repository);read-cache.c unsigned int ce_mode_from_stat(const struct cache_entry *ce, unsigned int mode) · line 231
Quoted 10 lines
read-cache.c +2
-1+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 & (cfg->trust_executable_bit ?0755 :0644 )) |S_IFREG ;case S_IFGITLINK :return S_IFDIR |0755 ;case S_IFDIR :Ditto.
Quoted 9 lines
read-cache.c +1
-0@@ -321,6 +325,7 @@ static int ce_modified_check_fs(struct index_state *istate,static int ce_match_stat_basic (const struct cache_entry *ce,struct stat *st) {unsigned int changed =0 ; +struct repo_config_values *cfg =repo_config_values (the_repository);if (ce->ce_flags &CE_REMOVE )return MODE_CHANGED |DATA_CHANGED |TYPE_CHANGED ;read-cache.c static int ce_match_stat_basic(const struct cache_entry *ce, struct stat *st) · line 342
Quoted 8 lines
read-cache.c +1
-1@@ -331,7 +336,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 (cfg->trust_executable_bit && (0100 & (ce->ce_mode ^ st->st_mode))) changed |=MODE_CHANGED ;break ;Ditto.
read-cache.c int add_to_index(struct index_state *istate, const char *path, struct stat *st, · line 741
Quoted 6 lines
read-cache.c +2
-0@@ -732,6 +737,8 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st, (intent_only ? ADD_CACHE_NEW_ONLY : 0));unsigned hash_flags = pretend ?0 :INDEX_WRITE_OBJECT ; +struct repo_config_values *cfg =repo_config_values (the_repository); +Lose the excess blank line before the new declaration.
Quoted 7 lines
read-cache.c +0
-0if (flags &ADD_CACHE_RENORMALIZE ) hash_flags |=INDEX_RENORMALIZE ;@@ -752,7 +759,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st, ce->ce_flags |=CE_INTENT_TO_ADD ;
Quoted 9 lines
read-cache.c int add_to_index(struct index_state *istate, const char *path, struct stat *st, · line 765
Quoted 5 lines
read-cache.c +1
-1-if (trust_executable_bit && has_symlinks) { +if (cfg->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 Almost all of these places that care about
trust_executable_bitalso cares abouthas_symlinks. I wonder if they should be converted to repo-local settings in the same series.
That’s true: I had actually planned to start migrating has_symlinks as soon as this series was approved. Since you think it would be better to merge them into a single series, I’ll go ahead and do that ;)
Thanks, yuchen
Re: [PATCH v1 3/4] environment: move 'trust_executable_bit' into repo_config_values
Quoted 2 lines · Tian Yuchen
That’s true: I had actually planned to start migrating
has_symlinksas soon as this series was approved. Since you think it would be better to merge them into a single series, I’ll go ahead and do that ;)
I’ve found that migrating has_symlinks seems to be quite a tricky business. Some callers in certain files pass very few parameters, and the call stack is quite deep, if I am correct. so I feel that adding a repo for this purpose might be overkill. Perhaps it would be better to focus on trust_executable_bit for now?
Regards, yuchen
Re: [PATCH v1 3/4] environment: move 'trust_executable_bit' into repo_config_values
Quoted 7 lines · Tian Yuchen
Quoted 4 lines · Tian Yuchen
That’s true: I had actually planned to start migrating
has_symlinksas soon as this series was approved. Since you think it would be better to merge them into a single series, I’ll go ahead and do that ;)
Quoted 7 lines
I’ve found that migrating
has_symlinksseems to be quite a tricky business. Some callers in certain files pass very few parameters, and the call stack is quite deep, if I am correct. so I feel that adding a repo for this purpose might be overkill. Perhaps it would be better to focus ontrust_executable_bitfor now?Regards, yuchen
Sounds fine. Thanks for digging.
PATCH 4/4 read-cache: pass 'istate' to stat/mode helper functions
In reply to Tian YuchenIn the previous commit, the gloabl 'trust_executable_bit' was migrated into 'repo_config_values', but low-level helpers in read-cache.c still relied on 'the_repository' to access it.
Refactor the signatures of ce_mode_from_stat(), st_mode_from_ce(), fake_lstat(), and check_removed() to accept a 'struct index_state *istate'. This allows these functions to retrieve the repository context via 'istate->repo'.
--- apply.c | 4 ++-- builtin/update-index.c | 2 +- diff-lib.c | 20 ++++++++++---------- read-cache-ll.h | 2 +- read-cache.c | 31 +++++++++++++++++++------------ read-cache.h | 3 ++- 6 files changed, 35 insertions(+), 27 deletions(-)
apply.c +2 -2
@@ -3890,13 +3890,13 @@ static int check_preimage(struct apply_state *state, }if (!state->cached && !previous) { -struct repo_config_values *cfg =repo_config_values (the_repository); +struct repo_config_values *cfg =repo_config_values (state->repo);if (*ce && !(*ce)->ce_mode)BUG ("ce_mode == 0 for path '%s'" , old_name);if (cfg->trust_executable_bit || !S_ISREG (st->st_mode)) - st_mode =ce_mode_from_stat (*ce, st->st_mode); + st_mode =ce_mode_from_stat (state->repo->index, *ce, st->st_mode);else if (*ce) st_mode = (*ce)->ce_mode;else
builtin/update-index.c +1 -1
@@ -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->index, old, st->st_mode);if (index_path (the_repository->index, &ce->oid, path, st, info_only ?0 :INDEX_WRITE_OBJECT )) {
diff-lib.c +10 -10
@@ -39,14 +39,14 @@* exists for ce that is a submodule -- it is a submodule that is not * checked out). Return negative for an error. */ -static int check_removed (const struct cache_entry *ce,struct stat *st) +static int check_removed (struct index_state *istate,const struct cache_entry *ce,struct stat *st) {int stat_err;if (!(ce->ce_flags &CE_FSMONITOR_VALID )) stat_err =lstat (ce->name, st);else - stat_err =fake_lstat (ce, st); + stat_err =fake_lstat (istate, ce, st);if (stat_err <0 ) {if (!is_missing_file_error (errno))return -1 ;
@@ -158,9 +158,9 @@ void run_diff_files(struct rev_info *revs, unsigned int option)int num_compare_stages =0 ;struct stat st; - changed =check_removed (ce, &st); + changed =check_removed (revs->repo->index, ce, &st);if (!changed) - wt_mode =ce_mode_from_stat (ce, st.st_mode); + wt_mode =ce_mode_from_stat (revs->repo->index, 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 (revs->repo->index, nce, mode); dpath->parent[stage-2 ].status =DIFF_STATUS_MODIFIED ; }
@@ -249,7 +249,7 @@ void run_diff_files(struct rev_info *revs, unsigned int option) }else {struct stat st; - changed =check_removed (ce, &st); + changed =check_removed (revs->repo->index, ce, &st);if (changed) {if (changed <0 ) {perror (ce->name);
@@ -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 (revs->repo->index, 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 (revs->repo->index, ce, st.st_mode); }if (!changed && !dirty_submodule) {
@@ -324,7 +324,7 @@ static int get_stat_data(const struct cache_entry *ce,if (!cached && !ce_uptodate (ce)) {int changed;struct stat st; - changed =check_removed (ce, &st); + changed =check_removed (diffopt->repo->index, ce, &st);if (changed <0 )return -1 ;else if (changed) {
@@ -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 (diffopt->repo->index, ce, st.st_mode); oid =null_oid (the_hash_algo); } }
read-cache-ll.h +1 -1
@@ -442,7 +442,7 @@ void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, st* for lstat() for a tracked path that is known to be up-to-date via * some out-of-line means (like fsmonitor). */ -int fake_lstat (const struct cache_entry *ce,struct stat *st); +int fake_lstat (struct index_state *istate,const struct cache_entry *ce,struct stat *st);#define REFRESH_REALLY (1 << 0)/* ignore_valid */ #define REFRESH_UNMERGED (1 << 1)/* allow unmerged */
read-cache.c +19 -12
@@ -202,9 +202,12 @@ void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, st } } -unsigned int ce_mode_from_stat (const struct cache_entry *ce,unsigned int mode) +unsigned int ce_mode_from_stat (struct index_state *istate, +const struct cache_entry *ce, +unsigned int mode) { -struct repo_config_values *cfg =repo_config_values (the_repository); +struct repository *repo = (istate && istate->repo) ? istate->repo : the_repository; +struct repo_config_values *cfg =repo_config_values (repo);if (!has_symlinks &&S_ISREG (mode) && ce &&S_ISLNK (ce->ce_mode))
@@ -217,9 +220,10 @@ unsigned int ce_mode_from_stat(const struct cache_entry *ce, unsigned int mode)return create_ce_mode (mode); } -static unsigned int st_mode_from_ce (const struct cache_entry *ce) +static unsigned int st_mode_from_ce (struct index_state *istate,const struct cache_entry *ce) { -struct repo_config_values *cfg =repo_config_values (the_repository); +struct repository *repo = (istate && istate->repo) ? istate->repo : the_repository; +struct repo_config_values *cfg =repo_config_values (repo);switch (ce->ce_mode &S_IFMT ) {case S_IFLNK :
@@ -235,10 +239,10 @@ static unsigned int st_mode_from_ce(const struct cache_entry *ce) } } -int fake_lstat (const struct cache_entry *ce,struct stat *st) +int fake_lstat (struct index_state *istate,const struct cache_entry *ce,struct stat *st) {fake_lstat_data (&ce->ce_stat_data, st); - st->st_mode =st_mode_from_ce (ce); + st->st_mode =st_mode_from_ce (istate, ce);/* always succeed as lstat() replacement */ return 0 ;
@@ -322,10 +326,12 @@ static int ce_modified_check_fs(struct index_state *istate,return 0 ; } -static int ce_match_stat_basic (const struct cache_entry *ce,struct stat *st) +static int ce_match_stat_basic (struct index_state *istate, +const struct cache_entry *ce,struct stat *st) {unsigned int changed =0 ; -struct repo_config_values *cfg =repo_config_values (the_repository); +struct repository *repo = (istate && istate->repo) ? istate->repo : the_repository; +struct repo_config_values *cfg =repo_config_values (repo);if (ce->ce_flags &CE_REMOVE )return MODE_CHANGED |DATA_CHANGED |TYPE_CHANGED ;
@@ -430,7 +436,7 @@ int ie_match_stat(struct index_state *istate,if (ce_intent_to_add (ce))return DATA_CHANGED |TYPE_CHANGED |MODE_CHANGED ; - changed =ce_match_stat_basic (ce, st); + changed =ce_match_stat_basic (istate, ce, st);/* * Within 1 second of this sequence:
@@ -737,7 +743,8 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st, (intent_only ? ADD_CACHE_NEW_ONLY : 0));unsigned hash_flags = pretend ?0 :INDEX_WRITE_OBJECT ; -struct repo_config_values *cfg =repo_config_values (the_repository); +struct repository *repo = (istate && istate->repo) ? istate->repo : the_repository; +struct repo_config_values *cfg =repo_config_values (repo);if (flags &ADD_CACHE_RENORMALIZE ) hash_flags |=INDEX_RENORMALIZE ;
@@ -769,7 +776,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 (istate, ent, st_mode); }/* When core.ignorecase=true, determine if a directory of the same name but differing
@@ -2592,7 +2599,7 @@ static void ce_smudge_racily_clean_entry(struct index_state *istate,if (lstat (ce->name, &st) <0 )return ; -if (ce_match_stat_basic (ce, &st)) +if (ce_match_stat_basic (istate, ce, &st))return ;if (ce_modified_check_fs (istate, ce, &st)) {/* This is "racily clean"; smudge it. Note that this
read-cache.h +2 -1
@@ -5,7 +5,8 @@#include "object.h" #include "pathspec.h" -unsigned int ce_mode_from_stat (const struct cache_entry *ce, +unsigned int ce_mode_from_stat (struct index_state *istate, +const struct cache_entry *ce,unsigned int mode);static inline int ce_to_dtype (const struct cache_entry *ce)
Signature · 1 line
2.43.0
Re: [PATCH v1 4/4] read-cache: pass 'istate' to stat/mode helper functions
Quoted 2 lines · Tian Yuchen
In the previous commit, the gloabl '
trust_executable_bit' was
s/gloabl/global/
Quoted 7 lines
migrated into '
repo_config_values', but low-level helpers inread-cache.cstill relied on 'the_repository' to access it.Refactor the signatures of
ce_mode_from_stat(),st_mode_from_ce(),fake_lstat(), andcheck_removed()to accept a 'structindex_state*istate'. This allows these functions to retrieve the repository context via 'istate->repo'.
The cover letter contains:
"In other words, this series of patches is laying the groundwork for the eventual elimination of 'the_repository'."
but I think it would be also interesting to have something similar here, as this is especially relevant to this commit.
For example maybe add something like "which will help with removing 'the_repository' in the future" to the last sentence?
v2 cover environment: migrate 'trust_executable_bit' into 'repo_config_values'
In reply to Tian YuchenThe 'core.filemode' (stored as 'trust_executable_bit') configuration act as a core filesystem capability flag.
This series moves it into 'struct repo_config_values' to tie it to the specific repository instance it was read from. Eager parsing is maintained because this flag is heavily consulted in hot paths.
Note: 'repo_config_values()' still does not support any struct repository other than the_repository due to how deeply these flags are accessed. In other words, this series of patches is laying the groundwork for the eventual elimination of the_repository.
Previous related work:
[PATCH 2/6] config: add trust_executable_bit to global config [1] [PATCH] Refactor 'trust_executable_bit' to repository-scoped setting [2] (This previous attempt was unsuccessful because the target location selected was 'struct repo_settings', which our analysis indicated was not the optimal choice. For further details, please see: [3])
Changes since V1:
Dropped istate plumbing: Dropped the last commit ("read-cache: pass 'istate' to stat/mode helper functions") to keep the patch focused.
Introduced safe getter: Getter function 'repo_trust_executable_bit()' has been introduced to retrieve configuration values safely.
Added comments for 'ce_mode_from_stat()'.
Thanks!
[1] https://lore.kernel.org/git/837b5360b40f992351f489a0ae05fedf49884c6e.1685716420.git.gitgitgadget@gmail.com/
[2] https://lore.kernel.org/git/[email protected]/
[3] https://lore.kernel.org/git/[email protected]/
Tian Yuchen (3):
read-cache: remove redundant extern declarations
read-cache: move 'ce_mode_from_stat()' to 'read-cache.c'
environment: move trust_executable_bit into repo_config_values
apply.c | 2 +- environment.c | 11 +++++++++-- environment.h | 9 ++++++++- read-cache.c | 28 +++++++++++++++++++++++----- read-cache.h | 16 ++-------------- 5 files changed, 43 insertions(+), 23 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 1/3 read-cache: remove redundant extern declarations
The 'read-cache.c' file already includes 'environment.h', which provides the extern declarations for variables like 'trust_executable_bit' and 'has_symlinks'.
Remove the redundant extern declarations inside 'st_mode_from_ce()' to clean up the code.
--- read-cache.c | 2 -- 1 file changed, 2 deletions(-)
read-cache.c +0 -2
@@ -204,8 +204,6 @@ void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, ststatic unsigned int st_mode_from_ce (const struct cache_entry *ce) { -extern int trust_executable_bit, has_symlinks; -switch (ce->ce_mode &S_IFMT ) {case S_IFLNK :return has_symlinks ?S_IFLNK : (S_IFREG |0644 );
Signature · 1 line
2.43.0
PATCH v2 2/3 read-cache: move 'ce_mode_from_stat()' to 'read-cache.c'
In reply to Tian YuchenThe ce_mode_from_stat() function is declared as a static inline function in 'read-cache.h'. As we want to migrate configuration variables, this helper function will need access to corresponding repository-specific configuration logic. Move the implementation to 'read-cache.c' to cleanly encapsulate its dependencies.
Note that the 'extern int trust_executable_bit, has_symlinks;' line is discarded because it's not necessary when the function lives in "read-cache.c".
At present, this change has no visible impact, but it is crucial for our future plans to pass in the repo context. Comment has been added whilst we are at it.
--- read-cache.c | 20 ++++++++++++++++++++ read-cache.h | 16 ++-------------- 2 files changed, 22 insertions(+), 14 deletions(-)
read-cache.c +20 -0
@@ -202,6 +202,26 @@ void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, st } } +/* +* Determine the appropriate index mode for a file based on its stat() +* information and the existing cache entry (if any). +* +* This function handles degradation for filesystems that lack +* symlink support or reliable executable bits. +*/ +unsigned int ce_mode_from_stat (const struct cache_entry *ce,unsigned int mode) +{ +if (!has_symlinks &&S_ISREG (mode) && + ce &&S_ISLNK (ce->ce_mode)) +return ce->ce_mode; +if (!trust_executable_bit &&S_ISREG (mode)) { +if (ce &&S_ISREG (ce->ce_mode)) +return ce->ce_mode; +return create_ce_mode (0666 ); + } +return create_ce_mode (mode); +} +static unsigned int st_mode_from_ce (const struct cache_entry *ce) {switch (ce->ce_mode &S_IFMT ) {
read-cache.h +2 -14
@@ -5,20 +5,8 @@#include "object.h" #include "pathspec.h" -static inline unsigned int ce_mode_from_stat (const struct cache_entry *ce, -unsigned int mode) -{ -extern int trust_executable_bit, 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 (ce &&S_ISREG (ce->ce_mode)) -return ce->ce_mode; -return create_ce_mode (0666 ); - } -return create_ce_mode (mode); -} +unsigned int ce_mode_from_stat (const struct cache_entry *ce, +unsigned int mode);static inline int ce_to_dtype (const struct cache_entry *ce) {
Signature · 1 line
2.43.0
Re: [PATCH v2 2/3] read-cache: move 'ce_mode_from_stat()' to 'read-cache.c'
Quoted 7 lines · Tian Yuchen
The
ce_mode_from_stat()function is declared as a static inline function in 'read-cache.h'. As we want to migrate configuration variables, this helper function will need access to corresponding repository-specific configuration logic. Move the implementation to 'read-cache.c' to cleanly encapsulate its dependencies.
Quoted 7 lines
Note that the 'extern int
trust_executable_bit,has_symlinks;' line is discarded because it's not necessary when the function lives in "read-cache.c".At present, this change has no visible impact, but it is crucial for our future plans to pass in the repo context. Comment has been added whilst we are at it.
We prefer it when comments like the one below are added in front of the declaration of the function into the header file ("read-cache.h" here), rather than the *.c file.
And yeah, I know that "read-cache.h" is a bad example right now because no function has such a comment there yet.
Quoted 19 lines
read-cache.c +19
-0+/* +* Determine the appropriate index mode for a file based on its stat() +* information and the existing cache entry (if any). +* +* This function handles degradation for filesystems that lack +* symlink support or reliable executable bits. +*/ +unsigned int ce_mode_from_stat (const struct cache_entry *ce,unsigned int mode) +{ +if (!has_symlinks &&S_ISREG (mode) && + ce &&S_ISLNK (ce->ce_mode)) +return ce->ce_mode; +if (!trust_executable_bit &&S_ISREG (mode)) { +if (ce &&S_ISREG (ce->ce_mode)) +return ce->ce_mode; +return create_ce_mode (0666 ); + } +return create_ce_mode (mode); +}
PATCH v2 3/3 environment: move trust_executable_bit into repo_config_values
In reply to Tian YuchenMove the global 'trust_executable_bit' configurations into the repository-specific 'repo_config_values' struct. To ensure code readability, the getter functions 'repo_trust_executable_bit()' has been introduced.
For now, associated functions access this configuration by explicitly falling back to 'the_repository'.
--- apply.c | 2 +- environment.c | 11 +++++++++-- environment.h | 9 ++++++++- read-cache.c | 8 ++++---- 4 files changed, 22 insertions(+), 8 deletions(-)
apply.c +1 -1
@@ -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 (the_repository) || !S_ISREG (st->st_mode)) st_mode =ce_mode_from_stat (*ce, st->st_mode);else if (*ce) st_mode = (*ce)->ce_mode;
environment.c +9 -2
@@ -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->gitdir? +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 ; }
environment.h +8 -1
@@ -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,13 @@ 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); +/* +* Getters for the `repo_trust_executable_bit` fields of `struct repo_config_values`. +* They check `repo->gitdir` to prevent calling repo_config_values() +* before the configuration is loaded or in bare environments. +*/ +int repo_trust_executable_bit (struct repository *repo); +void repo_config_values_init (struct repo_config_values *cfg);/*
@@ -160,7 +168,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 +4 -4
@@ -214,7 +214,7 @@ unsigned int ce_mode_from_stat(const struct cache_entry *ce, unsigned int mode)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_trust_executable_bit (the_repository) &&S_ISREG (mode)) {if (ce &&S_ISREG (ce->ce_mode))return ce->ce_mode;return create_ce_mode (0666 );
@@ -228,7 +228,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 :
@@ -338,7 +338,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 ;
@@ -759,7 +759,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 (the_repository) && has_symlinks) { ce->ce_mode =create_ce_mode (st_mode); }else {/* If there is an existing entry, pick the mode bits and type
Signature · 1 line
2.43.0
Re: [PATCH v2 3/3] environment: move trust_executable_bit into repo_config_values
Quoted 140 lines · Tian Yuchen
Move the global '
trust_executable_bit' configurations into the repository-specific 'repo_config_values' struct. To ensure code readability, the getter functions 'repo_trust_executable_bit()' has been introduced.For now, associated functions access this configuration by explicitly falling back to '
the_repository'.Mentored-by Christian Couder <[email protected]>Mentored-by Ayush Chandekar <[email protected]>Mentored-by Olamide Caleb Bello <[email protected]>Signed-off-by Tian Yuchen <[email protected]>--- apply.c | 2 +- environment.c | 11 +++++++++-- environment.h | 9 ++++++++- read-cache.c | 8 ++++---- 4 files changed, 22 insertions(+), 8 deletions(-)apply.c +1
-1@@ -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 (the_repository) || !S_ISREG (st->st_mode)) st_mode =ce_mode_from_stat (*ce, st->st_mode);else if (*ce) st_mode = (*ce)->ce_mode;environment.c +9
-2@@ -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->gitdir? +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 ; }environment.h +8
-1@@ -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,13 @@ 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); +/* +* Getters for the `repo_trust_executable_bit` fields of `struct repo_config_values`. +* They check `repo->gitdir` to prevent calling repo_config_values() +* before the configuration is loaded or in bare environments. +*/ +int repo_trust_executable_bit (struct repository *repo); +void repo_config_values_init (struct repo_config_values *cfg);/* @@ -160,7 +168,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 +3
-3@@ -214,7 +214,7 @@ unsigned int ce_mode_from_stat(const struct cache_entry *ce, unsigned int mode)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_trust_executable_bit (the_repository) &&S_ISREG (mode)) {if (ce &&S_ISREG (ce->ce_mode))return ce->ce_mode;return create_ce_mode (0666 );@@ -228,7 +228,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 :@@ -338,7 +338,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 ;
read-cache.c int add_to_index(struct index_state *istate, const char *path, struct stat *st, · line 765
Quoted 8 lines
read-cache.c +1
-1@@ -759,7 +759,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 (the_repository) && has_symlinks) { ce->ce_mode =create_ce_mode (st_mode); }else {/* If there is an existing entry, pick the mode bits and type
There seem to be typos everywhere here, will change in the next reroll.
Regards, yuchen
Re: [PATCH v2 3/3] environment: move trust_executable_bit into repo_config_values
In reply to Tian YuchenQuoted 2 lines · Tian Yuchen
+/*
+ * Getters for therepo_trust_executable_bitfields ofstruct repo_config_values.
s/Getters/Getter/
s/fields/field/
s/repo_trust_executable_bit/trust_executable_bit/
Quoted 4 lines
+ * They check
repo->gitdirto prevent callingrepo_config_values()
+ * before the configuration is loaded or in bare environments.
+ */
+intrepo_trust_executable_bit(struct repository *repo);
Thanks.
Re: [PATCH v2 3/3] environment: move trust_executable_bit into repo_config_values
Quoted 9 lines · Christian Couder
Quoted 2 lines · Tian Yuchen
+/*
+ * Getters for therepo_trust_executable_bitfields ofstruct repo_config_values.s/Getters/Getter/
s/fields/field/
s/repo_trust_executable_bit/trust_executable_bit/
Quoted 6 lines
Quoted 4 lines
+ * They check
repo->gitdirto prevent callingrepo_config_values()
+ * before the configuration is loaded or in bare environments.
+ */
+intrepo_trust_executable_bit(struct repository *repo);Thanks.
Thanks.
A hopefully small and final reroll is in order, and <[email protected]> has already promised one.
v3 cover environment: migrate 'trust_executable_bit' into 'repo_config_values'
In reply to Tian YuchenThe 'core.filemode' (stored as 'trust_executable_bit') configuration act as a core filesystem capability flag.
This series moves it into 'struct repo_config_values' to tie it to the specific repository instance it was read from. Eager parsing is maintained because this flag is heavily consulted in hot paths.
Note: 'repo_config_values()' still does not support any struct repository other than the_repository due to how deeply these flags are accessed. In other words, this series of patches is laying the groundwork for the eventual elimination of the_repository.
Previous related work:
[PATCH 2/6] config: add trust_executable_bit to global config [1] [PATCH] Refactor 'trust_executable_bit' to repository-scoped setting [2] (This previous attempt was unsuccessful because the target location selected was 'struct repo_settings', which our analysis indicated was not the optimal choice. For further details, please see: [3])
Changes since V2:
Fixed a whole bunch of typos;
Moved the comment for 'ce_mode_from_stat()' from 'read-cache.c' to 'read-cache.h'.
Thanks!
[1] https://lore.kernel.org/git/837b5360b40f992351f489a0ae05fedf49884c6e.1685716420.git.gitgitgadget@gmail.com/
[2] https://lore.kernel.org/git/[email protected]/
[3] https://lore.kernel.org/git/[email protected]/
Tian Yuchen (3):
read-cache: remove redundant extern declarations
read-cache: move 'ce_mode_from_stat()' to 'read-cache.c'
environment: move trust_executable_bit into repo_config_values
apply.c | 2 +- environment.c | 11 +++++++++-- environment.h | 9 ++++++++- read-cache.c | 21 ++++++++++++++++----- read-cache.h | 23 +++++++++-------------- 5 files changed, 43 insertions(+), 23 deletions(-)
Signature · 1 line
2.43.0
PATCH v3 1/3 read-cache: remove redundant extern declarations
The 'read-cache.c' file already includes 'environment.h', which provides the extern declarations for variables like 'trust_executable_bit' and 'has_symlinks'.
Remove the redundant extern declarations inside 'st_mode_from_ce()' to clean up the code.
--- read-cache.c | 2 -- 1 file changed, 2 deletions(-)
read-cache.c +0 -2
@@ -204,8 +204,6 @@ void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, ststatic unsigned int st_mode_from_ce (const struct cache_entry *ce) { -extern int trust_executable_bit, has_symlinks; -switch (ce->ce_mode &S_IFMT ) {case S_IFLNK :return has_symlinks ?S_IFLNK : (S_IFREG |0644 );
Signature · 1 line
2.43.0
PATCH v3 2/3 read-cache: move 'ce_mode_from_stat()' to 'read-cache.c'
In reply to Tian YuchenThe ce_mode_from_stat() function is declared as a static inline function in 'read-cache.h'. As we want to migrate configuration variables, this helper function will need access to corresponding repository-specific configuration logic. Move the implementation to 'read-cache.c' to cleanly encapsulate its dependencies.
Note that the 'extern int trust_executable_bit, has_symlinks;' line is discarded because it's not necessary when the function lives in "read-cache.c".
At present, this change has no visible impact, but it is crucial for our future plans to pass in the repo context. Comment has been added whilst we are at it.
--- read-cache.c | 13 +++++++++++++ read-cache.h | 23 +++++++++-------------- 2 files changed, 22 insertions(+), 14 deletions(-)
read-cache.c +13 -0
@@ -202,6 +202,19 @@ void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, st } } +unsigned int ce_mode_from_stat (const struct cache_entry *ce,unsigned int mode) +{ +if (!has_symlinks &&S_ISREG (mode) && + ce &&S_ISLNK (ce->ce_mode)) +return ce->ce_mode; +if (!trust_executable_bit &&S_ISREG (mode)) { +if (ce &&S_ISREG (ce->ce_mode)) +return ce->ce_mode; +return create_ce_mode (0666 ); + } +return create_ce_mode (mode); +} +static unsigned int st_mode_from_ce (const struct cache_entry *ce) {switch (ce->ce_mode &S_IFMT ) {
read-cache.h +9 -14
@@ -5,20 +5,15 @@#include "object.h" #include "pathspec.h" -static inline unsigned int ce_mode_from_stat (const struct cache_entry *ce, -unsigned int mode) -{ -extern int trust_executable_bit, 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 (ce &&S_ISREG (ce->ce_mode)) -return ce->ce_mode; -return create_ce_mode (0666 ); - } -return create_ce_mode (mode); -} +/* +* Determine the appropriate index mode for a file based on its stat() +* information and the existing cache entry (if any). +* +* This function handles degradation for filesystems that lack +* symlink support or reliable executable bits. +*/ +unsigned int ce_mode_from_stat (const struct cache_entry *ce, +unsigned int mode);static inline int ce_to_dtype (const struct cache_entry *ce) {
Signature · 1 line
2.43.0
PATCH v3 3/3 environment: move trust_executable_bit into repo_config_values
In reply to Tian YuchenMove 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.
For now, associated functions access this configuration by explicitly falling back to 'the_repository'.
--- apply.c | 2 +- environment.c | 11 +++++++++-- environment.h | 9 ++++++++- read-cache.c | 8 ++++---- 4 files changed, 22 insertions(+), 8 deletions(-)
apply.c +1 -1
@@ -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 (the_repository) || !S_ISREG (st->st_mode)) st_mode =ce_mode_from_stat (*ce, st->st_mode);else if (*ce) st_mode = (*ce)->ce_mode;
environment.c +9 -2
@@ -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->gitdir? +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 ; }
environment.h +8 -1
@@ -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,13 @@ 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); +/* +* Getter for the `trust_executable_bit` field of `struct repo_config_values`. +* It checks `repo->gitdir` to prevent calling repo_config_values() +* before the configuration is loaded or in bare environments. +*/ +int repo_trust_executable_bit (struct repository *repo); +void repo_config_values_init (struct repo_config_values *cfg);/*
@@ -160,7 +168,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 +4 -4
@@ -207,7 +207,7 @@ unsigned int ce_mode_from_stat(const struct cache_entry *ce, unsigned int mode)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_trust_executable_bit (the_repository) &&S_ISREG (mode)) {if (ce &&S_ISREG (ce->ce_mode))return ce->ce_mode;return create_ce_mode (0666 );
@@ -221,7 +221,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 :
@@ -331,7 +331,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 ;
@@ -752,7 +752,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 (the_repository) && has_symlinks) { ce->ce_mode =create_ce_mode (st_mode); }else {/* If there is an existing entry, pick the mode bits and type
Signature · 1 line
2.43.0
v4 cover environment: migrate 'trust_executable_bit' into 'repo_config_values'
In reply to Tian YuchenThe 'core.filemode' (stored as 'trust_executable_bit') configuration act as a core filesystem capability flag.
This series moves it into 'struct repo_config_values' to tie it to the specific repository instance it was read from. Eager parsing is maintained because this flag is heavily consulted in hot paths.
Note: 'repo_config_values()' still does not support any struct repository other than the_repository due to how deeply these flags are accessed. In other words, this series of patches is laying the groundwork for the eventual elimination of the_repository.
Previous related work:
[PATCH 2/6] config: add trust_executable_bit to global config [1] [PATCH] Refactor 'trust_executable_bit' to repository-scoped setting [2] (This previous attempt was unsuccessful because the target location selected was 'struct repo_settings', which our analysis indicated was not the optimal choice. For further details, please see: [3])
Change since V3:
- In repo_trust_executable_bit(), change repo->gitdir to using (repo && repo->initialized).
Thanks!
[1] https://lore.kernel.org/git/837b5360b40f992351f489a0ae05fedf49884c6e.1685716420.git.gitgitgadget@gmail.com/
[2] https://lore.kernel.org/git/[email protected]/
[3] https://lore.kernel.org/git/[email protected]/
Tian Yuchen (3):
read-cache: remove redundant extern declarations
read-cache: move 'ce_mode_from_stat()' to 'read-cache.c'
environment: move trust_executable_bit into repo_config_values
apply.c | 2 +- environment.c | 11 +++++++++-- environment.h | 9 ++++++++- read-cache.c | 21 ++++++++++++++++----- read-cache.h | 23 +++++++++-------------- 5 files changed, 43 insertions(+), 23 deletions(-)
Signature · 1 line
2.43.0
PATCH v4 1/3 read-cache: remove redundant extern declarations
The 'read-cache.c' file already includes 'environment.h', which provides the extern declarations for variables like 'trust_executable_bit' and 'has_symlinks'.
Remove the redundant extern declarations inside 'st_mode_from_ce()' to clean up the code.
--- read-cache.c | 2 -- 1 file changed, 2 deletions(-)
read-cache.c +0 -2
@@ -204,8 +204,6 @@ void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, ststatic unsigned int st_mode_from_ce (const struct cache_entry *ce) { -extern int trust_executable_bit, has_symlinks; -switch (ce->ce_mode &S_IFMT ) {case S_IFLNK :return has_symlinks ?S_IFLNK : (S_IFREG |0644 );
Signature · 1 line
2.43.0
PATCH v4 2/3 read-cache: move 'ce_mode_from_stat()' to 'read-cache.c'
In reply to Tian YuchenThe ce_mode_from_stat() function is declared as a static inline function in 'read-cache.h'. As we want to migrate configuration variables, this helper function will need access to corresponding repository-specific configuration logic. Move the implementation to 'read-cache.c' to cleanly encapsulate its dependencies.
Note that the 'extern int trust_executable_bit, has_symlinks;' line is discarded because it's not necessary when the function lives in "read-cache.c".
At present, this change has no visible impact, but it is crucial for our future plans to pass in the repo context. Comment has been added whilst we are at it.
--- read-cache.c | 13 +++++++++++++ read-cache.h | 23 +++++++++-------------- 2 files changed, 22 insertions(+), 14 deletions(-)
read-cache.c +13 -0
@@ -202,6 +202,19 @@ void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, st } } +unsigned int ce_mode_from_stat (const struct cache_entry *ce,unsigned int mode) +{ +if (!has_symlinks &&S_ISREG (mode) && + ce &&S_ISLNK (ce->ce_mode)) +return ce->ce_mode; +if (!trust_executable_bit &&S_ISREG (mode)) { +if (ce &&S_ISREG (ce->ce_mode)) +return ce->ce_mode; +return create_ce_mode (0666 ); + } +return create_ce_mode (mode); +} +static unsigned int st_mode_from_ce (const struct cache_entry *ce) {switch (ce->ce_mode &S_IFMT ) {
read-cache.h +9 -14
@@ -5,20 +5,15 @@#include "object.h" #include "pathspec.h" -static inline unsigned int ce_mode_from_stat (const struct cache_entry *ce, -unsigned int mode) -{ -extern int trust_executable_bit, 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 (ce &&S_ISREG (ce->ce_mode)) -return ce->ce_mode; -return create_ce_mode (0666 ); - } -return create_ce_mode (mode); -} +/* +* Determine the appropriate index mode for a file based on its stat() +* information and the existing cache entry (if any). +* +* This function handles degradation for filesystems that lack +* symlink support or reliable executable bits. +*/ +unsigned int ce_mode_from_stat (const struct cache_entry *ce, +unsigned int mode);static inline int ce_to_dtype (const struct cache_entry *ce) {
Signature · 1 line
2.43.0
PATCH v4 3/3 environment: move trust_executable_bit into repo_config_values
In reply to Tian YuchenMove 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.
For now, associated functions access this configuration by explicitly falling back to 'the_repository'.
--- apply.c | 2 +- environment.c | 11 +++++++++-- environment.h | 9 ++++++++- read-cache.c | 8 ++++---- 4 files changed, 22 insertions(+), 8 deletions(-)
apply.c +1 -1
@@ -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 (the_repository) || !S_ISREG (st->st_mode)) st_mode =ce_mode_from_stat (*ce, st->st_mode);else if (*ce) st_mode = (*ce)->ce_mode;
environment.c +9 -2
@@ -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 && 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 ; }
environment.h +8 -1
@@ -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,13 @@ 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); +/* +* Getter for the `trust_executable_bit` field of `struct repo_config_values`. +* It checks `repo->initialized` to prevent calling repo_config_values()` +* before the repository setup is fully complete or in non-git environments. +*/ +int repo_trust_executable_bit (struct repository *repo); +void repo_config_values_init (struct repo_config_values *cfg);/*
@@ -160,7 +168,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 +4 -4
@@ -207,7 +207,7 @@ unsigned int ce_mode_from_stat(const struct cache_entry *ce, unsigned int mode)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_trust_executable_bit (the_repository) &&S_ISREG (mode)) {if (ce &&S_ISREG (ce->ce_mode))return ce->ce_mode;return create_ce_mode (0666 );
@@ -221,7 +221,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 :
@@ -331,7 +331,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 ;
@@ -752,7 +752,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 (the_repository) && has_symlinks) { ce->ce_mode =create_ce_mode (st_mode); }else {/* If there is an existing entry, pick the mode bits and type
Signature · 1 line
2.43.0
Re: [PATCH v4 0/3] environment: migrate 'trust_executable_bit' into 'repo_config_values'
In reply to Tian YuchenQuoted 2 lines · Tian Yuchen
The 'core.filemode' (stored as '
trust_executable_bit') configuration act as a core filesystem capability flag.
This unfortunately hasn't heard any responses since June 19th. Are there remaining issues with it? Or do people fundamentally have objections against this change? Or things are too busy in general that there are more patches than there are folks willing to review them?
Re: [PATCH v4 0/3] environment: migrate 'trust_executable_bit' into 'repo_config_values'
Quoted 10 lines · Junio C Hamano
Quoted 2 lines · Tian Yuchen
The 'core.filemode' (stored as '
trust_executable_bit') configuration act as a core filesystem capability flag.This unfortunately hasn't heard any responses since June 19th. Are there remaining issues with it? Or do people fundamentally have objections against this change? Or things are too busy in general that there are more patches than there are folks willing to review them?
Seems that no many people are viewing this. Let me send V5 which includes a new commit and a few changes.
Hope this helps.
Thanks, yuchen
v5 cover environment: migrate 'trust_executable_bit' and 'has_symlinks' into 'repo_config_values'
In reply to Tian YuchenThis series moves 'trust_executable_bit' and 'has_symlinks' into 'struct repo_config_values' to tie them to the specific repository instance they were read from. Eager parsing is maintained because these two flags are heavily consulted in hot paths.
Note: 'repo_config_values()' still does not support any struct repository other than the_repository due to how deeply these flags are accessed. In other words, this series of patches is laying the groundwork for the eventual elimination of the_repository.
Previous related work:
[PATCH 2/6] config: add trust_executable_bit to global config [1] [PATCH] Refactor 'trust_executable_bit' to repository-scoped setting [2] (This previous attempt was unsuccessful because the target location selected was 'struct repo_settings', which our analysis indicated was not the optimal choice. For further details, please see: [3])
[PATCH 5/6] config: move has_symlinks [4]
RFC:
- I wonder if there is a better way to deal with compat/mingw.c in commit 4/4. Is it possible not to introduce a fallback variable?
Change since V4:
- the migration of has_symlinks is back [5], as a commit 4/4;
- drop the comment for repo_executable_bit();
- do not always pass the_repository to the getters. Use 'repo' when possible.
Thanks!
[1] https://lore.kernel.org/git/837b5360b40f992351f489a0ae05fedf49884c6e.1685716420.git.gitgitgadget@gmail.com/
[2] https://lore.kernel.org/git/[email protected]/
[3] https://lore.kernel.org/git/[email protected]/
[4] https://lore.kernel.org/git/a154008619790f7a60f2bba91db7b0fe29e67e1a.1685716420.git.gitgitgadget@gmail.com/
[5] https://lore.kernel.org/git/[email protected]/
Tian Yuchen (4):
read-cache: remove redundant extern declarations
read-cache: move 'ce_mode_from_stat()' to 'read-cache.c'
environment: move trust_executable_bit into repo_config_values
environment: move has_symlinks into repo_config_values
apply.c | 4 ++-- combine-diff.c | 2 +- compat/mingw.c | 7 ++++--- entry.c | 2 +- environment.c | 28 ++++++++++++++++++++++++---- environment.h | 9 +++++++-- read-cache.c | 33 ++++++++++++++++++++++++++------- read-cache.h | 16 ++-------------- 8 files changed, 67 insertions(+), 34 deletions(-)
Signature · 1 line
2.43.0
PATCH v5 1/4 read-cache: remove redundant extern declarations
The 'read-cache.c' file already includes 'environment.h', which provides the extern declarations for variables like 'trust_executable_bit' and 'has_symlinks'.
Remove the redundant extern declarations inside 'st_mode_from_ce()' to clean up the code.
--- read-cache.c | 2 -- 1 file changed, 2 deletions(-)
read-cache.c +0 -2
@@ -204,8 +204,6 @@ void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, ststatic unsigned int st_mode_from_ce (const struct cache_entry *ce) { -extern int trust_executable_bit, has_symlinks; -switch (ce->ce_mode &S_IFMT ) {case S_IFLNK :return has_symlinks ?S_IFLNK : (S_IFREG |0644 );
Signature · 1 line
2.43.0
PATCH v5 2/4 read-cache: move 'ce_mode_from_stat()' to 'read-cache.c'
In reply to Tian YuchenThe ce_mode_from_stat() function is declared as a static inline function in 'read-cache.h'. As we want to migrate configuration variables, this helper function will need access to corresponding repository-specific configuration logic. Move the implementation to 'read-cache.c' to cleanly encapsulate its dependencies.
Note that the 'extern int trust_executable_bit, has_symlinks;' line is discarded because it's not necessary when the function lives in "read-cache.c".
At present, this change has no visible impact, but it is crucial for our future plans to pass in the repo context. Comment has been added whilst we are at it.
--- read-cache.c | 20 ++++++++++++++++++++ read-cache.h | 16 ++-------------- 2 files changed, 22 insertions(+), 14 deletions(-)
read-cache.c +20 -0
@@ -202,6 +202,26 @@ void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, st } } +/* +* Determine the appropriate index mode for a file based on its stat() +* information and the existing cache entry (if any). +* +* This function handles degradation for filesystems that lack +* symlink support or reliable executable bits. +*/ +unsigned int ce_mode_from_stat (const struct cache_entry *ce,unsigned int mode) +{ +if (!has_symlinks &&S_ISREG (mode) && + ce &&S_ISLNK (ce->ce_mode)) +return ce->ce_mode; +if (!trust_executable_bit &&S_ISREG (mode)) { +if (ce &&S_ISREG (ce->ce_mode)) +return ce->ce_mode; +return create_ce_mode (0666 ); + } +return create_ce_mode (mode); +} +static unsigned int st_mode_from_ce (const struct cache_entry *ce) {switch (ce->ce_mode &S_IFMT ) {
read-cache.h +2 -14
@@ -5,20 +5,8 @@#include "object.h" #include "pathspec.h" -static inline unsigned int ce_mode_from_stat (const struct cache_entry *ce, -unsigned int mode) -{ -extern int trust_executable_bit, 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 (ce &&S_ISREG (ce->ce_mode)) -return ce->ce_mode; -return create_ce_mode (0666 ); - } -return create_ce_mode (mode); -} +unsigned int ce_mode_from_stat (const struct cache_entry *ce, +unsigned int mode);static inline int ce_to_dtype (const struct cache_entry *ce) {
Signature · 1 line
2.43.0
PATCH v5 3/4 environment: move trust_executable_bit into repo_config_values
In reply to Tian YuchenMove 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.
--- apply.c | 2 +- environment.c | 11 +++++++++-- environment.h | 4 +++- read-cache.c | 8 ++++---- 4 files changed, 17 insertions(+), 8 deletions(-)
apply.c +1 -1
@@ -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 (*ce, st->st_mode);else if (*ce) st_mode = (*ce)->ce_mode;
environment.c +9 -2
@@ -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->gitdir? +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 ; }
environment.h +3 -1
@@ -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);/*
@@ -160,7 +163,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 +4 -4
@@ -214,7 +214,7 @@ unsigned int ce_mode_from_stat(const struct cache_entry *ce, unsigned int mode)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_trust_executable_bit (the_repository) &&S_ISREG (mode)) {if (ce &&S_ISREG (ce->ce_mode))return ce->ce_mode;return create_ce_mode (0666 );
@@ -228,7 +228,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 :
@@ -338,7 +338,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 ;
@@ -759,7 +759,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
Signature · 1 line
2.43.0
PATCH v5 4/4 environment: move has_symlinks into repo_config_values
In reply to Tian YuchenMove the global 'has_symlinks' configuration into the repository-specific 'repo_config_values' struct.
To ensure code readability, the getter function 'repo_has_symlinks()' has been introduced. Callers access this configuration by passing in 'repo' when possible, and explicitly fall back to 'the_repository' the rest of the time.
Note:
To support early platform-specific (MinGW) overrides before repository initialization, a global variable 'default_has_symlinks' fallback is introduced as a fallback in environment.h. The *writer* in compat/mingw.c can only access this variable.
--- apply.c | 2 +- combine-diff.c | 2 +- compat/mingw.c | 7 ++++--- entry.c | 2 +- environment.c | 17 +++++++++++++++-- environment.h | 5 ++++- read-cache.c | 9 +++++---- 7 files changed, 31 insertions(+), 13 deletions(-)
apply.c +1 -1
@@ -4511,7 +4511,7 @@ static int try_create_file(struct apply_state *state, const char *path,return !!mkdir (path,0777 ); } -if (has_symlinks &&S_ISLNK (mode)) +if (repo_has_symlinks (state->repo) &&S_ISLNK (mode))/* Although buf:size is counted string, it also is NUL * terminated. */
combine-diff.c +1 -1
@@ -1078,7 +1078,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,/* if symlinks don't work, assume symlink if all parents * are symlinks */ - is_file = has_symlinks; + is_file =repo_has_symlinks (rev->repo);for (i =0 ; !is_file && i < num_parent; i++) is_file = !S_ISLNK (elem->parent[i].mode);if (!is_file)
compat/mingw.c +4 -3
@@ -7,6 +7,7 @@#include "config.h" #include "dir.h" #include "environment.h" +#include "repository.h" #include "gettext.h" #include "run-command.h" #include "strbuf.h"
@@ -1043,7 +1044,7 @@ int mingw_chdir(const char *dirname)if (xutftowcs_path (wdirname, dirname) <0 )return -1 ; -if (has_symlinks) { +if (repo_has_symlinks (the_repository)) {HANDLE hnd =CreateFileW (wdirname,0 ,FILE_SHARE_READ |FILE_SHARE_WRITE |FILE_SHARE_DELETE ,NULL ,OPEN_EXISTING ,FILE_FLAG_BACKUP_SEMANTICS ,NULL );
@@ -2903,7 +2904,7 @@ int symlink(const char *target, const char *link)int len;/* fail if symlinks are disabled or API is not supported (WinXP) */ -if (!has_symlinks) { +if (!repo_has_symlinks (the_repository)) { errno =ENOSYS ;return -1 ; }
@@ -3181,7 +3182,7 @@ static void setup_windows_environment(void)* symlink support. */ if (!(tmp =getenv ("MSYS" )) || !strstr (tmp,"winsymlinks:nativestrict" )) - has_symlinks =0 ; + default_has_symlinks =0 ; }static void get_current_user_sid (PSID *sid,HANDLE *linked_token)
entry.c +1 -1
@@ -321,7 +321,7 @@ static int write_entry(struct cache_entry *ce, char *path, struct conv_attrs *ca* We can't make a real symlink; write out a regular file entry * with the symlink destination as its contents. */ -if (!has_symlinks || to_tempfile) +if (!repo_has_symlinks (state->istate ? state->istate->repo :NULL ) || to_tempfile) goto write_file_entry; ret =symlink (new_blob, path);
environment.c +15 -2
@@ -43,7 +43,7 @@ static int zlib_compression_seen;int trust_ctime =1 ;int check_stat =1 ; -int has_symlinks =1 ; +int default_has_symlinks =1 ;int minimum_abbrev =4 , default_abbrev =-1 ;int ignore_case;int assume_unchanged;
@@ -148,6 +148,17 @@ int repo_trust_executable_bit(struct repository *repo)1 ; } +int repo_has_symlinks (struct repository *repo) +{ +if (!repo) + repo = the_repository; + +if (!repo->gitdir) +return default_has_symlinks; + +return repo_config_values (repo)->has_symlinks; +} +int have_git_dir (void ) {return startup_info->have_repository
@@ -336,7 +347,8 @@ int git_default_core_config(const char *var, const char *value, }if (!strcmp (var,"core.symlinks" )) { - has_symlinks =git_config_bool (var, value); +struct repo_config_values *cfg =repo_config_values (the_repository); + cfg->has_symlinks =git_config_bool (var, value);return 0 ; }
@@ -727,5 +739,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->has_symlinks = default_has_symlinks; cfg->branch_track =BRANCH_TRACK_REMOTE ; }
environment.h +4 -1
@@ -92,6 +92,7 @@ struct repo_config_values {char *attributes_file;int apply_sparse_checkout;int trust_executable_bit; +int has_symlinks;/* section "branch" config values */ enum branch_track branch_track;
@@ -126,6 +127,8 @@ int git_default_core_config(const char *var, const char *value,int repo_trust_executable_bit (struct repository *repo); +int repo_has_symlinks (struct repository *repo); +void repo_config_values_init (struct repo_config_values *cfg);/*
@@ -165,7 +168,7 @@ extern char *git_work_tree_cfg;/* Environment bits from configuration mechanism */ extern int trust_ctime;extern int check_stat; -extern int has_symlinks; +extern int default_has_symlinks;extern int minimum_abbrev, default_abbrev;extern int ignore_case;extern int assume_unchanged;
read-cache.c +5 -4
@@ -211,7 +211,7 @@ void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, st*/ unsigned int ce_mode_from_stat (const struct cache_entry *ce,unsigned int mode) { -if (!has_symlinks &&S_ISREG (mode) && +if (!repo_has_symlinks (the_repository) &&S_ISREG (mode) && ce &&S_ISLNK (ce->ce_mode))return ce->ce_mode;if (!repo_trust_executable_bit (the_repository) &&S_ISREG (mode)) {
@@ -226,7 +226,7 @@ static unsigned int st_mode_from_ce(const struct cache_entry *ce) {switch (ce->ce_mode &S_IFMT ) {case S_IFLNK : -return has_symlinks ?S_IFLNK : (S_IFREG |0644 ); +return repo_has_symlinks (the_repository) ?S_IFLNK : (S_IFREG |0644 );case S_IFREG :return (ce->ce_mode & (repo_trust_executable_bit (the_repository) ?0755 :0644 )) |S_IFREG ;case S_IFGITLINK :
@@ -344,7 +344,7 @@ static int ce_match_stat_basic(const struct cache_entry *ce, struct stat *st)break ;case S_IFLNK :if (!S_ISLNK (st->st_mode) && - (has_symlinks || !S_ISREG (st->st_mode))) + (repo_has_symlinks (the_repository) || !S_ISREG (st->st_mode))) changed |=TYPE_CHANGED ;break ;case S_IFGITLINK :
@@ -759,7 +759,8 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st, ce->ce_flags |=CE_INTENT_TO_ADD ; -if (repo_trust_executable_bit (istate->repo) && has_symlinks) { +if (repo_trust_executable_bit (istate->repo) && +repo_has_symlinks (istate->repo)) { ce->ce_mode =create_ce_mode (st_mode); }else {/* If there is an existing entry, pick the mode bits and type
Signature · 1 line
2.43.0
Re: [PATCH v5 4/4] environment: move has_symlinks into repo_config_values
Quoted 10 lines · Tian Yuchen
Move the global '
has_symlinks' configuration into the repository-specific 'repo_config_values' struct.To ensure code readability, the getter function '
repo_has_symlinks()' has been introduced. Callers access this configuration by passing in 'repo' when possible, and explicitly fall back to 'the_repository' the rest of the time.
Quoted 4 lines
Note:
To support early platform-specific (MinGW) overrides before repository initialization, a global variable 'default_has_symlinks' fallback is introduced as a fallback
It seems a bit redundant to use "fallback" twice in the above sentence.
Quoted 2 lines
in
environment.h. The *writer* incompat/mingw.ccan only access this variable.
Otherwise this series looks good to me.
Thanks.
Re: [PATCH v5 4/4] environment: move has_symlinks into repo_config_values
Quoted 16 lines · Christian Couder
Quoted 10 lines · Tian Yuchen
Move the global '
has_symlinks' configuration into the repository-specific 'repo_config_values' struct.To ensure code readability, the getter function '
repo_has_symlinks()' has been introduced. Callers access this configuration by passing in 'repo' when possible, and explicitly fall back to 'the_repository' the rest of the time.Quoted 4 lines
Note:
To support early platform-specific (MinGW) overrides before repository initialization, a global variable 'default_has_symlinks' fallback is introduced as a fallback
Quoted 6 lines
It seems a bit redundant to use "fallback" twice in the above sentence.
Quoted 2 lines
in
environment.h. The *writer* incompat/mingw.ccan only access this variable.Otherwise this series looks good to me.
Thanks for helping, Christian, and thanks, Tian, for working on this topic.
Re: [PATCH v5 4/4] environment: move has_symlinks into repo_config_values
In reply to Tian YuchenQuoted 6 lines · Tian Yuchen
Note:
To support early platform-specific (MinGW) overrides before repository initialization, a global variable 'default_has_symlinks' fallback is introduced as a fallback inenvironment.h. The *writer* incompat/mingw.ccan only access this variable.
This may invite people to abuse the global variable. I wonder if we want to do something similar to how we handle is_dir_sep() and friends instead.
The idea is to have something like this in the generic header:
#ifndef platform_has_symlinks
#define platform_has_symlinks() 1
#endifAnd then allow selected platforms override it:
/* in compat/mingw.h */
#define platform_has_symlinks() mingw_platform_has_symlinks()
extern int mingw_platform_has_symlinks(void);
/* in compat/mingw.c */
int mingw_platform_has_symlinks(void)
{
if (!(tmp = getenv("MSYS")) || !strstr(tmp, "winsymlinks:nativestrict"))
return 0;
else
return 1;
}This keeps the namespace clean and avoids exposing a mutable state variable that others might be tempted to meddle with.
v6 cover environment: migrate 'trust_executable_bit' and 'has_symlinks' into 'repo_config_values'
In reply to Tian YuchenThis series moves 'trust_executable_bit' and 'has_symlinks' into 'struct repo_config_values' to tie them to the specific repository instance they were read from. Eager parsing is maintained because these two flags are heavily consulted in hot paths.
Note: 'repo_config_values()' still does not support any struct repository other than the_repository due to how deeply these flags are accessed. In other words, this series of patches is laying the groundwork for the eventual elimination of the_repository.
Previous related work:
[PATCH 2/6] config: add trust_executable_bit to global config [1] [PATCH] Refactor 'trust_executable_bit' to repository-scoped setting [2] (This previous attempt was unsuccessful because the target location selected was 'struct repo_settings', which our analysis indicated was not the optimal choice. For further details, please see: [3])
[PATCH 5/6] config: move has_symlinks [4]
RFC:
- Is the locations of the newly introduced definitions/macros appropriate?
Change since V5:
- do not intruduce new global variable to deal with compat/mingw.c. Make use of macro preprocessing to allow platforms to override platform_has_symlinks().
Thanks!
[1] https://lore.kernel.org/git/837b5360b40f992351f489a0ae05fedf49884c6e.1685716420.git.gitgitgadget@gmail.com/
[2] https://lore.kernel.org/git/[email protected]/
[3] https://lore.kernel.org/git/[email protected]/
[4] https://lore.kernel.org/git/a154008619790f7a60f2bba91db7b0fe29e67e1a.1685716420.git.gitgitgadget@gmail.com/
[5] https://lore.kernel.org/git/[email protected]/
Tian Yuchen (4):
read-cache: remove redundant extern declarations
read-cache: move 'ce_mode_from_stat()' to 'read-cache.c'
environment: move trust_executable_bit into repo_config_values
environment: move has_symlinks into repo_config_values
apply.c | 4 ++-- combine-diff.c | 2 +- compat/mingw.c | 17 +++++++++++++---- compat/mingw.h | 3 +++ entry.c | 2 +- environment.c | 27 +++++++++++++++++++++++---- environment.h | 8 ++++++-- git-compat-util.h | 4 ++++ read-cache.c | 33 ++++++++++++++++++++++++++------- read-cache.h | 16 ++-------------- 10 files changed, 81 insertions(+), 35 deletions(-)
Signature · 1 line
2.43.0
PATCH v6 1/4 read-cache: remove redundant extern declarations
The 'read-cache.c' file already includes 'environment.h', which provides the extern declarations for variables like 'trust_executable_bit' and 'has_symlinks'.
Remove the redundant extern declarations inside 'st_mode_from_ce()' to clean up the code.
--- read-cache.c | 2 -- 1 file changed, 2 deletions(-)
read-cache.c +0 -2
@@ -204,8 +204,6 @@ void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, ststatic unsigned int st_mode_from_ce (const struct cache_entry *ce) { -extern int trust_executable_bit, has_symlinks; -switch (ce->ce_mode &S_IFMT ) {case S_IFLNK :return has_symlinks ?S_IFLNK : (S_IFREG |0644 );
Signature · 1 line
2.43.0
PATCH v6 2/4 read-cache: move 'ce_mode_from_stat()' to 'read-cache.c'
In reply to Tian YuchenThe ce_mode_from_stat() function is declared as a static inline function in 'read-cache.h'. As we want to migrate configuration variables, this helper function will need access to corresponding repository-specific configuration logic. Move the implementation to 'read-cache.c' to cleanly encapsulate its dependencies.
Note that the 'extern int trust_executable_bit, has_symlinks;' line is discarded because it's not necessary when the function lives in "read-cache.c".
At present, this change has no visible impact, but it is crucial for our future plans to pass in the repo context. Comment has been added whilst we are at it.
--- read-cache.c | 20 ++++++++++++++++++++ read-cache.h | 16 ++-------------- 2 files changed, 22 insertions(+), 14 deletions(-)
read-cache.c +20 -0
@@ -202,6 +202,26 @@ void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, st } } +/* +* Determine the appropriate index mode for a file based on its stat() +* information and the existing cache entry (if any). +* +* This function handles degradation for filesystems that lack +* symlink support or reliable executable bits. +*/ +unsigned int ce_mode_from_stat (const struct cache_entry *ce,unsigned int mode) +{ +if (!has_symlinks &&S_ISREG (mode) && + ce &&S_ISLNK (ce->ce_mode)) +return ce->ce_mode; +if (!trust_executable_bit &&S_ISREG (mode)) { +if (ce &&S_ISREG (ce->ce_mode)) +return ce->ce_mode; +return create_ce_mode (0666 ); + } +return create_ce_mode (mode); +} +static unsigned int st_mode_from_ce (const struct cache_entry *ce) {switch (ce->ce_mode &S_IFMT ) {
read-cache.h +2 -14
@@ -5,20 +5,8 @@#include "object.h" #include "pathspec.h" -static inline unsigned int ce_mode_from_stat (const struct cache_entry *ce, -unsigned int mode) -{ -extern int trust_executable_bit, 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 (ce &&S_ISREG (ce->ce_mode)) -return ce->ce_mode; -return create_ce_mode (0666 ); - } -return create_ce_mode (mode); -} +unsigned int ce_mode_from_stat (const struct cache_entry *ce, +unsigned int mode);static inline int ce_to_dtype (const struct cache_entry *ce) {
Signature · 1 line
2.43.0
Re: [PATCH v6 2/4] read-cache: move 'ce_mode_from_stat()' to 'read-cache.c'
Quoted 9 lines · Tian Yuchen
The
ce_mode_from_stat()function is declared as a static inline function in 'read-cache.h'. As we want to migrate configuration variables, this helper function will need access to corresponding repository-specific configuration logic. Move the implementation to 'read-cache.c' to cleanly encapsulate its dependencies.Note that the 'extern int
trust_executable_bit,has_symlinks;' line is discarded because it's not necessary when the function lives in "read-cache.c".
A "static inline" function in a header typically signals that it is expected to be called from the depths of a performance- critical loop. I am not sure if this helper is still in such a hot path, but I wonder if we can keep it inline and still teach it to take a "struct repository *r" (or whatever extra parameter you need) to move these two bits from being global variables to members of a per-repository structure.
PATCH v6 3/4 environment: move trust_executable_bit into repo_config_values
In reply to Tian YuchenMove 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.
--- apply.c | 2 +- environment.c | 11 +++++++++-- environment.h | 4 +++- read-cache.c | 8 ++++---- 4 files changed, 17 insertions(+), 8 deletions(-)
apply.c +1 -1
@@ -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 (*ce, st->st_mode);else if (*ce) st_mode = (*ce)->ce_mode;
environment.c +9 -2
@@ -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->gitdir? +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 ; }
environment.h +3 -1
@@ -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);/*
@@ -160,7 +163,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 +4 -4
@@ -214,7 +214,7 @@ unsigned int ce_mode_from_stat(const struct cache_entry *ce, unsigned int mode)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_trust_executable_bit (the_repository) &&S_ISREG (mode)) {if (ce &&S_ISREG (ce->ce_mode))return ce->ce_mode;return create_ce_mode (0666 );
@@ -228,7 +228,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 :
@@ -338,7 +338,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 ;
@@ -759,7 +759,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
Signature · 1 line
2.43.0
PATCH v6 4/4 environment: move has_symlinks into repo_config_values
In reply to Tian YuchenMove the global 'has_symlinks' configuration into the repository-specific 'repo_config_values' struct.
To ensure code readability, the getter function 'repo_has_symlinks()' has been introduced. Callers access this configuration by passing in 'repo' when possible, and explicitly fall back to 'the_repository' the rest of the time.
Note:
To support platform-specific overrides (MinGW) before repository initialization, the 'platform_has_symlinks()' macro is introduced in git-compat-util.h. Platforms can override this in their respective headers.
--- apply.c | 2 +- combine-diff.c | 2 +- compat/mingw.c | 17 +++++++++++++---- compat/mingw.h | 3 +++ entry.c | 2 +- environment.c | 16 ++++++++++++++-- environment.h | 4 +++- git-compat-util.h | 4 ++++ read-cache.c | 9 +++++---- 9 files changed, 45 insertions(+), 14 deletions(-)
apply.c +1 -1
@@ -4511,7 +4511,7 @@ static int try_create_file(struct apply_state *state, const char *path,return !!mkdir (path,0777 ); } -if (has_symlinks &&S_ISLNK (mode)) +if (repo_has_symlinks (state->repo) &&S_ISLNK (mode))/* Although buf:size is counted string, it also is NUL * terminated. */
combine-diff.c +1 -1
@@ -1078,7 +1078,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,/* if symlinks don't work, assume symlink if all parents * are symlinks */ - is_file = has_symlinks; + is_file =repo_has_symlinks (rev->repo);for (i =0 ; !is_file && i < num_parent; i++) is_file = !S_ISLNK (elem->parent[i].mode);if (!is_file)
compat/mingw.c +13 -4
@@ -7,6 +7,7 @@#include "config.h" #include "dir.h" #include "environment.h" +#include "repository.h" #include "gettext.h" #include "run-command.h" #include "strbuf.h"
@@ -1043,7 +1044,7 @@ int mingw_chdir(const char *dirname)if (xutftowcs_path (wdirname, dirname) <0 )return -1 ; -if (has_symlinks) { +if (repo_has_symlinks (the_repository)) {HANDLE hnd =CreateFileW (wdirname,0 ,FILE_SHARE_READ |FILE_SHARE_WRITE |FILE_SHARE_DELETE ,NULL ,OPEN_EXISTING ,FILE_FLAG_BACKUP_SEMANTICS ,NULL );
@@ -2903,7 +2904,7 @@ int symlink(const char *target, const char *link)int len;/* fail if symlinks are disabled or API is not supported (WinXP) */ -if (!has_symlinks) { +if (!repo_has_symlinks (the_repository)) { errno =ENOSYS ;return -1 ; }
@@ -3173,15 +3174,23 @@ static void setup_windows_environment(void)if (!tmp && (tmp =getenv ("USERPROFILE" )))setenv ("HOME" , tmp,1 ); } +} +int mingw_platform_has_symlinks (void ) +{ +static int has_symlinks =-1 ;/* * Change 'core.symlinks' default to false, unless native symlinks are * enabled in MSys2 (via 'MSYS=winsymlinks:nativestrict'). Thus we can * run the test suite (which doesn't obey config files) with or without * symlink support. */ -if (!(tmp =getenv ("MSYS" )) || !strstr (tmp,"winsymlinks:nativestrict" )) - has_symlinks =0 ; +if (has_symlinks <0 ) { +const char *tmp =getenv ("MSYS" ); + has_symlinks = (tmp &&strstr (tmp,"winsymlinks:nativestrict" )) ?1 :0 ; + } + +return has_symlinks; }static void get_current_user_sid (PSID *sid,HANDLE *linked_token)
compat/mingw.h +3 -0
@@ -208,6 +208,9 @@ void open_in_gdb(void);*/ int err_win_to_posix (DWORD winerr); +int mingw_platform_has_symlinks (void ); +#define platform_has_symlinks () mingw_platform_has_symlinks() +#ifndef NO_UNIX_SOCKETS int mingw_have_unix_sockets (void );#undef have_unix_sockets
entry.c +1 -1
@@ -321,7 +321,7 @@ static int write_entry(struct cache_entry *ce, char *path, struct conv_attrs *ca* We can't make a real symlink; write out a regular file entry * with the symlink destination as its contents. */ -if (!has_symlinks || to_tempfile) +if (!repo_has_symlinks (state->istate ? state->istate->repo :NULL ) || to_tempfile) goto write_file_entry; ret =symlink (new_blob, path);
environment.c +14 -2
@@ -43,7 +43,6 @@ static int zlib_compression_seen;int trust_ctime =1 ;int check_stat =1 ; -int has_symlinks =1 ;int minimum_abbrev =4 , default_abbrev =-1 ;int ignore_case;int assume_unchanged;
@@ -148,6 +147,17 @@ int repo_trust_executable_bit(struct repository *repo)1 ; } +int repo_has_symlinks (struct repository *repo) +{ +if (!repo) + repo = the_repository; + +if (!repo->gitdir) +return platform_has_symlinks (); + +return repo_config_values (repo)->has_symlinks; +} +int have_git_dir (void ) {return startup_info->have_repository
@@ -336,7 +346,8 @@ int git_default_core_config(const char *var, const char *value, }if (!strcmp (var,"core.symlinks" )) { - has_symlinks =git_config_bool (var, value); +struct repo_config_values *cfg =repo_config_values (the_repository); + cfg->has_symlinks =git_config_bool (var, value);return 0 ; }
@@ -727,5 +738,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->has_symlinks =platform_has_symlinks (); cfg->branch_track =BRANCH_TRACK_REMOTE ; }
environment.h +3 -1
@@ -92,6 +92,7 @@ struct repo_config_values {char *attributes_file;int apply_sparse_checkout;int trust_executable_bit; +int has_symlinks;/* section "branch" config values */ enum branch_track branch_track;
@@ -126,6 +127,8 @@ int git_default_core_config(const char *var, const char *value,int repo_trust_executable_bit (struct repository *repo); +int repo_has_symlinks (struct repository *repo); +void repo_config_values_init (struct repo_config_values *cfg);/*
@@ -165,7 +168,6 @@ extern char *git_work_tree_cfg;/* Environment bits from configuration mechanism */ extern int trust_ctime;extern int check_stat; -extern int has_symlinks;extern int minimum_abbrev, default_abbrev;extern int ignore_case;extern int assume_unchanged;
git-compat-util.h +4 -0
@@ -245,6 +245,10 @@ static inline int git_is_dir_sep(int c)#define is_dir_sep git_is_dir_sep#endif +#ifndef platform_has_symlinks +#define platform_has_symlinks () 1 +#endif +#ifndef offset_1st_componentstatic inline int git_offset_1st_component (const char *path) {
read-cache.c +5 -4
@@ -211,7 +211,7 @@ void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, st*/ unsigned int ce_mode_from_stat (const struct cache_entry *ce,unsigned int mode) { -if (!has_symlinks &&S_ISREG (mode) && +if (!repo_has_symlinks (the_repository) &&S_ISREG (mode) && ce &&S_ISLNK (ce->ce_mode))return ce->ce_mode;if (!repo_trust_executable_bit (the_repository) &&S_ISREG (mode)) {
@@ -226,7 +226,7 @@ static unsigned int st_mode_from_ce(const struct cache_entry *ce) {switch (ce->ce_mode &S_IFMT ) {case S_IFLNK : -return has_symlinks ?S_IFLNK : (S_IFREG |0644 ); +return repo_has_symlinks (the_repository) ?S_IFLNK : (S_IFREG |0644 );case S_IFREG :return (ce->ce_mode & (repo_trust_executable_bit (the_repository) ?0755 :0644 )) |S_IFREG ;case S_IFGITLINK :
@@ -344,7 +344,7 @@ static int ce_match_stat_basic(const struct cache_entry *ce, struct stat *st)break ;case S_IFLNK :if (!S_ISLNK (st->st_mode) && - (has_symlinks || !S_ISREG (st->st_mode))) + (repo_has_symlinks (the_repository) || !S_ISREG (st->st_mode))) changed |=TYPE_CHANGED ;break ;case S_IFGITLINK :
@@ -759,7 +759,8 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st, ce->ce_flags |=CE_INTENT_TO_ADD ; -if (repo_trust_executable_bit (istate->repo) && has_symlinks) { +if (repo_trust_executable_bit (istate->repo) && +repo_has_symlinks (istate->repo)) { ce->ce_mode =create_ce_mode (st_mode); }else {/* If there is an existing entry, pick the mode bits and type
Signature · 1 line
2.43.0
Re: [PATCH v6 4/4] environment: move has_symlinks into repo_config_values
Quoted 9 lines · Tian Yuchen
Move the global '
has_symlinks' configuration into the repository-specific 'repo_config_values' struct.To ensure code readability, the getter function '
repo_has_symlinks()' has been introduced. Callers access this configuration by passing in 'repo' when possible, and explicitly fall back to 'the_repository' the rest of the time.
Quoted 5 lines
Note:
To support platform-specific overrides (MinGW) before repository initialization, the 'platform_has_symlinks()' macro is introduced ingit-compat-util.h. Platforms can override this in their respective headers.
This shouldn't be a mere "Note:" but should be treated as an integral part of the implementation details.
Move the global variable 'has_symlinks' into the 'repo_config_values struct.
Introduce 'repo_has_symlinks()' getter for readability, and 'platform_has_symlinks()' macro to allow platform specific customization, primarily to help MinGW.
may be sufficient.
The changes to compat/ looked reasonable to me.
Thanks.
v7 cover environment: migrate 'trust_executable_bit' and 'has_symlinks' into 'repo_config_values'
In reply to Tian YuchenThis series moves 'trust_executable_bit' and 'has_symlinks' into 'struct repo_config_values' to tie them to the specific repository instance they were read from. Eager parsing is maintained because these two flags are heavily consulted in hot paths.
Note: 'repo_config_values()' still does not support any struct repository other than the_repository due to how deeply these flags are accessed. In other words, this series of patches is laying the groundwork for the eventual elimination of the_repository.
Previous related work:
[PATCH 2/6] config: add trust_executable_bit to global config [1] [PATCH] Refactor 'trust_executable_bit' to repository-scoped setting [2] (This previous attempt was unsuccessful because the target location selected was 'struct repo_settings', which our analysis indicated was not the optimal choice. For further details, please see: [3])
[PATCH 5/6] config: move has_symlinks [4]
RFC:
- Is the locations of the newly introduced definitions/macros appropriate?
Changes since V6:
- In commit 2/4, keep ce_mode_from_stat() static inline. Teach it to take a 'struct repository *' parameter instead.
- In commit 4/4, reword the commit message.
Thanks!
[1] https://lore.kernel.org/git/837b5360b40f992351f489a0ae05fedf49884c6e.1685716420.git.gitgitgadget@gmail.com/
[2] https://lore.kernel.org/git/[email protected]/
[3] https://lore.kernel.org/git/[email protected]/
[4] https://lore.kernel.org/git/a154008619790f7a60f2bba91db7b0fe29e67e1a.1685716420.git.gitgitgadget@gmail.com/
[5] https://lore.kernel.org/git/[email protected]/
Tian Yuchen (4):
read-cache: remove redundant extern declarations
read-cache: pass 'repo' to 'ce_mode_from_stat()'
environment: move trust_executable_bit into repo_config_values
environment: move has_symlinks into repo_config_values
apply.c | 6 +++--- builtin/update-index.c | 2 +- combine-diff.c | 2 +- compat/mingw.c | 17 +++++++++++++---- compat/mingw.h | 3 +++ diff-lib.c | 10 +++++----- entry.c | 2 +- environment.c | 27 +++++++++++++++++++++++---- environment.h | 8 ++++++-- git-compat-util.h | 4 ++++ read-cache.c | 15 +++++++-------- read-cache.h | 16 ++++++++++++---- 12 files changed, 79 insertions(+), 33 deletions(-)
Signature · 1 line
2.43.0
PATCH v7 1/4 read-cache: remove redundant extern declarations
The 'read-cache.c' file already includes 'environment.h', which provides the extern declarations for variables like 'trust_executable_bit' and 'has_symlinks'.
Remove the redundant extern declarations inside 'st_mode_from_ce()' to clean up the code.
--- read-cache.c | 2 -- 1 file changed, 2 deletions(-)
read-cache.c +0 -2
@@ -204,8 +204,6 @@ void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, ststatic unsigned int st_mode_from_ce (const struct cache_entry *ce) { -extern int trust_executable_bit, has_symlinks; -switch (ce->ce_mode &S_IFMT ) {case S_IFLNK :return has_symlinks ?S_IFLNK : (S_IFREG |0644 );
Signature · 1 line
2.43.0
PATCH v7 2/4 read-cache: pass 'repo' to 'ce_mode_from_stat()'
In reply to Tian YuchenThe ce_mode_from_stat() function is a performance-critical static inline helper in 'read-cache.h'. As we migrate configuration variables into the repository struct, this helper needs access to the repository context.
Update the signature of ce_mode_from_stat() to take a 'struct repository *' parameter, and update all callers to pass the appropriate repository instance.
To prepare for the overhead of replacing cheap global variable accesses with getter functions, the boolean expressions are reordered to evaluate 'S_ISREG(mode)' first.
While at it, add a comment for ce_mode_from_stat().
--- apply.c | 2 +- builtin/update-index.c | 2 +- diff-lib.c | 10 +++++----- read-cache.c | 2 +- read-cache.h | 15 ++++++++++++--- 5 files changed, 20 insertions(+), 11 deletions(-)
apply.c +1 -1
@@ -3894,7 +3894,7 @@ static int check_preimage(struct apply_state *state,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); + st_mode =ce_mode_from_stat (state->repo, *ce, st->st_mode);else if (*ce) st_mode = (*ce)->ce_mode;else
builtin/update-index.c +1 -1
@@ -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
@@ -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 (revs->repo, 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 (revs->repo, 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 (revs->repo, 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 (revs->repo, 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 (diffopt->repo, ce, st.st_mode); oid =null_oid (the_hash_algo); } }
read-cache.c +1 -1
@@ -749,7 +749,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 (istate->repo, ent, st_mode); }/* When core.ignorecase=true, determine if a directory of the same name but differing
read-cache.h +12 -3
@@ -4,15 +4,24 @@#include "read-cache-ll.h" #include "object.h" #include "pathspec.h" +#include "environment.h" -static inline unsigned int ce_mode_from_stat (const struct cache_entry *ce, +/* +* Determine the appropriate index mode for a file based on its stat() +* information and the existing cache entry (if any). +* +* 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, +const struct cache_entry *ce,unsigned int mode) {extern int trust_executable_bit, has_symlinks; -if (!has_symlinks &&S_ISREG (mode) && +if (S_ISREG (mode) && !has_symlinks && ce &&S_ISLNK (ce->ce_mode))return ce->ce_mode; -if (!trust_executable_bit &&S_ISREG (mode)) { +if (S_ISREG (mode) && !trust_executable_bit) {if (ce &&S_ISREG (ce->ce_mode))return ce->ce_mode;return create_ce_mode (0666 );
Signature · 1 line
2.43.0
Re: [PATCH v7 2/4] read-cache: pass 'repo' to 'ce_mode_from_stat()'
Quoted 30 lines · Tian Yuchen
The
ce_mode_from_stat()function is a performance-critical static inline helper in 'read-cache.h'. As we migrate configuration variables into the repository struct, this helper needs access to the repository context.Update the signature of
ce_mode_from_stat()to take a 'struct repository *' parameter, and update all callers to pass the appropriate repository instance.To prepare for the overhead of replacing cheap global variable accesses with getter functions, the boolean expressions are reordered to evaluate '
S_ISREG(mode)' first.While at it, add a comment for
ce_mode_from_stat().Mentored-by Christian Couder <[email protected]>Mentored-by Ayush Chandekar <[email protected]>Mentored-by Olamide Caleb Bello <[email protected]>Signed-off-by Tian Yuchen <[email protected]>---
read-cache.h +1
-0@@ -4,15 +4,24 @@#include "read-cache-ll.h" #include "object.h" #include "pathspec.h" +#include "environment.h"
read-cache.h line 16
Quoted 10 lines
read-cache.h +8
-1-static inline unsigned int ce_mode_from_stat(const struct cache_entry *ce, +/* +* Determine the appropriate index mode for a file based on its stat() +* information and the existing cache entry (if any). +* +* 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,
This new parameter is not yet used in this function, which causes compilation errors in all source files which include "read-cache.h" when trying to build this commit using DEVELOPER=1, e.g.:
CC pathspec.o
In file included from pathspec.c:11:
read-cache.h: In function ‘ce_mode_from_stat’:
read-cache.h:16:65: error: unused parameter ‘repo’ [-Werror=unused-parameter]
16 | static inline unsigned int ce_mode_from_stat(struct repository *repo,
| ~~~~~~~~~~~~~~~~~~~^~~~
cc1: all warnings being treated as errors
make: *** [Makefile:2921: pathspec.o] Error 1
CC preload-index.o
In file included from preload-index.c:16:
read-cache.h: In function ‘ce_mode_from_stat’:
read-cache.h:16:65: error: unused parameter ‘repo’ [-Werror=unused-parameter]
16 | static inline unsigned int ce_mode_from_stat(struct repository *repo,
| ~~~~~~~~~~~~~~~~~~~^~~~
cc1: all warnings being treated as errors
make: *** [Makefile:2921: preload-index.o] Error 1
CC read-cache.o
In file included from read-cache.c:34:
read-cache.h: In function ‘ce_mode_from_stat’:
read-cache.h:16:65: error: unused parameter ‘repo’ [-Werror=unused-parameter]
16 | static inline unsigned int ce_mode_from_stat(struct repository *repo,
| ~~~~~~~~~~~~~~~~~~~^~~~
cc1: all warnings being treated as errors
make: *** [Makefile:2921: read-cache.o] Error 1
I think the new parameter should be marked as UNUSED in this patch, and then the UNUSED should be dropped in the next, where you start using the parameter.
Quoted 16 lines
read-cache.h +3
-2+const struct cache_entry *ce, unsigned int mode) { extern int trust_executable_bit, has_symlinks; -if (!has_symlinks &&S_ISREG (mode) && +if (S_ISREG (mode) && !has_symlinks && ce &&S_ISLNK (ce->ce_mode))return ce->ce_mode; -if (!trust_executable_bit &&S_ISREG (mode)) { +if (S_ISREG (mode) && !trust_executable_bit) {if (ce &&S_ISREG (ce->ce_mode))return ce->ce_mode;return create_ce_mode (0666 );Signature · 1 line
2.43.0
Re: [PATCH v7 2/4] read-cache: pass 'repo' to 'ce_mode_from_stat()'
Quoted 62 lines · SZEDER Gábor
Quoted 30 lines · Tian Yuchen
The
ce_mode_from_stat()function is a performance-critical static inline helper in 'read-cache.h'. As we migrate configuration variables into the repository struct, this helper needs access to the repository context.Update the signature of
ce_mode_from_stat()to take a 'struct repository *' parameter, and update all callers to pass the appropriate repository instance.To prepare for the overhead of replacing cheap global variable accesses with getter functions, the boolean expressions are reordered to evaluate '
S_ISREG(mode)' first.While at it, add a comment for
ce_mode_from_stat().Mentored-by Christian Couder <[email protected]>Mentored-by Ayush Chandekar <[email protected]>Mentored-by Olamide Caleb Bello <[email protected]>Signed-off-by Tian Yuchen <[email protected]>---
read-cache.h +1
-0@@ -4,15 +4,24 @@#include "read-cache-ll.h" #include "object.h" #include "pathspec.h" +#include "environment.h" read-cache.h line 16
Quoted 10 lines
read-cache.h +8
-1-static inline unsigned int ce_mode_from_stat(const struct cache_entry *ce, +/* +* Determine the appropriate index mode for a file based on its stat() +* information and the existing cache entry (if any). +* +* 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,This new parameter is not yet used in this function, which causes compilation errors in all source files which include "
read-cache.h" when trying to build this commit using DEVELOPER=1, e.g.:CC pathspec.o
In file included from pathspec.c:11:
read-cache.h: In function ‘ce_mode_from_stat’:
read-cache.h:16:65: error: unused parameter ‘repo’ [-Werror=unused-parameter]
16 | static inline unsigned int ce_mode_from_stat(struct repository *repo,
| ~~~~~~~~~~~~~~~~~~~^~~~
cc1: all warnings being treated as errors
make: *** [Makefile:2921: pathspec.o] Error 1
CC preload-index.o
In file included from preload-index.c:16:
read-cache.h: In function ‘ce_mode_from_stat’:
read-cache.h:16:65: error: unused parameter ‘repo’ [-Werror=unused-parameter]
16 | static inline unsigned int ce_mode_from_stat(struct repository *repo,
| ~~~~~~~~~~~~~~~~~~~^~~~
cc1: all warnings being treated as errors
make: *** [Makefile:2921: preload-index.o] Error 1
Quoted 9 lines
CC read-cache.o
In file included from read-cache.c:34:
read-cache.h: In function ‘ce_mode_from_stat’:
read-cache.h:16:65: error: unused parameter ‘repo’ [-Werror=unused-parameter]
16 | static inline unsigned int ce_mode_from_stat(struct repository *repo,
| ~~~~~~~~~~~~~~~~~~~^~~~
cc1: all warnings being treated as errors
make: *** [Makefile:2921: read-cache.o] Error 1
Nice catch.
Quoted 4 lines
I think the new parameter should be marked as UNUSED in this patch, and then the UNUSED should be dropped in the next, where you start using the parameter.
Quoted 16 lines
Quoted 16 lines
read-cache.h +3
-2+const struct cache_entry *ce, unsigned int mode) { extern int trust_executable_bit, has_symlinks; -if (!has_symlinks &&S_ISREG (mode) && +if (S_ISREG (mode) && !has_symlinks && ce &&S_ISLNK (ce->ce_mode))return ce->ce_mode; -if (!trust_executable_bit &&S_ISREG (mode)) { +if (S_ISREG (mode) && !trust_executable_bit) {if (ce &&S_ISREG (ce->ce_mode))return ce->ce_mode;return create_ce_mode (0666 );Signature · 1 line
2.43.0
But 'USUSED' cannot be used here since the corresponding header (git-compat-util.h, or more specifically compat/posix.h) is not included.
Can we write..
(void)repo; /* TODO: use this parameter in the next patch */
..to keep it simple?
Regards, yuchen
Re: [PATCH v7 2/4] read-cache: pass 'repo' to 'ce_mode_from_stat()'
Quoted 40 lines · Tian Yuchen
Quoted 39 lines · SZEDER Gábor
Quoted 8 lines · Tian Yuchen
read-cache.h +0
-0@@ -4,15 +4,24 @@#include "read-cache-ll.h" #include "object.h" #include "pathspec.h" read-cache.h line 15
Quoted 10 lines
read-cache.h +9
-1+#include "environment.h" -static inline unsigned int ce_mode_from_stat(const struct cache_entry *ce, +/* +* Determine the appropriate index mode for a file based on its stat() +* information and the existing cache entry (if any). +* +* 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,This new parameter is not yet used in this function, which causes compilation errors in all source files which include "
read-cache.h" when trying to build this commit using DEVELOPER=1, e.g.:I think the new parameter should be marked as UNUSED in this patch, and then the UNUSED should be dropped in the next, where you start using the parameter.
Quoted 11 lines
read-cache.h +3
-2+const struct cache_entry *ce, unsigned int mode) { extern int trust_executable_bit, has_symlinks; -if (!has_symlinks &&S_ISREG (mode) && +if (S_ISREG (mode) && !has_symlinks && ce &&S_ISLNK (ce->ce_mode))return ce->ce_mode; -if (!trust_executable_bit &&S_ISREG (mode)) { +if (S_ISREG (mode) && !trust_executable_bit) {if (ce &&S_ISREG (ce->ce_mode))
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
read-cache.h +0
-0return ce->ce_mode;return create_ce_mode (0666 );Signature · 1 line
2.43.0But 'USUSED' cannot be used here since the corresponding header (
git-compat-util.h, or more specificallycompat/posix.h) is not included.
UNUSED _can_ be used here, because:
- This is a header file, so it's not supposed to be compiled on its own.
- All C source files including this header file must start with including "git-compat-util.h", so by the time they include "read-cache.h", the UNUSED macro is already defined.
Re: [PATCH v7 2/4] read-cache: pass 'repo' to 'ce_mode_from_stat()'
Quoted 50 lines · SZEDER Gábor
Quoted 40 lines · Tian Yuchen
Quoted 39 lines · SZEDER Gábor
Quoted 8 lines · Tian Yuchen
read-cache.h +0
-0@@ -4,15 +4,24 @@#include "read-cache-ll.h" #include "object.h" #include "pathspec.h" read-cache.h line 15
Quoted 10 lines
read-cache.h +9
-1+#include "environment.h" -static inline unsigned int ce_mode_from_stat(const struct cache_entry *ce, +/* +* Determine the appropriate index mode for a file based on its stat() +* information and the existing cache entry (if any). +* +* 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,This new parameter is not yet used in this function, which causes compilation errors in all source files which include "
read-cache.h" when trying to build this commit using DEVELOPER=1, e.g.:I think the new parameter should be marked as UNUSED in this patch, and then the UNUSED should be dropped in the next, where you start using the parameter.
Quoted 11 lines
read-cache.h +3
-2+const struct cache_entry *ce, unsigned int mode) { extern int trust_executable_bit, has_symlinks; -if (!has_symlinks &&S_ISREG (mode) && +if (S_ISREG (mode) && !has_symlinks && ce &&S_ISLNK (ce->ce_mode))return ce->ce_mode; -if (!trust_executable_bit &&S_ISREG (mode)) { +if (S_ISREG (mode) && !trust_executable_bit) {if (ce &&S_ISREG (ce->ce_mode))Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
read-cache.h +0
-0return ce->ce_mode;return create_ce_mode (0666 );Signature · 1 line
2.43.0But 'USUSED' cannot be used here since the corresponding header (
git-compat-util.h, or more specificallycompat/posix.h) is not included.
Quoted 8 lines
UNUSED _can_ be used here, because:
- This is a header file, so it's not supposed to be compiled on its own.
- All C source files including this header file must start with including "git-compat-util.h", so by the time they include "read-cache.h", the UNUSED macro is already defined.
I see.
Thanks, yuchen
PATCH v7 3/4 environment: move trust_executable_bit into repo_config_values
In reply to Tian YuchenMove 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.
--- apply.c | 2 +- environment.c | 11 +++++++++-- environment.h | 4 +++- read-cache.c | 6 +++--- read-cache.h | 4 ++-- 5 files changed, 18 insertions(+), 9 deletions(-)
apply.c +1 -1
@@ -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;
environment.c +9 -2
@@ -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->gitdir? +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 ; }
environment.h +3 -1
@@ -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);/*
@@ -160,7 +163,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 +3 -3
@@ -208,7 +208,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 :
@@ -318,7 +318,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 ;
@@ -739,7 +739,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
read-cache.h +2 -2
@@ -17,11 +17,11 @@ 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 );
Signature · 1 line
2.43.0
Re: [PATCH v7 3/4] environment: move trust_executable_bit into repo_config_values
Quoted 16 lines · Tian Yuchen
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 ;@@ -142,6 +141,13 @@ int is_bare_repository(void)return is_bare_repository_cfg && !repo_get_work_tree (the_repository); }
environment.c int is_bare_repository(void) · line 153
Quoted 10 lines
environment.c +7
-0+int repo_trust_executable_bit (struct repository *repo) +{ +return repo->gitdir? +repo_config_values (repo)->trust_executable_bit : +1 ; +} +int have_git_dir (void ) {return startup_info->have_repository
Two comments.
* Missing SP before '?'. It may be easier to read if it is written like this:
return repo->gitdir ? repo_config_values(repo)->trust_executable_bit : 1;
which more clearly highlights the ternary structure. If you tilt your head 90 degrees to the left, you can almost see the parse tree of the expression.
* Does it make sense to protect against a NULL 'repo' case, as repo_protect_ntfs() and repo_protect_hfs() helpers do? Or is it better to crash loudly with a segfault to let the developer know they have a bug to fix? I lean toward the latter myself, and if we go that route, we should probably stop using 'repo && repo->gitdir' elsewhere, rather than sweeping the problem under the rug with defensive checks.
Re: [PATCH v7 3/4] environment: move trust_executable_bit into repo_config_values
Quoted 34 lines · Junio C Hamano
Quoted 16 lines · Tian Yuchen
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 ;@@ -142,6 +141,13 @@ int is_bare_repository(void)return is_bare_repository_cfg && !repo_get_work_tree (the_repository); }environment.c int is_bare_repository(void) · line 153
Quoted 10 lines
environment.c +7
-0+int repo_trust_executable_bit (struct repository *repo) +{ +return repo->gitdir? +repo_config_values (repo)->trust_executable_bit : +1 ; +} +int have_git_dir (void ) {return startup_info->have_repositoryTwo comments.
* Missing SP before '?'. It may be easier to read if it is written like this:
Quoted 8 lines
return
repo->gitdir
? repo_config_values(repo)->trust_executable_bit : 1;which more clearly highlights the ternary structure. If you tilt your head 90 degrees to the left, you can almost see the parse tree of the expression.
Okay.
Quoted 7 lines
* Does it make sense to protect against a NULL 'repo' case, as
repo_protect_ntfs()andrepo_protect_hfs()helpers do? Or is it better to crash loudly with a segfault to let the developer know they have a bug to fix? I lean toward the latter myself, and if we go that route, we should probably stop using 'repo &&repo->gitdir' elsewhere, rather than sweeping the problem under the rug with defensive checks.
Sounds sensible. I will drop the checks and adjust the calls themselves instead.
Note that repo_protect_ntfs() looks like this:
int repo_protect_ntfs(struct repository *repo)
{
return (repo && repo->initialized) ? repo_config_values(repo)->protect_ntfs :
PROTECT_NTFS_DEFAULT;
}
Do we need another fixup commit for it?
Regards, yuchen
PATCH v7 4/4 environment: move has_symlinks into repo_config_values
In reply to Tian YuchenMove the global 'has_symlinks' configuration into the repository-specific 'repo_config_values' struct.
Introduce 'repo_has_symlinks()' getter for readability. Callers access this configuration by passing in 'repo' when possible, and explicitly fall back to 'the_repository' the rest of the time.
Introduce 'platform_has_symlinks()' macro to allow platform specific-customization, primarily to help MinGW. Platforms can override this in their respective headers.
--- apply.c | 2 +- combine-diff.c | 2 +- compat/mingw.c | 17 +++++++++++++---- compat/mingw.h | 3 +++ entry.c | 2 +- environment.c | 16 ++++++++++++++-- environment.h | 4 +++- git-compat-util.h | 4 ++++ read-cache.c | 7 ++++--- read-cache.h | 3 +-- 10 files changed, 45 insertions(+), 15 deletions(-)
apply.c +1 -1
@@ -4511,7 +4511,7 @@ static int try_create_file(struct apply_state *state, const char *path,return !!mkdir (path,0777 ); } -if (has_symlinks &&S_ISLNK (mode)) +if (repo_has_symlinks (state->repo) &&S_ISLNK (mode))/* Although buf:size is counted string, it also is NUL * terminated. */
combine-diff.c +1 -1
@@ -1078,7 +1078,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,/* if symlinks don't work, assume symlink if all parents * are symlinks */ - is_file = has_symlinks; + is_file =repo_has_symlinks (rev->repo);for (i =0 ; !is_file && i < num_parent; i++) is_file = !S_ISLNK (elem->parent[i].mode);if (!is_file)
compat/mingw.c +13 -4
@@ -7,6 +7,7 @@#include "config.h" #include "dir.h" #include "environment.h" +#include "repository.h" #include "gettext.h" #include "run-command.h" #include "strbuf.h"
@@ -1043,7 +1044,7 @@ int mingw_chdir(const char *dirname)if (xutftowcs_path (wdirname, dirname) <0 )return -1 ; -if (has_symlinks) { +if (repo_has_symlinks (the_repository)) {HANDLE hnd =CreateFileW (wdirname,0 ,FILE_SHARE_READ |FILE_SHARE_WRITE |FILE_SHARE_DELETE ,NULL ,OPEN_EXISTING ,FILE_FLAG_BACKUP_SEMANTICS ,NULL );
@@ -2903,7 +2904,7 @@ int symlink(const char *target, const char *link)int len;/* fail if symlinks are disabled or API is not supported (WinXP) */ -if (!has_symlinks) { +if (!repo_has_symlinks (the_repository)) { errno =ENOSYS ;return -1 ; }
@@ -3173,15 +3174,23 @@ static void setup_windows_environment(void)if (!tmp && (tmp =getenv ("USERPROFILE" )))setenv ("HOME" , tmp,1 ); } +} +int mingw_platform_has_symlinks (void ) +{ +static int has_symlinks =-1 ;/* * Change 'core.symlinks' default to false, unless native symlinks are * enabled in MSys2 (via 'MSYS=winsymlinks:nativestrict'). Thus we can * run the test suite (which doesn't obey config files) with or without * symlink support. */ -if (!(tmp =getenv ("MSYS" )) || !strstr (tmp,"winsymlinks:nativestrict" )) - has_symlinks =0 ; +if (has_symlinks <0 ) { +const char *tmp =getenv ("MSYS" ); + has_symlinks = (tmp &&strstr (tmp,"winsymlinks:nativestrict" )) ?1 :0 ; + } + +return has_symlinks; }static void get_current_user_sid (PSID *sid,HANDLE *linked_token)
compat/mingw.h +3 -0
@@ -208,6 +208,9 @@ void open_in_gdb(void);*/ int err_win_to_posix (DWORD winerr); +int mingw_platform_has_symlinks (void ); +#define platform_has_symlinks () mingw_platform_has_symlinks() +#ifndef NO_UNIX_SOCKETS int mingw_have_unix_sockets (void );#undef have_unix_sockets
entry.c +1 -1
@@ -321,7 +321,7 @@ static int write_entry(struct cache_entry *ce, char *path, struct conv_attrs *ca* We can't make a real symlink; write out a regular file entry * with the symlink destination as its contents. */ -if (!has_symlinks || to_tempfile) +if (!repo_has_symlinks (state->istate ? state->istate->repo :NULL ) || to_tempfile) goto write_file_entry; ret =symlink (new_blob, path);
environment.c +14 -2
@@ -43,7 +43,6 @@ static int zlib_compression_seen;int trust_ctime =1 ;int check_stat =1 ; -int has_symlinks =1 ;int minimum_abbrev =4 , default_abbrev =-1 ;int ignore_case;int assume_unchanged;
@@ -148,6 +147,17 @@ int repo_trust_executable_bit(struct repository *repo)1 ; } +int repo_has_symlinks (struct repository *repo) +{ +if (!repo) + repo = the_repository; + +if (!repo->gitdir) +return platform_has_symlinks (); + +return repo_config_values (repo)->has_symlinks; +} +int have_git_dir (void ) {return startup_info->have_repository
@@ -336,7 +346,8 @@ int git_default_core_config(const char *var, const char *value, }if (!strcmp (var,"core.symlinks" )) { - has_symlinks =git_config_bool (var, value); +struct repo_config_values *cfg =repo_config_values (the_repository); + cfg->has_symlinks =git_config_bool (var, value);return 0 ; }
@@ -727,5 +738,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->has_symlinks =platform_has_symlinks (); cfg->branch_track =BRANCH_TRACK_REMOTE ; }
environment.h +3 -1
@@ -92,6 +92,7 @@ struct repo_config_values {char *attributes_file;int apply_sparse_checkout;int trust_executable_bit; +int has_symlinks;/* section "branch" config values */ enum branch_track branch_track;
@@ -126,6 +127,8 @@ int git_default_core_config(const char *var, const char *value,int repo_trust_executable_bit (struct repository *repo); +int repo_has_symlinks (struct repository *repo); +void repo_config_values_init (struct repo_config_values *cfg);/*
@@ -165,7 +168,6 @@ extern char *git_work_tree_cfg;/* Environment bits from configuration mechanism */ extern int trust_ctime;extern int check_stat; -extern int has_symlinks;extern int minimum_abbrev, default_abbrev;extern int ignore_case;extern int assume_unchanged;
git-compat-util.h +4 -0
@@ -245,6 +245,10 @@ static inline int git_is_dir_sep(int c)#define is_dir_sep git_is_dir_sep#endif +#ifndef platform_has_symlinks +#define platform_has_symlinks () 1 +#endif +#ifndef offset_1st_componentstatic inline int git_offset_1st_component (const char *path) {
read-cache.c +4 -3
@@ -206,7 +206,7 @@ static unsigned int st_mode_from_ce(const struct cache_entry *ce) {switch (ce->ce_mode &S_IFMT ) {case S_IFLNK : -return has_symlinks ?S_IFLNK : (S_IFREG |0644 ); +return repo_has_symlinks (the_repository) ?S_IFLNK : (S_IFREG |0644 );case S_IFREG :return (ce->ce_mode & (repo_trust_executable_bit (the_repository) ?0755 :0644 )) |S_IFREG ;case S_IFGITLINK :
@@ -324,7 +324,7 @@ static int ce_match_stat_basic(const struct cache_entry *ce, struct stat *st)break ;case S_IFLNK :if (!S_ISLNK (st->st_mode) && - (has_symlinks || !S_ISREG (st->st_mode))) + (repo_has_symlinks (the_repository) || !S_ISREG (st->st_mode))) changed |=TYPE_CHANGED ;break ;case S_IFGITLINK :
@@ -739,7 +739,8 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st, ce->ce_flags |=CE_INTENT_TO_ADD ; -if (repo_trust_executable_bit (istate->repo) && has_symlinks) { +if (repo_trust_executable_bit (istate->repo) && +repo_has_symlinks (istate->repo)) { ce->ce_mode =create_ce_mode (st_mode); }else {/* If there is an existing entry, pick the mode bits and type
read-cache.h +1 -2
@@ -17,8 +17,7 @@ static inline unsigned int ce_mode_from_stat(struct repository *repo, const struct cache_entry *ce, unsigned int mode) { - extern int has_symlinks; -if (S_ISREG (mode) && !has_symlinks && + if (S_ISREG(mode) && !repo_has_symlinks(repo) && ce && S_ISLNK(ce->ce_mode)) return ce->ce_mode; if (S_ISREG(mode) && !repo_trust_executable_bit(repo)) {
Signature · 1 line
2.43.0
v8 cover environment: migrate 'trust_executable_bit' and 'has_symlinks' into 'repo_config_values'
In reply to Tian YuchenThis series moves 'trust_executable_bit' and 'has_symlinks' into 'struct repo_config_values' to tie them to the specific repository instance they were read from. Eager parsing is maintained because these two flags are heavily consulted in hot paths.
Note: 'repo_config_values()' still does not support any struct repository other than the_repository due to how deeply these flags are accessed. In other words, this series of patches is laying the groundwork for the eventual elimination of the_repository.
Previous related work:
[PATCH 2/6] config: add trust_executable_bit to global config [1] [PATCH] Refactor 'trust_executable_bit' to repository-scoped setting [2] (This previous attempt was unsuccessful because the target location selected was 'struct repo_settings', which our analysis indicated was not the optimal choice. For further details, please see: [3])
[PATCH 5/6] config: move has_symlinks [4]
RFC:
- Is the locations of the newly introduced definitions/macros appropriate?
Changes since V7:
- In commit 2/4, mark the 'struct repository' parameter of ce_mode_from_stat() UNUSED. In commit 3/4, drop it.
- Don't check '!repo' in the getters, which lets the developers know there is a bug to fix when NULL is passed in. Callers should be responsible of passing non-null repos. Therefore, adjust the call in write_entry().
Change back to check 'repo->initiaized' instead of 'repo->gitdir'.
Thanks!
[1] https://lore.kernel.org/git/837b5360b40f992351f489a0ae05fedf49884c6e.1685716420.git.gitgitgadget@gmail.com/
[2] https://lore.kernel.org/git/[email protected]/
[3] https://lore.kernel.org/git/[email protected]/
[4] https://lore.kernel.org/git/a154008619790f7a60f2bba91db7b0fe29e67e1a.1685716420.git.gitgitgadget@gmail.com/
[5] https://lore.kernel.org/git/[email protected]/
Tian Yuchen (4):
read-cache: remove redundant extern declarations
read-cache: pass 'repo' to 'ce_mode_from_stat()'
environment: move trust_executable_bit into repo_config_values
environment: move has_symlinks into repo_config_values
apply.c | 6 +++--- builtin/update-index.c | 2 +- combine-diff.c | 2 +- compat/mingw.c | 17 +++++++++++++---- compat/mingw.h | 3 +++ diff-lib.c | 10 +++++----- entry.c | 3 ++- environment.c | 23 +++++++++++++++++++---- environment.h | 8 ++++++-- git-compat-util.h | 4 ++++ read-cache.c | 15 +++++++-------- read-cache.h | 16 ++++++++++++---- 12 files changed, 76 insertions(+), 33 deletions(-)
Signature · 1 line
2.43.0
PATCH v8 1/4 read-cache: remove redundant extern declarations
The 'read-cache.c' file already includes 'environment.h', which provides the extern declarations for variables like 'trust_executable_bit' and 'has_symlinks'.
Remove the redundant extern declarations inside 'st_mode_from_ce()' to clean up the code.
--- read-cache.c | 2 -- 1 file changed, 2 deletions(-)
read-cache.c +0 -2
@@ -204,8 +204,6 @@ void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, ststatic unsigned int st_mode_from_ce (const struct cache_entry *ce) { -extern int trust_executable_bit, has_symlinks; -switch (ce->ce_mode &S_IFMT ) {case S_IFLNK :return has_symlinks ?S_IFLNK : (S_IFREG |0644 );
Signature · 1 line
2.43.0
PATCH v8 2/4 read-cache: pass 'repo' to 'ce_mode_from_stat()'
In reply to Tian YuchenThe ce_mode_from_stat() function is a performance-critical static inline helper in 'read-cache.h'. As we migrate configuration variables into the repository struct, this helper needs access to the repository context.
Update the signature of ce_mode_from_stat() to take a 'struct repository *' parameter, and update all callers to pass the appropriate repository instance.
To prepare for the overhead of replacing cheap global variable accesses with getter functions, the boolean expressions are reordered to evaluate 'S_ISREG(mode)' first.
While at it, add a comment for ce_mode_from_stat().
--- apply.c | 2 +- builtin/update-index.c | 2 +- diff-lib.c | 10 +++++----- read-cache.c | 2 +- read-cache.h | 15 ++++++++++++--- 5 files changed, 20 insertions(+), 11 deletions(-)
apply.c +1 -1
@@ -3894,7 +3894,7 @@ static int check_preimage(struct apply_state *state,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); + st_mode =ce_mode_from_stat (state->repo, *ce, st->st_mode);else if (*ce) st_mode = (*ce)->ce_mode;else
builtin/update-index.c +1 -1
@@ -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
@@ -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 (revs->repo, 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 (revs->repo, 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 (revs->repo, 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 (revs->repo, 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 (diffopt->repo, ce, st.st_mode); oid =null_oid (the_hash_algo); } }
read-cache.c +1 -1
@@ -749,7 +749,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 (istate->repo, ent, st_mode); }/* When core.ignorecase=true, determine if a directory of the same name but differing
read-cache.h +12 -3
@@ -4,15 +4,24 @@#include "read-cache-ll.h" #include "object.h" #include "pathspec.h" +#include "environment.h" -static inline unsigned int ce_mode_from_stat (const struct cache_entry *ce, +/* +* Determine the appropriate index mode for a file based on its stat() +* information and the existing cache entry (if any). +* +* 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, +const struct cache_entry *ce,unsigned int mode) {extern int trust_executable_bit, has_symlinks; -if (!has_symlinks &&S_ISREG (mode) && +if (S_ISREG (mode) && !has_symlinks && ce &&S_ISLNK (ce->ce_mode))return ce->ce_mode; -if (!trust_executable_bit &&S_ISREG (mode)) { +if (S_ISREG (mode) && !trust_executable_bit) {if (ce &&S_ISREG (ce->ce_mode))return ce->ce_mode;return create_ce_mode (0666 );
Signature · 1 line
2.43.0
PATCH v8 3/4 environment: move trust_executable_bit into repo_config_values
In reply to Tian YuchenMove 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.
--- apply.c | 2 +- environment.c | 11 +++++++++-- environment.h | 4 +++- read-cache.c | 6 +++--- read-cache.h | 6 +++--- 5 files changed, 19 insertions(+), 10 deletions(-)
apply.c +1 -1
@@ -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;
environment.c +9 -2
@@ -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 ; }
environment.h +3 -1
@@ -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);/*
@@ -160,7 +163,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 +3 -3
@@ -208,7 +208,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 :
@@ -318,7 +318,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 ;
@@ -739,7 +739,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
read-cache.h +3 -3
@@ -13,15 +13,15 @@* 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 );
Signature · 1 line
2.43.0
PATCH v8 4/4 environment: move has_symlinks into repo_config_values
In reply to Tian YuchenMove the global 'has_symlinks' configuration into the repository-specific 'repo_config_values' struct.
Introduce 'repo_has_symlinks()' getter for readability. Callers access this configuration by passing in 'repo' when possible, and explicitly fall back to 'the_repository' the rest of the time.
Introduce 'platform_has_symlinks()' macro to allow platform specific-customization, primarily to help MinGW. Platforms can override this in their respective headers.
--- apply.c | 2 +- combine-diff.c | 2 +- compat/mingw.c | 17 +++++++++++++---- compat/mingw.h | 3 +++ entry.c | 3 ++- environment.c | 12 ++++++++++-- environment.h | 4 +++- git-compat-util.h | 4 ++++ read-cache.c | 7 ++++--- read-cache.h | 3 +-- 10 files changed, 42 insertions(+), 15 deletions(-)
apply.c +1 -1
@@ -4511,7 +4511,7 @@ static int try_create_file(struct apply_state *state, const char *path,return !!mkdir (path,0777 ); } -if (has_symlinks &&S_ISLNK (mode)) +if (repo_has_symlinks (state->repo) &&S_ISLNK (mode))/* Although buf:size is counted string, it also is NUL * terminated. */
combine-diff.c +1 -1
@@ -1078,7 +1078,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,/* if symlinks don't work, assume symlink if all parents * are symlinks */ - is_file = has_symlinks; + is_file =repo_has_symlinks (rev->repo);for (i =0 ; !is_file && i < num_parent; i++) is_file = !S_ISLNK (elem->parent[i].mode);if (!is_file)
compat/mingw.c +13 -4
@@ -7,6 +7,7 @@#include "config.h" #include "dir.h" #include "environment.h" +#include "repository.h" #include "gettext.h" #include "run-command.h" #include "strbuf.h"
@@ -1043,7 +1044,7 @@ int mingw_chdir(const char *dirname)if (xutftowcs_path (wdirname, dirname) <0 )return -1 ; -if (has_symlinks) { +if (repo_has_symlinks (the_repository)) {HANDLE hnd =CreateFileW (wdirname,0 ,FILE_SHARE_READ |FILE_SHARE_WRITE |FILE_SHARE_DELETE ,NULL ,OPEN_EXISTING ,FILE_FLAG_BACKUP_SEMANTICS ,NULL );
@@ -2903,7 +2904,7 @@ int symlink(const char *target, const char *link)int len;/* fail if symlinks are disabled or API is not supported (WinXP) */ -if (!has_symlinks) { +if (!repo_has_symlinks (the_repository)) { errno =ENOSYS ;return -1 ; }
@@ -3173,15 +3174,23 @@ static void setup_windows_environment(void)if (!tmp && (tmp =getenv ("USERPROFILE" )))setenv ("HOME" , tmp,1 ); } +} +int mingw_platform_has_symlinks (void ) +{ +static int has_symlinks =-1 ;/* * Change 'core.symlinks' default to false, unless native symlinks are * enabled in MSys2 (via 'MSYS=winsymlinks:nativestrict'). Thus we can * run the test suite (which doesn't obey config files) with or without * symlink support. */ -if (!(tmp =getenv ("MSYS" )) || !strstr (tmp,"winsymlinks:nativestrict" )) - has_symlinks =0 ; +if (has_symlinks <0 ) { +const char *tmp =getenv ("MSYS" ); + has_symlinks = (tmp &&strstr (tmp,"winsymlinks:nativestrict" )) ?1 :0 ; + } + +return has_symlinks; }static void get_current_user_sid (PSID *sid,HANDLE *linked_token)
compat/mingw.h +3 -0
@@ -208,6 +208,9 @@ void open_in_gdb(void);*/ int err_win_to_posix (DWORD winerr); +int mingw_platform_has_symlinks (void ); +#define platform_has_symlinks () mingw_platform_has_symlinks() +#ifndef NO_UNIX_SOCKETS int mingw_have_unix_sockets (void );#undef have_unix_sockets
entry.c +2 -1
@@ -321,7 +321,8 @@ static int write_entry(struct cache_entry *ce, char *path, struct conv_attrs *ca* We can't make a real symlink; write out a regular file entry * with the symlink destination as its contents. */ -if (!has_symlinks || to_tempfile) +if (!repo_has_symlinks (state->istate && state->istate->repo ? + state->istate->repo : the_repository) || to_tempfile) goto write_file_entry; ret =symlink (new_blob, path);
environment.c +10 -2
@@ -43,7 +43,6 @@ static int zlib_compression_seen;int trust_ctime =1 ;int check_stat =1 ; -int has_symlinks =1 ;int minimum_abbrev =4 , default_abbrev =-1 ;int ignore_case;int assume_unchanged;
@@ -148,6 +147,13 @@ int repo_trust_executable_bit(struct repository *repo) : 1; } +int repo_has_symlinks (struct repository *repo) +{ +return repo->initialized + ?repo_config_values (repo)->has_symlinks + :platform_has_symlinks (); +} +int have_git_dir (void ) {return startup_info->have_repository
@@ -336,7 +342,8 @@ int git_default_core_config(const char *var, const char *value, }if (!strcmp (var,"core.symlinks" )) { - has_symlinks =git_config_bool (var, value); +struct repo_config_values *cfg =repo_config_values (the_repository); + cfg->has_symlinks =git_config_bool (var, value);return 0 ; }
@@ -727,5 +734,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->has_symlinks =platform_has_symlinks (); cfg->branch_track =BRANCH_TRACK_REMOTE ; }
environment.h +3 -1
@@ -92,6 +92,7 @@ struct repo_config_values {char *attributes_file;int apply_sparse_checkout;int trust_executable_bit; +int has_symlinks;/* section "branch" config values */ enum branch_track branch_track;
@@ -126,6 +127,8 @@ int git_default_core_config(const char *var, const char *value,int repo_trust_executable_bit (struct repository *repo); +int repo_has_symlinks (struct repository *repo); +void repo_config_values_init (struct repo_config_values *cfg);/*
@@ -165,7 +168,6 @@ extern char *git_work_tree_cfg;/* Environment bits from configuration mechanism */ extern int trust_ctime;extern int check_stat; -extern int has_symlinks;extern int minimum_abbrev, default_abbrev;extern int ignore_case;extern int assume_unchanged;
git-compat-util.h +4 -0
@@ -245,6 +245,10 @@ static inline int git_is_dir_sep(int c)#define is_dir_sep git_is_dir_sep#endif +#ifndef platform_has_symlinks +#define platform_has_symlinks () 1 +#endif +#ifndef offset_1st_componentstatic inline int git_offset_1st_component (const char *path) {
read-cache.c +4 -3
@@ -206,7 +206,7 @@ static unsigned int st_mode_from_ce(const struct cache_entry *ce) {switch (ce->ce_mode &S_IFMT ) {case S_IFLNK : -return has_symlinks ?S_IFLNK : (S_IFREG |0644 ); +return repo_has_symlinks (the_repository) ?S_IFLNK : (S_IFREG |0644 );case S_IFREG :return (ce->ce_mode & (repo_trust_executable_bit (the_repository) ?0755 :0644 )) |S_IFREG ;case S_IFGITLINK :
@@ -324,7 +324,7 @@ static int ce_match_stat_basic(const struct cache_entry *ce, struct stat *st)break ;case S_IFLNK :if (!S_ISLNK (st->st_mode) && - (has_symlinks || !S_ISREG (st->st_mode))) + (repo_has_symlinks (the_repository) || !S_ISREG (st->st_mode))) changed |=TYPE_CHANGED ;break ;case S_IFGITLINK :
@@ -739,7 +739,8 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st, ce->ce_flags |=CE_INTENT_TO_ADD ; -if (repo_trust_executable_bit (istate->repo) && has_symlinks) { +if (repo_trust_executable_bit (istate->repo) && +repo_has_symlinks (istate->repo)) { ce->ce_mode =create_ce_mode (st_mode); }else {/* If there is an existing entry, pick the mode bits and type
read-cache.h +1 -2
@@ -17,8 +17,7 @@ static inline unsigned int ce_mode_from_stat(struct repository *repo, const struct cache_entry *ce, unsigned int mode) { - extern int has_symlinks; -if (S_ISREG (mode) && !has_symlinks && + if (S_ISREG(mode) && !repo_has_symlinks(repo) && ce && S_ISLNK(ce->ce_mode)) return ce->ce_mode; if (S_ISREG(mode) && !repo_trust_executable_bit(repo)) {
Signature · 1 line
2.43.0