Skip to content

Commit e5d7e4c

Browse files
malon7782gitster
authored andcommitted
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>
1 parent a9be508 commit e5d7e4c

2 files changed

Lines changed: 22 additions & 14 deletions

File tree

read-cache.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,19 @@ void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, st
203203
}
204204
}
205205

206+
unsigned int ce_mode_from_stat(const struct cache_entry *ce, unsigned int mode)
207+
{
208+
if (!has_symlinks && S_ISREG(mode) &&
209+
ce && S_ISLNK(ce->ce_mode))
210+
return ce->ce_mode;
211+
if (!trust_executable_bit && S_ISREG(mode)) {
212+
if (ce && S_ISREG(ce->ce_mode))
213+
return ce->ce_mode;
214+
return create_ce_mode(0666);
215+
}
216+
return create_ce_mode(mode);
217+
}
218+
206219
static unsigned int st_mode_from_ce(const struct cache_entry *ce)
207220
{
208221
switch (ce->ce_mode & S_IFMT) {

read-cache.h

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,15 @@
55
#include "object.h"
66
#include "pathspec.h"
77

8-
static inline unsigned int ce_mode_from_stat(const struct cache_entry *ce,
9-
unsigned int mode)
10-
{
11-
extern int trust_executable_bit, has_symlinks;
12-
if (!has_symlinks && S_ISREG(mode) &&
13-
ce && S_ISLNK(ce->ce_mode))
14-
return ce->ce_mode;
15-
if (!trust_executable_bit && S_ISREG(mode)) {
16-
if (ce && S_ISREG(ce->ce_mode))
17-
return ce->ce_mode;
18-
return create_ce_mode(0666);
19-
}
20-
return create_ce_mode(mode);
21-
}
8+
/*
9+
* Determine the appropriate index mode for a file based on its stat()
10+
* information and the existing cache entry (if any).
11+
*
12+
* This function handles degradation for filesystems that lack
13+
* symlink support or reliable executable bits.
14+
*/
15+
unsigned int ce_mode_from_stat(const struct cache_entry *ce,
16+
unsigned int mode);
2217

2318
static inline int ce_to_dtype(const struct cache_entry *ce)
2419
{

0 commit comments

Comments
 (0)