fsmonitor: use fsmonitor data in `git diff`
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>
Alex Vandiver committed
Oct 20, 2020 at 13:40 UTC
c9052a8392878d9e38381db5d2172f7f8f7272a3
1 file changed
+13
-2
diff-lib.c
+13
-2
@@ -97,6 +97,8 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
97
98
diff_set_mnemonic_prefix(&revs->diffopt, "i/", "w/");
99
100
+ refresh_fsmonitor(istate);
101
+
102
if (diff_unmerged_stage < 0)
103
diff_unmerged_stage = 2;
104
entries = istate->cache_nr;
@@ -197,8 +199,17 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
199
if (ce_uptodate(ce) || ce_skip_worktree(ce))
200
continue;
201
200
- /* If CE_VALID is set, don't look at workdir for file removal */
201
- if (ce->ce_flags & CE_VALID) {
202
+ /*
203
+ * When CE_VALID is set (via "update-index --assume-unchanged"
204
+ * or via adding paths while core.ignorestat is set to true),
205
+ * the user has promised that the working tree file for that
206
+ * path will not be modified. When CE_FSMONITOR_VALID is true,
207
+ * the fsmonitor knows that the path hasn't been modified since
208
+ * we refreshed the cached stat information. In either case,
209
+ * we do not have to stat to see if the path has been removed
210
+ * or modified.
211
+ */
212
+ if (ce->ce_flags & (CE_VALID | CE_FSMONITOR_VALID)) {
213
changed = 0;
214
newmode = ce->ce_mode;
215
} else {