Skip to content

Commit 473b431

Browse files
committed
Merge branch 'us/unpack-trees-fsmonitor'
Users of oneway_merge() (like "reset --hard") learned to take advantage of fsmonitor to avoid unnecessary lstat(2) calls. * us/unpack-trees-fsmonitor: unpack-trees: skip stat on fsmonitor-valid files
2 parents e0f9ec9 + 679f2f9 commit 473b431

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

fsmonitor.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,26 @@ void refresh_fsmonitor(struct index_state *istate)
191191
}
192192
if (bol < query_result.len)
193193
fsmonitor_refresh_callback(istate, buf + bol);
194+
195+
/* Now mark the untracked cache for fsmonitor usage */
196+
if (istate->untracked)
197+
istate->untracked->use_fsmonitor = 1;
194198
} else {
199+
200+
/* We only want to run the post index changed hook if we've actually changed entries, so keep track
201+
* if we actually changed entries or not */
202+
int is_cache_changed = 0;
195203
/* Mark all entries invalid */
196-
for (i = 0; i < istate->cache_nr; i++)
197-
istate->cache[i]->ce_flags &= ~CE_FSMONITOR_VALID;
204+
for (i = 0; i < istate->cache_nr; i++) {
205+
if (istate->cache[i]->ce_flags & CE_FSMONITOR_VALID) {
206+
is_cache_changed = 1;
207+
istate->cache[i]->ce_flags &= ~CE_FSMONITOR_VALID;
208+
}
209+
}
198210

199211
/* If we're going to check every file, ensure we save the results */
200-
istate->cache_changed |= FSMONITOR_CHANGED;
212+
if (is_cache_changed)
213+
istate->cache_changed |= FSMONITOR_CHANGED;
201214

202215
if (istate->untracked)
203216
istate->untracked->use_fsmonitor = 0;
@@ -259,9 +272,7 @@ void tweak_fsmonitor(struct index_state *istate)
259272
(uintmax_t)istate->fsmonitor_dirty->bit_size, istate->cache_nr);
260273
ewah_each_bit(istate->fsmonitor_dirty, fsmonitor_ewah_callback, istate);
261274

262-
/* Now mark the untracked cache for fsmonitor usage */
263-
if (istate->untracked)
264-
istate->untracked->use_fsmonitor = 1;
275+
refresh_fsmonitor(istate);
265276
}
266277

267278
ewah_free(istate->fsmonitor_dirty);

t/t7519-status-fsmonitor.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ EOF
106106

107107
# test that "update-index --fsmonitor-valid" sets the fsmonitor valid bit
108108
test_expect_success 'update-index --fsmonitor-valid" sets the fsmonitor valid bit' '
109+
write_script .git/hooks/fsmonitor-test<<-\EOF &&
110+
EOF
109111
git update-index --fsmonitor &&
110112
git update-index --fsmonitor-valid dir1/modified &&
111113
git update-index --fsmonitor-valid dir2/modified &&
@@ -164,6 +166,8 @@ EOF
164166

165167
# test that newly added files are marked valid
166168
test_expect_success 'newly added files are marked valid' '
169+
write_script .git/hooks/fsmonitor-test<<-\EOF &&
170+
EOF
167171
git add new &&
168172
git add dir1/new &&
169173
git add dir2/new &&
@@ -218,11 +222,12 @@ test_expect_success '*only* files returned by the integration script get flagged
218222
# Ensure commands that call refresh_index() to move the index back in time
219223
# properly invalidate the fsmonitor cache
220224
test_expect_success 'refresh_index() invalidates fsmonitor cache' '
221-
write_script .git/hooks/fsmonitor-test<<-\EOF &&
222-
EOF
223225
clean_repo &&
224226
dirty_repo &&
227+
write_integration_script &&
225228
git add . &&
229+
write_script .git/hooks/fsmonitor-test<<-\EOF &&
230+
EOF
226231
git commit -m "to reset" &&
227232
git reset HEAD~1 &&
228233
git status >actual &&

unpack-trees.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1504,6 +1504,9 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
15041504
o->merge_size = len;
15051505
mark_all_ce_unused(o->src_index);
15061506

1507+
if (o->src_index->fsmonitor_last_update)
1508+
o->result.fsmonitor_last_update = o->src_index->fsmonitor_last_update;
1509+
15071510
/*
15081511
* Sparse checkout loop #1: set NEW_SKIP_WORKTREE on existing entries
15091512
*/
@@ -2384,7 +2387,8 @@ int oneway_merge(const struct cache_entry * const *src,
23842387

23852388
if (old && same(old, a)) {
23862389
int update = 0;
2387-
if (o->reset && o->update && !ce_uptodate(old) && !ce_skip_worktree(old)) {
2390+
if (o->reset && o->update && !ce_uptodate(old) && !ce_skip_worktree(old) &&
2391+
!(old->ce_flags & CE_FSMONITOR_VALID)) {
23882392
struct stat st;
23892393
if (lstat(old->name, &st) ||
23902394
ie_match_stat(o->src_index, old, &st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE))

0 commit comments

Comments
 (0)