Skip to content

Commit c9052a8

Browse files
Alex Vandivergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Nipunn Koorapati <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 430cabb commit c9052a8

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

diff-lib.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
9797

9898
diff_set_mnemonic_prefix(&revs->diffopt, "i/", "w/");
9999

100+
refresh_fsmonitor(istate);
101+
100102
if (diff_unmerged_stage < 0)
101103
diff_unmerged_stage = 2;
102104
entries = istate->cache_nr;
@@ -197,8 +199,17 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
197199
if (ce_uptodate(ce) || ce_skip_worktree(ce))
198200
continue;
199201

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)) {
202213
changed = 0;
203214
newmode = ce->ce_mode;
204215
} else {

0 commit comments

Comments
 (0)