Skip to content

Commit f8fe49e

Browse files
derrickstoleegitster
authored andcommitted
fsmonitor: integrate with sparse index
If we need to expand a sparse-index into a full one, then the FS Monitor bitmap is going to be incorrect. Ensure that we start fresh at such an event. While this is currently a performance drawback, the eventual hope of the sparse-index feature is that these expansions will be rare and hence we will be able to keep the FS Monitor data accurate across multiple Git commands. These tests are added to demonstrate that the behavior is the same across a full index and a sparse index, but also that file modifications to a tracked directory outside of the sparse cone will trigger ensure_full_index(). Reviewed-by: Elijah Newren <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fe0d576 commit f8fe49e

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

sparse-index.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ int convert_to_sparse(struct index_state *istate)
186186
cache_tree_free(&istate->cache_tree);
187187
cache_tree_update(istate, 0);
188188

189+
istate->fsmonitor_has_run_once = 0;
190+
FREE_AND_NULL(istate->fsmonitor_dirty);
191+
FREE_AND_NULL(istate->fsmonitor_last_update);
192+
189193
istate->sparse_index = 1;
190194
trace2_region_leave("index", "convert_to_sparse", istate->repo);
191195
return 0;
@@ -282,6 +286,9 @@ void ensure_full_index(struct index_state *istate)
282286
istate->cache = full->cache;
283287
istate->cache_nr = full->cache_nr;
284288
istate->cache_alloc = full->cache_alloc;
289+
istate->fsmonitor_has_run_once = 0;
290+
FREE_AND_NULL(istate->fsmonitor_dirty);
291+
FREE_AND_NULL(istate->fsmonitor_last_update);
285292

286293
strbuf_release(&base);
287294
free(full);

t/t7519-status-fsmonitor.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ test_expect_success 'setup' '
7373
expect*
7474
actual*
7575
marker*
76+
trace2*
7677
EOF
7778
'
7879

@@ -383,4 +384,52 @@ test_expect_success 'status succeeds after staging/unstaging' '
383384
)
384385
'
385386

387+
# Usage:
388+
# check_sparse_index_behavior [!]
389+
# If "!" is supplied, then we verify that we do not call ensure_full_index
390+
# during a call to 'git status'. Otherwise, we verify that we _do_ call it.
391+
check_sparse_index_behavior () {
392+
git status --porcelain=v2 >expect &&
393+
git sparse-checkout init --cone --sparse-index &&
394+
git sparse-checkout set dir1 dir2 &&
395+
GIT_TRACE2_EVENT="$(pwd)/trace2.txt" GIT_TRACE2_EVENT_NESTING=10 \
396+
git status --porcelain=v2 >actual &&
397+
test_region $1 index ensure_full_index trace2.txt &&
398+
test_region fsm_hook query trace2.txt &&
399+
test_cmp expect actual &&
400+
rm trace2.txt &&
401+
git sparse-checkout disable
402+
}
403+
404+
test_expect_success 'status succeeds with sparse index' '
405+
git reset --hard &&
406+
407+
test_config core.fsmonitor "$TEST_DIRECTORY/t7519/fsmonitor-all" &&
408+
check_sparse_index_behavior ! &&
409+
410+
write_script .git/hooks/fsmonitor-test<<-\EOF &&
411+
printf "last_update_token\0"
412+
EOF
413+
git config core.fsmonitor .git/hooks/fsmonitor-test &&
414+
check_sparse_index_behavior ! &&
415+
416+
write_script .git/hooks/fsmonitor-test<<-\EOF &&
417+
printf "last_update_token\0"
418+
printf "dir1/modified\0"
419+
EOF
420+
check_sparse_index_behavior ! &&
421+
422+
cp -r dir1 dir1a &&
423+
git add dir1a &&
424+
git commit -m "add dir1a" &&
425+
426+
# This one modifies outside the sparse-checkout definition
427+
# and hence we expect to expand the sparse-index.
428+
write_script .git/hooks/fsmonitor-test<<-\EOF &&
429+
printf "last_update_token\0"
430+
printf "dir1a/modified\0"
431+
EOF
432+
check_sparse_index_behavior
433+
'
434+
386435
test_done

0 commit comments

Comments
 (0)