Skip to content

Commit ed4d535

Browse files
committed
Merge branch 'sg/test-split-index-fix'
Test updates. * sg/test-split-index-fix: read-cache: fix GIT_TEST_SPLIT_INDEX tests: disable GIT_TEST_SPLIT_INDEX for sparse index tests read-cache: look for shared index files next to the index, too t1600-index: disable GIT_TEST_SPLIT_INDEX t1600-index: don't run git commands upstream of a pipe t1600-index: remove unnecessary redirection
2 parents 9567a67 + e8ffd03 commit ed4d535

File tree

5 files changed

+121
-56
lines changed

5 files changed

+121
-56
lines changed

read-cache.c

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2400,9 +2400,21 @@ int read_index_from(struct index_state *istate, const char *path,
24002400
base_path = xstrfmt("%s/sharedindex.%s", gitdir, base_oid_hex);
24012401
trace2_region_enter_printf("index", "shared/do_read_index",
24022402
the_repository, "%s", base_path);
2403-
ret = do_read_index(split_index->base, base_path, 1);
2403+
ret = do_read_index(split_index->base, base_path, 0);
24042404
trace2_region_leave_printf("index", "shared/do_read_index",
24052405
the_repository, "%s", base_path);
2406+
if (!ret) {
2407+
char *path_copy = xstrdup(path);
2408+
const char *base_path2 = xstrfmt("%s/sharedindex.%s",
2409+
dirname(path_copy),
2410+
base_oid_hex);
2411+
free(path_copy);
2412+
trace2_region_enter_printf("index", "shared/do_read_index",
2413+
the_repository, "%s", base_path2);
2414+
ret = do_read_index(split_index->base, base_path2, 1);
2415+
trace2_region_leave_printf("index", "shared/do_read_index",
2416+
the_repository, "%s", base_path2);
2417+
}
24062418
if (!oideq(&split_index->base_oid, &split_index->base->oid))
24072419
die(_("broken index, expect %s in %s, got %s"),
24082420
base_oid_hex, base_path,
@@ -2821,11 +2833,8 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
28212833
}
28222834
}
28232835

2824-
if (!istate->version) {
2836+
if (!istate->version)
28252837
istate->version = get_index_format_default(the_repository);
2826-
if (git_env_bool("GIT_TEST_SPLIT_INDEX", 0))
2827-
init_split_index(istate);
2828-
}
28292838

