diff options
| author | Junio C Hamano <gitster@pobox.com> | 2023-12-27 14:52:24 -0800 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2023-12-27 14:52:24 -0800 |
| commit | 01f86ebb95cc6613db3e637aaba1599e6435c6b7 (patch) | |
| tree | 14ba5298c9a6d3b0eb34507a2b855457d6083fc4 /read-cache.c | |
| parent | Merge branch 'jk/mailinfo-oob-read-fix' (diff) | |
| parent | cache: add fake_lstat() (diff) | |
| download | git-01f86ebb95cc6613db3e637aaba1599e6435c6b7.tar.gz git-01f86ebb95cc6613db3e637aaba1599e6435c6b7.zip | |
Merge branch 'jc/fake-lstat'
A new helper to let us pretend that we called lstat() when we know
our cache_entry is up-to-date via fsmonitor.
* jc/fake-lstat:
cache: add fake_lstat()
Diffstat (limited to 'read-cache.c')
| -rw-r--r-- | read-cache.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/read-cache.c b/read-cache.c index 080bd39713..eb750e2e49 100644 --- a/read-cache.c +++ b/read-cache.c @@ -197,6 +197,33 @@ void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, st } } +static unsigned int st_mode_from_ce(const struct cache_entry *ce) +{ + extern int trust_executable_bit, has_symlinks; + + 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; + case S_IFGITLINK: + return S_IFDIR | 0755; + case S_IFDIR: + return ce->ce_mode; + default: + BUG("unsupported ce_mode: %o", ce->ce_mode); + } +} + +int fake_lstat(const struct cache_entry *ce, struct stat *st) +{ + fake_lstat_data(&ce->ce_stat_data, st); + st->st_mode = st_mode_from_ce(ce); + + /* always succeed as lstat() replacement */ + return 0; +} + static int ce_compare_data(struct index_state *istate, const struct cache_entry *ce, struct stat *st) |
