| 2521 | } |
| 2522 | |
| 2523 | static int valid_cached_dir(struct dir_struct *dir, |
| 2524 | struct untracked_cache_dir *untracked, |
| 2525 | struct index_state *istate, |
| 2526 | struct strbuf *path, |
| 2527 | int check_only) |
| 2528 | { |
| 2529 | struct stat st; |
| 2530 | |
| 2531 | if (!untracked) |
| 2532 | return 0; |
| 2533 | |
| 2534 | /* |
| 2535 | * With fsmonitor, we can trust the untracked cache's valid field. |
| 2536 | */ |
| 2537 | refresh_fsmonitor(istate); |
| 2538 | if (!(dir->untracked->use_fsmonitor && untracked->valid)) { |
| 2539 | if (lstat(path->len ? path->buf : ".", &st)) { |
| 2540 | memset(&untracked->stat_data, 0, sizeof(untracked->stat_data)); |
| 2541 | return 0; |
| 2542 | } |
| 2543 | if (!untracked->valid || |
| 2544 | match_stat_data_racy(istate, &untracked->stat_data, &st)) { |
| 2545 | fill_stat_data(&untracked->stat_data, &st); |
| 2546 | return 0; |
| 2547 | } |
| 2548 | } |
| 2549 | |
| 2550 | if (untracked->check_only != !!check_only) |
| 2551 | return 0; |
| 2552 | |
| 2553 | /* |
| 2554 | * prep_exclude will be called eventually on this directory, |
| 2555 | * but it's called much later in last_matching_pattern(). We |
| 2556 | * need it now to determine the validity of the cache for this |
| 2557 | * path. The next calls will be nearly no-op, the way |
| 2558 | * prep_exclude() is designed. |
| 2559 | */ |
| 2560 | if (path->len && path->buf[path->len - 1] != '/') { |
| 2561 | strbuf_addch(path, '/'); |
| 2562 | prep_exclude(dir, istate, path->buf, path->len); |
| 2563 | strbuf_setlen(path, path->len - 1); |
| 2564 | } else |
| 2565 | prep_exclude(dir, istate, path->buf, path->len); |
| 2566 | |
| 2567 | /* hopefully prep_exclude() haven't invalidated this entry... */ |
| 2568 | return untracked->valid; |
| 2569 | } |
| 2570 | |
| 2571 | static int open_cached_dir(struct cached_dir *cdir, |
| 2572 | struct dir_struct *dir, |
no test coverage detected