28302839
/* demote version 3 to version 2 when the latter suffices */
28312840
if (istate->version == 3 || istate->version == 2)
@@ -3252,7 +3261,7 @@ static int too_many_not_shared_entries(struct index_state *istate)
32523261
int write_locked_index(struct index_state *istate, struct lock_file *lock,
32533262
unsigned flags)
32543263
{
3255-
int new_shared_index, ret;
3264+
int new_shared_index, ret, test_split_index_env;
32563265
struct split_index *si = istate->split_index;
32573266

32583267
if (git_env_bool("GIT_TEST_CHECK_CACHE_TREE", 0))
@@ -3267,18 +3276,26 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
32673276
if (istate->fsmonitor_last_update)
32683277
fill_fsmonitor_bitmap(istate);
32693278

3270-
if (!si || alternate_index_output ||
3279+
test_split_index_env = git_env_bool("GIT_TEST_SPLIT_INDEX", 0);
3280+
3281+
if ((!si && !test_split_index_env) ||
3282+
alternate_index_output ||
32713283
(istate->cache_changed & ~EXTMASK)) {
32723284
if (si)
32733285
oidclr(&si->base_oid);
32743286
ret = do_write_locked_index(istate, lock, flags);
32753287
goto out;
32763288
}
32773289

3278-
if (git_env_bool("GIT_TEST_SPLIT_INDEX", 0)) {
3279-
int v = si->base_oid.hash[0];
3280-
if ((v & 15) < 6)
3290+
if (test_split_index_env) {
3291+
if (!si) {
3292+
si = init_split_index(istate);
32813293
istate->cache_changed |= SPLIT_INDEX_ORDERED;
3294+
} else {
3295+
int v = si->base_oid.hash[0];
3296+
if ((v & 15) < 6)
3297+
istate->cache_changed |= SPLIT_INDEX_ORDERED;
3298+
}
32823299
}
32833300
if (too_many_not_shared_entries(istate))
32843301
istate->cache_changed |= SPLIT_INDEX_ORDERED;

t/t1091-sparse-checkout-builtin.sh

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -206,16 +206,21 @@ test_expect_success 'sparse-checkout disable' '
206206
'
207207

208208
test_expect_success 'sparse-index enabled and disabled' '
209-
git -C repo sparse-checkout init --cone --sparse-index &&
210-
test_cmp_config -C repo true index.sparse &&
211-
test-tool -C repo read-cache --table >cache &&
212-
grep " tree " cache &&
213-
214-
git -C repo sparse-checkout disable &&
215-
test-tool -C repo read-cache --table >cache &&
216-
! grep " tree " cache &&
217-
git -C repo config --list >config &&
218-
! grep index.sparse config
209+
(
210+
sane_unset GIT_TEST_SPLIT_INDEX &&
211+
git -C repo update-index --no-split-index &&
212+
213+
git -C repo sparse-checkout init --cone --sparse-index &&
214+
test_cmp_config -C repo true index.sparse &&
215+
test-tool -C repo read-cache --table >cache &&
216+
grep " tree " cache &&
217+
218+
git -C repo sparse-checkout disable &&
219+
test-tool -C repo read-cache --table >cache &&
220+
! grep " tree " cache &&
221+
git -C repo config --list >config &&
222+
! grep index.sparse config
223+
)
219224
'
220225

221226
test_expect_success 'cone mode: init and set' '

t/t1600-index.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ test_description='index file specific tests'
44

55
. ./test-lib.sh
66

7+
sane_unset GIT_TEST_SPLIT_INDEX
8+
79
test_expect_success 'setup' '
810
echo 1 >a
911
'
@@ -13,7 +15,8 @@ test_expect_success 'bogus GIT_INDEX_VERSION issues warning' '
1315
rm -f .git/index &&
1416
GIT_INDEX_VERSION=2bogus &&
1517
export GIT_INDEX_VERSION &&
16-
git add a 2>&1 | sed "s/[0-9]//" >actual.err &&
18+
git add a 2>err &&
19+
sed "s/[0-9]//" err >actual.err &&
1720
sed -e "s/ Z$/ /" <<-\EOF >expect.err &&
1821
warning: GIT_INDEX_VERSION set, but the value is invalid.
1922
Using version Z
@@ -27,7 +30,8 @@ test_expect_success 'out of bounds GIT_INDEX_VERSION issues warning' '
2730
rm -f .git/index &&
2831
GIT_INDEX_VERSION=1 &&
2932
export GIT_INDEX_VERSION &&
30-
git add a 2>&1 | sed "s/[0-9]//" >actual.err &&
33+
git add a 2>err &&
34+
sed "s/[0-9]//" err >actual.err &&
3135
sed -e "s/ Z$/ /" <<-\EOF >expect.err &&
3236
warning: GIT_INDEX_VERSION set, but the value is invalid.
3337
Using version Z
@@ -50,7 +54,8 @@ test_expect_success 'out of bounds index.version issues warning' '
5054
sane_unset GIT_INDEX_VERSION &&
5155
rm -f .git/index &&
5256
git config --add index.version 1 &&
53-
git add a 2>&1 | sed "s/[0-9]//" >actual.err &&
57+
git add a 2>err &&
58+
sed "s/[0-9]//" err >actual.err &&
5459
sed -e "s/ Z$/ /" <<-\EOF >expect.err &&
5560
warning: index.version set, but the value is invalid.
5661
Using version Z
@@ -79,7 +84,7 @@ test_index_version () {
7984
else
8085
unset GIT_INDEX_VERSION
8186
fi &&
82-
git add a 2>&1 &&
87+
git add a &&
8388
echo $EXPECTED_OUTPUT_VERSION >expect &&
8489
test-tool index-version <.git/index >actual &&
8590
test_cmp expect actual

t/t1700-split-index.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,4 +510,38 @@ test_expect_success 'do not refresh null base index' '
510510
)
511511
'
512512

513+
test_expect_success 'reading split index at alternate location' '
514+
git init reading-alternate-location &&
515+
(
516+
cd reading-alternate-location &&
517+
>file-in-alternate &&
518+
git update-index --split-index --add file-in-alternate
519+
) &&
520+
echo file-in-alternate >expect &&
521+
522+
# Should be able to find the shared index both right next to
523+
# the specified split index file ...
524+
GIT_INDEX_FILE=./reading-alternate-location/.git/index \
525+
git ls-files --cached >actual &&
526+
test_cmp expect actual &&
527+
528+
# ... and, for backwards compatibility, in the current GIT_DIR
529+
# as well.
530+
mv -v ./reading-alternate-location/.git/sharedindex.* .git &&
531+
GIT_INDEX_FILE=./reading-alternate-location/.git/index \
532+
git ls-files --cached >actual &&
533+
test_cmp expect actual
534+
'
535+
536+
test_expect_success 'GIT_TEST_SPLIT_INDEX works' '
537+
git init git-test-split-index &&
538+
(
539+
cd git-test-split-index &&
540+
>file &&
541+
GIT_TEST_SPLIT_INDEX=1 git update-index --add file &&
542+
ls -l .git/sharedindex.* >actual &&
543+
test_line_count = 1 actual
544+
)
545+
'
546+
513547
test_done

t/t7519-status-fsmonitor.sh

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -399,41 +399,45 @@ check_sparse_index_behavior () {
399399
}
400400

401401
test_expect_success 'status succeeds with sparse index' '
402-
git clone . full &&
403-
git clone --sparse . sparse &&
404-
git -C sparse sparse-checkout init --cone --sparse-index &&
405-
git -C sparse sparse-checkout set dir1 dir2 &&
402+
(
403+
sane_unset GIT_TEST_SPLIT_INDEX &&
406404
407-
write_script .git/hooks/fsmonitor-test <<-\EOF &&
408-
printf "last_update_token\0"
409-
EOF
410-
git -C full config core.fsmonitor ../.git/hooks/fsmonitor-test &&
411-
git -C sparse config core.fsmonitor ../.git/hooks/fsmonitor-test &&
412-
check_sparse_index_behavior ! &&
405+
git clone . full &&
406+
git clone --sparse . sparse &&
407+
git -C sparse sparse-checkout init --cone --sparse-index &&
408+
git -C sparse sparse-checkout set dir1 dir2 &&
413409
414-
write_script .git/hooks/fsmonitor-test <<-\EOF &&
415-
printf "last_update_token\0"
416-
printf "dir1/modified\0"
417-
EOF
418-
check_sparse_index_behavior ! &&
419-
420-
git -C sparse sparse-checkout add dir1a &&
410+
write_script .git/hooks/fsmonitor-test <<-\EOF &&
411+
printf "last_update_token\0"
412+
EOF
413+
git -C full config core.fsmonitor ../.git/hooks/fsmonitor-test &&
414+
git -C sparse config core.fsmonitor ../.git/hooks/fsmonitor-test &&
415+
check_sparse_index_behavior ! &&
421416
422-
for repo in full sparse
423-
do
424-
cp -r $repo/dir1 $repo/dir1a &&
425-
git -C $repo add dir1a &&
426-
git -C $repo commit -m "add dir1a" || return 1
427-
done &&
428-
git -C sparse sparse-checkout set dir1 dir2 &&
429-
430-
# This one modifies outside the sparse-checkout definition
431-
# and hence we expect to expand the sparse-index.
432-
write_script .git/hooks/fsmonitor-test <<-\EOF &&
433-
printf "last_update_token\0"
434-
printf "dir1a/modified\0"
435-
EOF
436-
check_sparse_index_behavior
417+
write_script .git/hooks/fsmonitor-test <<-\EOF &&
418+
printf "last_update_token\0"
419+
printf "dir1/modified\0"
420+
EOF
421+
check_sparse_index_behavior ! &&
422+
423+
git -C sparse sparse-checkout add dir1a &&
424+
425+
for repo in full sparse
426+
do
427+
cp -r $repo/dir1 $repo/dir1a &&
428+
git -C $repo add dir1a &&
429+
git -C $repo commit -m "add dir1a" || return 1
430+
done &&
431+
git -C sparse sparse-checkout set dir1 dir2 &&
432+
433+
# This one modifies outside the sparse-checkout definition
434+
# and hence we expect to expand the sparse-index.
435+
write_script .git/hooks/fsmonitor-test <<-\EOF &&
436+
printf "last_update_token\0"
437+
printf "dir1a/modified\0"
438+
EOF
439+
check_sparse_index_behavior
440+
)
437441
'
438442

439443
test_done

0 commit comments

Comments
 (0)