Git fork

Merge branch 'jc/fake-lstat' into jc/diff-cached-fsmonitor-fix

* jc/fake-lstat:
cache: add fake_lstat()

+70
+8
read-cache-ll.h
··· 436 436 437 437 void fill_stat_cache_info(struct index_state *istate, struct cache_entry *ce, struct stat *st); 438 438 439 + /* 440 + * Fill members of st by members of sd enough to convince match_stat() 441 + * to consider that they match. It should be usable as a replacement 442 + * for lstat() for a tracked path that is known to be up-to-date via 443 + * some out-of-line means (like fsmonitor). 444 + */ 445 + int fake_lstat(const struct cache_entry *ce, struct stat *st); 446 + 439 447 #define REFRESH_REALLY (1 << 0) /* ignore_valid */ 440 448 #define REFRESH_UNMERGED (1 << 1) /* allow unmerged */ 441 449 #define REFRESH_QUIET (1 << 2) /* be quiet about it */
+27
read-cache.c
··· 197 197 } 198 198 } 199 199 200 + static unsigned int st_mode_from_ce(const struct cache_entry *ce) 201 + { 202 + extern int trust_executable_bit, has_symlinks; 203 + 204 + switch (ce->ce_mode & S_IFMT) { 205 + case S_IFLNK: 206 + return has_symlinks ? S_IFLNK : (S_IFREG | 0644); 207 + case S_IFREG: 208 + return (ce->ce_mode & (trust_executable_bit ? 0755 : 0644)) | S_IFREG; 209 + case S_IFGITLINK: 210 + return S_IFDIR | 0755; 211 + case S_IFDIR: 212 + return ce->ce_mode; 213 + default: 214 + BUG("unsupported ce_mode: %o", ce->ce_mode); 215 + } 216 + } 217 + 218 + int fake_lstat(const struct cache_entry *ce, struct stat *st) 219 + { 220 + fake_lstat_data(&ce->ce_stat_data, st); 221 + st->st_mode = st_mode_from_ce(ce); 222 + 223 + /* always succeed as lstat() replacement */ 224 + return 0; 225 + } 226 + 200 227 static int ce_compare_data(struct index_state *istate, 201 228 const struct cache_entry *ce, 202 229 struct stat *st)
+27
statinfo.c
··· 15 15 sd->sd_size = st->st_size; 16 16 } 17 17 18 + static void set_times(struct stat *st, const struct stat_data *sd) 19 + { 20 + st->st_ctime = sd->sd_ctime.sec; 21 + st->st_mtime = sd->sd_mtime.sec; 22 + #ifdef NO_NSEC 23 + ; /* nothing */ 24 + #else 25 + #ifdef USE_ST_TIMESPEC 26 + st->st_ctimespec.tv_nsec = sd->sd_ctime.nsec; 27 + st->st_mtimespec.tv_nsec = sd->sd_mtime.nsec; 28 + #else 29 + st->st_ctim.tv_nsec = sd->sd_ctime.nsec; 30 + st->st_mtim.tv_nsec = sd->sd_mtime.nsec; 31 + #endif 32 + #endif 33 + } 34 + 35 + void fake_lstat_data(const struct stat_data *sd, struct stat *st) 36 + { 37 + set_times(st, sd); 38 + st->st_dev = sd->sd_dev; 39 + st->st_ino = sd->sd_ino; 40 + st->st_uid = sd->sd_uid; 41 + st->st_gid = sd->sd_gid; 42 + st->st_size = sd->sd_size; 43 + } 44 + 18 45 int match_stat_data(const struct stat_data *sd, struct stat *st) 19 46 { 20 47 int changed = 0;
+8
statinfo.h
··· 47 47 void fill_stat_data(struct stat_data *sd, struct stat *st); 48 48 49 49 /* 50 + * The inverse of the above. When we know the cache_entry that 51 + * contains sd is up-to-date, but still need to pretend we called 52 + * lstat() to learn that fact, this function fills "st" enough to 53 + * fool ie_match_stat(). 54 + */ 55 + void fake_lstat_data(const struct stat_data *sd, struct stat *st); 56 + 57 + /* 50 58 * Return 0 if st is consistent with a file not having been changed 51 59 * since sd was filled. If there are differences, return a 52 60 * combination of MTIME_CHANGED, CTIME_CHANGED, OWNER_CHANGED,