environment.c: migrate 'trust_executable_bit' into 'repo_config_values'#2312
environment.c: migrate 'trust_executable_bit' into 'repo_config_values'#2312malon7782 wants to merge 4 commits into
Conversation
898ae86 to
373dfb2
Compare
| return ce->ce_mode; | ||
| default: | ||
| BUG("unsupported ce_mode: %o", ce->ce_mode); | ||
| bug("unsupported ce_mode: %o", ce->ce_mode); |
There was a problem hiding this comment.
Why is BUG() changed into bug()?
| #define INDEX_FORMAT_UB 4 | ||
|
|
||
| struct cache_entry { | ||
|
|
There was a problem hiding this comment.
Why is this blank line added?
| struct repository *repo = (istate && istate->repo) ? istate->repo : the_repository; | ||
| struct repo_config_values *cfg = repo_config_values(repo); | ||
|
|
||
| extern int has_symlinks; |
There was a problem hiding this comment.
"read-cache.c" already includes "environment.h" which has extern int has_symlinks; so I am not sure this is useful here. I think it could be dropped.
| static unsigned int st_mode_from_ce(struct index_state *istate, const struct cache_entry *ce) | ||
| { | ||
| extern int trust_executable_bit, has_symlinks; | ||
| extern int has_symlinks; |
There was a problem hiding this comment.
"read-cache.c" already includes "environment.h" which has extern int has_symlinks; so I am not sure this is useful here. I think it could be dropped.
|
It seems to me that the single commit in this branch is doing too many things:
I think the commit could be split into three commits to help with reviews. Also the usefulness of 3. is dubious for now because repo_config_values() still contains: So 3. makes it look like some functions could work for a repo that isn't the_repository, but it's in fact not true. At least 3. should be explained more thoroughly in a dedicated commit message. It looks like there could even be a small cleanup patch before the main three patches to remove the:
which was not necessary since "read-cache.c" already does |
| #include "object.h" | ||
| #include "pathspec.h" | ||
| #include "repository.h" | ||
| #include "environment.h" |
There was a problem hiding this comment.
Not sure that including both is necessary.
There was a problem hiding this comment.
In fact it seems to compile correctly without them.
|
Also about the commit message, maybe you can start to systematically add |
|
|
||
| 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->index, ent, st_mode); |
There was a problem hiding this comment.
It looks like this could simply be:
ce->ce_mode = ce_mode_from_stat(istate, ent, st_mode);
|
The nice thing with a pull request (or merge request) is that its description can contain what will be in the cover letter of the patch series. In the cover letter it's nice to talk about previous work related to the series. About the https://lore.kernel.org/git/20260301190017.53539-1-dronarajgyawali@gmail.com/ and it looks like you participated in the discussion. This one is maybe relevant too: So you might want to mention them in the cover letter/this PR's description. |
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. Mentored-by: Christian Couder <christian.couder@gamil.com> Mentored-by: Ayush Chandekar <ayu.chandekar@gmail.com> Signed-off-by: Tian Yuchen <cat@malon.dev>
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. Mentored-by: Christian Couder <christian.couder@gamil.com> Mentored-by: Ayush Chandekar <ayu.chandekar@gmail.com> Signed-off-by: Tian Yuchen <cat@malon.dev>
In preparation for moving global configuration variables into the repository-specific 'repo_config_values' struct, low-level stat and mode helper functions need access to repository context. 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'. Mentored-by: Christian Couder <christian.couder@gamil.com> Mentored-by: Ayush Chandekar <ayu.chandekar@gmail.com> Signed-off-by: Tian Yuchen <cat@malon.dev>
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. For callers where 'istate->repo' might be NULL, fall back safely to 'the_repository'. Mentored-by: Christian Couder <christian.couder@gamil.com> Mentored-by: Ayush Chandekar <ayu.chandekar@gmail.com> Signed-off-by: Tian Yuchen <cat@malon.dev>
373dfb2 to
51ca686
Compare
|
There is an issue in commit 9ef58e0:
|
| static unsigned int st_mode_from_ce(const struct cache_entry *ce) | ||
| { | ||
| extern int trust_executable_bit, has_symlinks; | ||
|
|
There was a problem hiding this comment.
I think the blank line following the extern int ... line could be removed too.
7207106 to
51ca686
Compare
|
There is an issue in commit 9ef58e0:
|
51ca686 to
56a4f3c
Compare
|
There is an issue in commit 9ef58e0:
|
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:
These functions now accept a 'struct index_state *istate', ensuring the correct context is seamlessly passed down to the lowest levels.
Patch 1: Cleans up redundant local 'extern' declarations for 'trust_executable_bit' and 'has_symlinks' in 'read-cache.c'.
Patch 2: Moves 'ce_mode_from_stat()' from 'read-cache.h' to 'read-cache.c', removing its inline status.
Patch 3: Refactors the signatures of low-level helpers.
Patch 4: Performs the actual migration of 'trust_executable_bit' into 'repo_config_values'.
Previous related work: https://lore.kernel.org/git/837b5360b40f992351f489a0ae05fedf49884c6e.1685716420.git.gitgitgadget@gmail.com/
Mentored-by: Christian Couder christian.couder@gamil.com
Mentored-by: Ayush Chandekar ayu.chandekar@gmail.com
Signed-off-by: Tian Yuchen cat@malon.dev