read-cache: move 'ce_mode_from_stat()' to 'read-cache.c'

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".

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.

Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored-by: Ayush Chandekar <ayu.chandekar@gmail.com>
Mentored-by: Olamide Caleb Bello <belkid98@gmail.com>
Signed-off-by: Tian Yuchen <cat@malon.dev>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Tian Yuchen
2026-06-13 00:05:25 +08:00
committed by Junio C Hamano
parent a9be508ed4
commit e5d7e4cbfa
2 changed files with 22 additions and 14 deletions

View File

@@ -203,6 +203,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) {

View File

@@ -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)
{