1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-09 04:26:08 +02:00
git/t/t5325-reverse-index.sh
Taylor Blau 9f7f10a282 t: invert `GIT_TEST_WRITE_REV_INDEX`
Back in e8c58f894b (t: support GIT_TEST_WRITE_REV_INDEX, 2021-01-25), we
added a test knob to conditionally enable writing a ".rev" file when
indexing a pack. At the time, this was used to ensure that the test
suite worked even when ".rev" files were written, which served as a
stress-test for the on-disk reverse index implementation.

Now that reading from on-disk ".rev" files is enabled by default, the
test knob `GIT_TEST_WRITE_REV_INDEX` no longer has any meaning.

We could get rid of the option entirely, but there would be no
convenient way to test Git when ".rev" files *aren't* in place.

Instead of getting rid of the option, invert its meaning to instead
disable writing ".rev" files, thereby running the test suite in a mode
where the reverse index is generated from scratch.

This ensures that, when GIT_TEST_NO_WRITE_REV_INDEX is set to some
spelling of "true", we are still running and exercising Git's behavior
when forced to generate reverse indexes from scratch. Do so by setting
it in the linux-TEST-vars CI run to ensure that we are maintaining good
coverage of this now-legacy code.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
Acked-by: Derrick Stolee <derrickstolee@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-04-13 07:55:46 -07:00

135 lines
3.4 KiB
Bash
Executable File

#!/bin/sh
test_description='on-disk reverse index'
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
# The below tests want control over the 'pack.writeReverseIndex' setting
# themselves to assert various combinations of it with other options.
sane_unset GIT_TEST_NO_WRITE_REV_INDEX
packdir=.git/objects/pack
test_expect_success 'setup' '
test_commit base &&
test_config pack.writeReverseIndex false &&
pack=$(git pack-objects --all $packdir/pack) &&
rev=$packdir/pack-$pack.rev &&
test_path_is_missing $rev
'
test_index_pack () {
rm -f $rev &&
conf=$1 &&
shift &&
# remove the index since Windows won't overwrite an existing file
rm $packdir/pack-$pack.idx &&
git -c pack.writeReverseIndex=$conf index-pack "$@" \
$packdir/pack-$pack.pack
}
test_expect_success 'index-pack with pack.writeReverseIndex' '
test_index_pack "" &&
test_path_is_missing $rev &&
test_index_pack false &&
test_path_is_missing $rev &&
test_index_pack true &&
test_path_is_file $rev
'
test_expect_success 'index-pack with --[no-]rev-index' '
for conf in "" true false
do
test_index_pack "$conf" --rev-index &&
test_path_exists $rev &&
test_index_pack "$conf" --no-rev-index &&
test_path_is_missing $rev || return 1
done
'
test_expect_success 'index-pack can verify reverse indexes' '
test_when_finished "rm -f $rev" &&
test_index_pack true &&
test_path_is_file $rev &&
git index-pack --rev-index --verify $packdir/pack-$pack.pack &&
# Intentionally corrupt the reverse index.
chmod u+w $rev &&
printf "xxxx" | dd of=$rev bs=1 count=4 conv=notrunc &&
test_must_fail git index-pack --rev-index --verify \
$packdir/pack-$pack.pack 2>err &&
grep "validation error" err
'
test_expect_success 'index-pack infers reverse index name with -o' '
git index-pack --rev-index -o other.idx $packdir/pack-$pack.pack &&
test_path_is_file other.idx &&
test_path_is_file other.rev
'
test_expect_success 'pack-objects respects pack.writeReverseIndex' '
test_when_finished "rm -fr pack-1-*" &&
git -c pack.writeReverseIndex= pack-objects --all pack-1 &&
test_path_is_missing pack-1-*.rev &&
git -c pack.writeReverseIndex=false pack-objects --all pack-1 &&
test_path_is_missing pack-1-*.rev &&
git -c pack.writeReverseIndex=true pack-objects --all pack-1 &&
test_path_is_file pack-1-*.rev
'
test_expect_success 'reverse index is not generated when available on disk' '
test_index_pack true &&
test_path_is_file $rev &&
git rev-parse HEAD >tip &&
GIT_TEST_REV_INDEX_DIE_IN_MEMORY=1 git cat-file \
--batch-check="%(objectsize:disk)" <tip
'
test_expect_success 'reverse index is ignored when pack.readReverseIndex is false' '
test_index_pack true &&
test_path_is_file $rev &&
test_config pack.readReverseIndex false &&
git rev-parse HEAD >tip &&
GIT_TEST_REV_INDEX_DIE_ON_DISK=1 git cat-file \
--batch-check="%(objectsize:disk)" <tip
'
test_expect_success 'revindex in-memory vs on-disk' '
git init repo &&
test_when_finished "rm -fr repo" &&
(
cd repo &&
test_commit commit &&
git rev-list --objects --no-object-names --all >objects &&
git -c pack.writeReverseIndex=false repack -ad &&
test_path_is_missing $packdir/pack-*.rev &&
git cat-file --batch-check="%(objectsize:disk) %(objectname)" \
<objects >in-core &&
git -c pack.writeReverseIndex=true repack -ad &&
test_path_is_file $packdir/pack-*.rev &&
git cat-file --batch-check="%(objectsize:disk) %(objectname)" \
<objects >on-disk &&
test_cmp on-disk in-core
)
'
test_done