git/t/t1419-exclude-refs.sh
Patrick Steinhardt 61e1c560bc t1419: mark test suite as files-backend specific
With 59c35fac54 (refs/packed-backend.c: implement jump lists to avoid
excluded pattern(s), 2023-07-10) we have implemented logic to handle
excluded refs more efficiently in the "packed" ref backend. This logic
allows us to skip emitting refs completely which we know to not be of
any interest to the caller, which can avoid quite some allocations and
object lookups.

This was wired up via a new `exclude_patterns` parameter passed to the
backend's ref iterator. The backend only needs to handle them on a best
effort basis though, and in fact we only handle it for the "packed-refs"
file, but not for loose references. Consequently, all callers must still
filter emitted refs with those exclude patterns.

The result is that handling exclude patterns is completely optional in
the ref backend, and any future backends may or may not implement it.
Let's thus mark the test for t1419 to depend on the REFFILES prereq.

An alternative would be to introduce a new prereq that tells us whether
the backend under test supports exclude patterns or not. But this does
feel a bit overblown:

  - It would either map to the REFFILES prereq, in which case it feels
    overengineered because the prereq is only ever relevant to t1419.

  - Otherwise, it could auto-detect whether the backend supports exclude
    patterns. But this could lead to silent failures in case the support
    for this feature breaks at any point in time.

It should thus be good enough to just use the REFFILES prereq for now.
If future backends ever grow support for exclude patterns we can easily
add their respective prereq as another condition for this test suite to
execute.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Reviewed-by: Christian Couder <christian.couder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-01-29 13:54:33 -08:00

129 lines
3.1 KiB
Bash
Executable file

#!/bin/sh
test_description='test exclude_patterns functionality in main ref store'
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
if test_have_prereq !REFFILES
then
skip_all='skipping `git for-each-ref --exclude` tests; need files backend'
test_done
fi
for_each_ref__exclude () {
GIT_TRACE2_PERF=1 test-tool ref-store main \
for-each-ref--exclude "$@" >actual.raw
cut -d ' ' -f 2 actual.raw
}
for_each_ref () {
git for-each-ref --format='%(refname)' "$@"
}
assert_jumps () {
local nr="$1"
local trace="$2"
grep -q "name:jumps_made value:$nr$" $trace
}
assert_no_jumps () {
! assert_jumps ".*" "$1"
}
test_expect_success 'setup' '
test_commit --no-tag base &&
base="$(git rev-parse HEAD)" &&
for name in foo bar baz quux
do
for i in 1 2 3
do
echo "create refs/heads/$name/$i $base" || return 1
done || return 1
done >in &&
echo "delete refs/heads/main" >>in &&
git update-ref --stdin <in &&
git pack-refs --all
'
test_expect_success 'excluded region in middle' '
for_each_ref__exclude refs/heads refs/heads/foo >actual 2>perf &&
for_each_ref refs/heads/bar refs/heads/baz refs/heads/quux >expect &&
test_cmp expect actual &&
assert_jumps 1 perf
'
test_expect_success 'excluded region at beginning' '
for_each_ref__exclude refs/heads refs/heads/bar >actual 2>perf &&
for_each_ref refs/heads/baz refs/heads/foo refs/heads/quux >expect &&
test_cmp expect actual &&
assert_jumps 1 perf
'
test_expect_success 'excluded region at end' '
for_each_ref__exclude refs/heads refs/heads/quux >actual 2>perf &&
for_each_ref refs/heads/foo refs/heads/bar refs/heads/baz >expect &&
test_cmp expect actual &&
assert_jumps 1 perf
'
test_expect_success 'disjoint excluded regions' '
for_each_ref__exclude refs/heads refs/heads/bar refs/heads/quux >actual 2>perf &&
for_each_ref refs/heads/baz refs/heads/foo >expect &&
test_cmp expect actual &&
assert_jumps 2 perf
'
test_expect_success 'adjacent, non-overlapping excluded regions' '
for_each_ref__exclude refs/heads refs/heads/bar refs/heads/baz >actual 2>perf &&
for_each_ref refs/heads/foo refs/heads/quux >expect &&
test_cmp expect actual &&
assert_jumps 1 perf
'
test_expect_success 'overlapping excluded regions' '
for_each_ref__exclude refs/heads refs/heads/ba refs/heads/baz >actual 2>perf &&
for_each_ref refs/heads/foo refs/heads/quux >expect &&
test_cmp expect actual &&
assert_jumps 1 perf
'
test_expect_success 'several overlapping excluded regions' '
for_each_ref__exclude refs/heads \
refs/heads/bar refs/heads/baz refs/heads/foo >actual 2>perf &&
for_each_ref refs/heads/quux >expect &&
test_cmp expect actual &&
assert_jumps 1 perf
'
test_expect_success 'non-matching excluded section' '
for_each_ref__exclude refs/heads refs/heads/does/not/exist >actual 2>perf &&
for_each_ref >expect &&
test_cmp expect actual &&
assert_no_jumps perf
'
test_expect_success 'meta-characters are discarded' '
for_each_ref__exclude refs/heads "refs/heads/ba*" >actual 2>perf &&
for_each_ref >expect &&
test_cmp expect actual &&
assert_no_jumps perf
'
test_done