]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fsmonitor: use fsmonitor data in `git diff`
authorAlex Vandiver <alexmv@dropbox.com>
Tue, 20 Oct 2020 13:40:58 +0000 (13:40 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 20 Oct 2020 19:52:21 +0000 (12:52 -0700)
With fsmonitor enabled, the first call to match_stat_with_submodule
calls refresh_fsmonitor, incurring the overhead of reading the list of
updated files -- but run_diff_files does not respect the
CE_FSMONITOR_VALID flag.

Make use of the fsmonitor extension to skip lstat() calls on files
that fsmonitor judged as unmodified.

Notably, this change improves performance of the git shell prompt when
GIT_PS1_SHOWDIRTYSTATE is set.

Signed-off-by: Alex Vandiver <alexmv@dropbox.com>
Signed-off-by: Nipunn Koorapati <nipunn@dropbox.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
diff-lib.c

index f95c6de75fc843fd19f683b6217c5fe87f341cd1..d2d31b9f82cce5b934a89ee263dc7b51131f2ab9 100644 (file)
@@ -97,6 +97,8 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
 
        diff_set_mnemonic_prefix(&revs->diffopt, "i/", "w/");
 
+       refresh_fsmonitor(istate);
+
        if (diff_unmerged_stage < 0)
                diff_unmerged_stage = 2;
        entries = istate->cache_nr;
@@ -197,8 +199,17 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
                if (ce_uptodate(ce) || ce_skip_worktree(ce))
                        continue;
 
-               /* If CE_VALID is set, don't look at workdir for file removal */
-               if (ce->ce_flags & CE_VALID) {
+               /*
+                * When CE_VALID is set (via "update-index --assume-unchanged"
+                * or via adding paths while core.ignorestat is set to true),
+                * the user has promised that the working tree file for that
+                * path will not be modified.  When CE_FSMONITOR_VALID is true,
+                * the fsmonitor knows that the path hasn't been modified since
+                * we refreshed the cached stat information.  In either case,
+                * we do not have to stat to see if the path has been removed
+                * or modified.
+                */
+               if (ce->ce_flags & (CE_VALID | CE_FSMONITOR_VALID)) {
                        changed = 0;
                        newmode = ce->ce_mode;
                } else {