From c33fa871a5c89091cfc89fd7b6ef504d2d48bef2 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 14 Sep 2023 14:46:46 -0700 Subject: cache: add fake_lstat() At times, we may already know that a path represented by a cache_entry ce has no changes via some out-of-line means, like fsmonitor, and yet need the control to go through a codepath that requires us to have "struct stat" obtained by lstat() on the path, for various purposes (e.g. "ie_match_stat()" wants cached stat-info is still current wrt "struct stat", "diff" wants to know st_mode). The callers of lstat() on a tracked file, when its cache_entry knows it is up-to-date, can instead call this helper to pretend that it called lstat() by faking the "struct stat" information. Signed-off-by: Junio C Hamano --- read-cache-ll.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'read-cache-ll.h') diff --git a/read-cache-ll.h b/read-cache-ll.h index 9a1a7edc5a..2a50a784f0 100644 --- a/read-cache-ll.h +++ b/read-cache-ll.h @@ -436,6 +436,14 @@ int match_stat_data_racy(const struct index_state *istate, void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, struct stat *st); +/* + * Fill members of st by members of sd enough to convince match_stat() + * to consider that they match. It should be usable as a replacement + * 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); + #define REFRESH_REALLY (1 << 0) /* ignore_valid */ #define REFRESH_UNMERGED (1 << 1) /* allow unmerged */ #define REFRESH_QUIET (1 << 2) /* be quiet about it */ -- cgit v1.2.3