fsmonitor: skip lstat deletion check during git diff-index

Teach git to honor fsmonitor rather than issuing an lstat when checking for dirty local deletes. Eliminates O(files) lstats during `git diff HEAD` Signed-off-by: Nipunn Koorapati <nipunn@dropbox.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nipunn Koorapati committed Mar 17, 2021 at 21:22 UTC 4f3d6d026176a48991c4e5ff95c8db583af38148
1 file changed +4 -1
diff-lib.c
+4 -1
@@ -30,7 +30,7 @@
30 */
31 static int check_removed(const struct cache_entry *ce, struct stat *st)
32 {
33 - if (lstat(ce->name, st) < 0) {
33 + if (!(ce->ce_flags & CE_FSMONITOR_VALID) && lstat(ce->name, st) < 0) {
34 if (!is_missing_file_error(errno))
35 return -1;
36 return 1;
@@ -574,6 +574,7 @@ int run_diff_index(struct rev_info *revs, unsigned int option)
574 struct object_id oid;
575 const char *name;
576 char merge_base_hex[GIT_MAX_HEXSZ + 1];
577 + struct index_state *istate = revs->diffopt.repo->index;
578
579 if (revs->pending.nr != 1)
580 BUG("run_diff_index must be passed exactly one tree");
@@ -581,6 +582,8 @@ int run_diff_index(struct rev_info *revs, unsigned int option)
582 trace_performance_enter();
583 ent = revs->pending.objects;
584
585 + refresh_fsmonitor(istate);
586 +
587 if (merge_base) {
588 diff_get_merge_base(revs, &oid);
589 name = oid_to_hex_r(merge_base_hex, &oid);