mirror of
https://github.com/git/git
synced 2024-08-25 02:35:46 +00:00
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
This commit is contained in:
commit
ed4d535342
37
read-cache.c
37
read-cache.c
|
@ -2400,9 +2400,21 @@ int read_index_from(struct index_state *istate, const char *path,
|
|||
base_path = xstrfmt("%s/sharedindex.%s", gitdir, base_oid_hex);
|
||||
trace2_region_enter_printf("index", "shared/do_read_index",
|
||||
the_repository, "%s", base_path);
|
||||
ret = do_read_index(split_index->base, base_path, 1);
|
||||
ret = do_read_index(split_index->base, base_path, 0);
|
||||
trace2_region_leave_printf("index", "shared/do_read_index",
|
||||
the_repository, "%s", base_path);
|
||||
if (!ret) {
|
||||
char *path_copy = xstrdup(path);
|
||||
const char *base_path2 = xstrfmt("%s/sharedindex.%s",
|
||||
dirname(path_copy),
|
||||
base_oid_hex);
|
||||
free(path_copy);
|
||||
trace2_region_enter_printf("index", "shared/do_read_index",
|
||||
the_repository, "%s", base_path2);
|
||||
ret = do_read_index(split_index->base, base_path2, 1);
|
||||
trace2_region_leave_printf("index", "shared/do_read_index",
|
||||
the_repository, "%s", base_path2);
|
||||
}
|
||||
if (!oideq(&split_index->base_oid, &split_index->base->oid))
|
||||
die(_("broken index, expect %s in %s, got %s"),
|
||||
base_oid_hex, base_path,
|
||||
|
@ -2821,11 +2833,8 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,
|
|||
}
|
||||
}
|
||||
|
||||
if (!istate->version) {
|
||||
if (!istate->version)
|
||||
istate->version = get_index_format_default(the_repository);
|
||||
if (git_env_bool("GIT_TEST_SPLIT_INDEX", 0))
|
||||
init_split_index(istate);
|
||||
}
|
||||
|
||||
/* demote version 3 to version 2 when the latter suffices */
|
||||
if (istate->version == 3 || istate->version == 2)
|
||||
|
@ -3252,7 +3261,7 @@ static int too_many_not_shared_entries(struct index_state *istate)
|
|||
int write_locked_index(struct index_state *istate, struct lock_file *lock,
|
||||
unsigned flags)
|
||||
{
|
||||
int new_shared_index, ret;
|
||||
int new_shared_index, ret, test_split_index_env;
|
||||
struct split_index *si = istate->split_index;
|
||||
|
||||
if (git_env_bool("GIT_TEST_CHECK_CACHE_TREE", 0))
|
||||
|
@ -3267,7 +3276,10 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
|
|||
if (istate->fsmonitor_last_update)
|
||||
fill_fsmonitor_bitmap(istate);
|
||||
|
||||
if (!si || alternate_index_output ||
|
||||
test_split_index_env = git_env_bool("GIT_TEST_SPLIT_INDEX", 0);
|
||||
|
||||
if ((!si && !test_split_index_env) ||
|
||||
alternate_index_output ||
|
||||
(istate->cache_changed & ~EXTMASK)) {
|
||||
if (si)
|
||||
oidclr(&si->base_oid);
|
||||
|
@ -3275,10 +3287,15 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
|
|||
goto out;
|
||||
}
|
||||
|
||||
if (git_env_bool("GIT_TEST_SPLIT_INDEX", 0)) {
|
||||
int v = si->base_oid.hash[0];
|
||||
if ((v & 15) < 6)
|
||||
if (test_split_index_env) {
|
||||
if (!si) {
|
||||
si = init_split_index(istate);
|
||||
istate->cache_changed |= SPLIT_INDEX_ORDERED;
|
||||
} else {
|
||||
int v = si->base_oid.hash[0];
|
||||
if ((v & 15) < 6)
|
||||
istate->cache_changed |= SPLIT_INDEX_ORDERED;
|
||||
}
|
||||
}
|
||||
if (too_many_not_shared_entries(istate))
|
||||
istate->cache_changed |= SPLIT_INDEX_ORDERED;
|
||||
|
|
|
@ -206,16 +206,21 @@ test_expect_success 'sparse-checkout disable' '
|
|||
'
|
||||
|
||||
test_expect_success 'sparse-index enabled and disabled' '
|
||||
git -C repo sparse-checkout init --cone --sparse-index &&
|
||||
test_cmp_config -C repo true index.sparse &&
|
||||
test-tool -C repo read-cache --table >cache &&
|
||||
grep " tree " cache &&
|
||||
(
|
||||
sane_unset GIT_TEST_SPLIT_INDEX &&
|
||||
git -C repo update-index --no-split-index &&
|
||||
|
||||
git -C repo sparse-checkout disable &&
|
||||
test-tool -C repo read-cache --table >cache &&
|
||||
! grep " tree " cache &&
|
||||
git -C repo config --list >config &&
|
||||
! grep index.sparse config
|
||||
git -C repo sparse-checkout init --cone --sparse-index &&
|
||||
test_cmp_config -C repo true index.sparse &&
|
||||
test-tool -C repo read-cache --table >cache &&
|
||||
grep " tree " cache &&
|
||||
|
||||
git -C repo sparse-checkout disable &&
|
||||
test-tool -C repo read-cache --table >cache &&
|
||||
! grep " tree " cache &&
|
||||
git -C repo config --list >config &&
|
||||
! grep index.sparse config
|
||||
)
|
||||
'
|
||||
|
||||
test_expect_success 'cone mode: init and set' '
|
||||
|
|
|
@ -4,6 +4,8 @@ test_description='index file specific tests'
|
|||
|
||||
. ./test-lib.sh
|
||||
|
||||
sane_unset GIT_TEST_SPLIT_INDEX
|
||||
|
||||
test_expect_success 'setup' '
|
||||
echo 1 >a
|
||||
'
|
||||
|
@ -13,7 +15,8 @@ test_expect_success 'bogus GIT_INDEX_VERSION issues warning' '
|
|||
rm -f .git/index &&
|
||||
GIT_INDEX_VERSION=2bogus &&
|
||||
export GIT_INDEX_VERSION &&
|
||||
git add a 2>&1 | sed "s/[0-9]//" >actual.err &&
|
||||
git add a 2>err &&
|
||||
sed "s/[0-9]//" err >actual.err &&
|
||||
sed -e "s/ Z$/ /" <<-\EOF >expect.err &&
|
||||
warning: GIT_INDEX_VERSION set, but the value is invalid.
|
||||
Using version Z
|
||||
|
@ -27,7 +30,8 @@ test_expect_success 'out of bounds GIT_INDEX_VERSION issues warning' '
|
|||
rm -f .git/index &&
|
||||
GIT_INDEX_VERSION=1 &&
|
||||
export GIT_INDEX_VERSION &&
|
||||
git add a 2>&1 | sed "s/[0-9]//" >actual.err &&
|
||||
git add a 2>err &&
|
||||
sed "s/[0-9]//" err >actual.err &&
|
||||
sed -e "s/ Z$/ /" <<-\EOF >expect.err &&
|
||||
warning: GIT_INDEX_VERSION set, but the value is invalid.
|
||||
Using version Z
|
||||
|
@ -50,7 +54,8 @@ test_expect_success 'out of bounds index.version issues warning' '
|
|||
sane_unset GIT_INDEX_VERSION &&
|
||||
rm -f .git/index &&
|
||||
git config --add index.version 1 &&
|
||||
git add a 2>&1 | sed "s/[0-9]//" >actual.err &&
|
||||
git add a 2>err &&
|
||||
sed "s/[0-9]//" err >actual.err &&
|
||||
sed -e "s/ Z$/ /" <<-\EOF >expect.err &&
|
||||
warning: index.version set, but the value is invalid.
|
||||
Using version Z
|
||||
|
@ -79,7 +84,7 @@ test_index_version () {
|
|||
else
|
||||
unset GIT_INDEX_VERSION
|
||||
fi &&
|
||||
git add a 2>&1 &&
|
||||
git add a &&
|
||||
echo $EXPECTED_OUTPUT_VERSION >expect &&
|
||||
test-tool index-version <.git/index >actual &&
|
||||
test_cmp expect actual
|
||||
|
|
|
@ -510,4 +510,38 @@ test_expect_success 'do not refresh null base index' '
|
|||
)
|
||||
'
|
||||
|
||||
test_expect_success 'reading split index at alternate location' '
|
||||
git init reading-alternate-location &&
|
||||
(
|
||||
cd reading-alternate-location &&
|
||||
>file-in-alternate &&
|
||||
git update-index --split-index --add file-in-alternate
|
||||
) &&
|
||||
echo file-in-alternate >expect &&
|
||||
|
||||
# Should be able to find the shared index both right next to
|
||||
# the specified split index file ...
|
||||
GIT_INDEX_FILE=./reading-alternate-location/.git/index \
|
||||
git ls-files --cached >actual &&
|
||||
test_cmp expect actual &&
|
||||
|
||||
# ... and, for backwards compatibility, in the current GIT_DIR
|
||||
# as well.
|
||||
mv -v ./reading-alternate-location/.git/sharedindex.* .git &&
|
||||
GIT_INDEX_FILE=./reading-alternate-location/.git/index \
|
||||
git ls-files --cached >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'GIT_TEST_SPLIT_INDEX works' '
|
||||
git init git-test-split-index &&
|
||||
(
|
||||
cd git-test-split-index &&
|
||||
>file &&
|
||||
GIT_TEST_SPLIT_INDEX=1 git update-index --add file &&
|
||||
ls -l .git/sharedindex.* >actual &&
|
||||
test_line_count = 1 actual
|
||||
)
|
||||
'
|
||||
|
||||
test_done
|
||||
|
|
|
@ -399,41 +399,45 @@ check_sparse_index_behavior () {
|
|||
}
|
||||
|
||||
test_expect_success 'status succeeds with sparse index' '
|
||||
git clone . full &&
|
||||
git clone --sparse . sparse &&
|
||||
git -C sparse sparse-checkout init --cone --sparse-index &&
|
||||
git -C sparse sparse-checkout set dir1 dir2 &&
|
||||
(
|
||||
sane_unset GIT_TEST_SPLIT_INDEX &&
|
||||
|
||||
write_script .git/hooks/fsmonitor-test <<-\EOF &&
|
||||
printf "last_update_token\0"
|
||||
EOF
|
||||
git -C full config core.fsmonitor ../.git/hooks/fsmonitor-test &&
|
||||
git -C sparse config core.fsmonitor ../.git/hooks/fsmonitor-test &&
|
||||
check_sparse_index_behavior ! &&
|
||||
git clone . full &&
|
||||
git clone --sparse . sparse &&
|
||||
git -C sparse sparse-checkout init --cone --sparse-index &&
|
||||
git -C sparse sparse-checkout set dir1 dir2 &&
|
||||
|
||||
write_script .git/hooks/fsmonitor-test <<-\EOF &&
|
||||
printf "last_update_token\0"
|
||||
printf "dir1/modified\0"
|
||||
EOF
|
||||
check_sparse_index_behavior ! &&
|
||||
write_script .git/hooks/fsmonitor-test <<-\EOF &&
|
||||
printf "last_update_token\0"
|
||||
EOF
|
||||
git -C full config core.fsmonitor ../.git/hooks/fsmonitor-test &&
|
||||
git -C sparse config core.fsmonitor ../.git/hooks/fsmonitor-test &&
|
||||
check_sparse_index_behavior ! &&
|
||||
|
||||
git -C sparse sparse-checkout add dir1a &&
|
||||
write_script .git/hooks/fsmonitor-test <<-\EOF &&
|
||||
printf "last_update_token\0"
|
||||
printf "dir1/modified\0"
|
||||
EOF
|
||||
check_sparse_index_behavior ! &&
|
||||
|
||||
for repo in full sparse
|
||||
do
|
||||
cp -r $repo/dir1 $repo/dir1a &&
|
||||
git -C $repo add dir1a &&
|
||||
git -C $repo commit -m "add dir1a" || return 1
|
||||
done &&
|
||||
git -C sparse sparse-checkout set dir1 dir2 &&
|
||||
git -C sparse sparse-checkout add dir1a &&
|
||||
|
||||
# This one modifies outside the sparse-checkout definition
|
||||
# and hence we expect to expand the sparse-index.
|
||||
write_script .git/hooks/fsmonitor-test <<-\EOF &&
|
||||
printf "last_update_token\0"
|
||||
printf "dir1a/modified\0"
|
||||
EOF
|
||||
check_sparse_index_behavior
|
||||
for repo in full sparse
|
||||
do
|
||||
cp -r $repo/dir1 $repo/dir1a &&
|
||||
git -C $repo add dir1a &&
|
||||
git -C $repo commit -m "add dir1a" || return 1
|
||||
done &&
|
||||
git -C sparse sparse-checkout set dir1 dir2 &&
|
||||
|
||||
# This one modifies outside the sparse-checkout definition
|
||||
# and hence we expect to expand the sparse-index.
|
||||
write_script .git/hooks/fsmonitor-test <<-\EOF &&
|
||||
printf "last_update_token\0"
|
||||
printf "dir1a/modified\0"
|
||||
EOF
|
||||
check_sparse_index_behavior
|
||||
)
|
||||
'
|
||||
|
||||
test_done
|
||||
|
|
Loading…
Reference in a new issue