mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
The "seq" tool has a "-f" option to produce printf-style formatted
lines. Let's teach our test_seq helper the same trick. This lets us get
rid of some shell loops in test snippets (which are particularly verbose
in our test suite because we have to "|| return 1" to keep the &&-chain
going).
This converts a few call-sites I found by grepping around the test
suite. A few notes on these:
- In "seq", the format specifier is a "%g" float. Since test_seq only
supports integers, I've kept the more natural "%d" (which is what
these call sites were using already).
- Like "seq", test_seq automatically adds a newline to the specified
format. This is what all callers are doing already except for t0021,
but there we do not care about the exact format. We are just trying
to printf a large number of bytes to a file. It's not worth
complicating other callers or adding an option to avoid the newline
in that caller.
- Most conversions are just replacing a shell loop (which does get rid
of an extra fork, since $() requires a subshell). In t0612 we can
replace an awk invocation, which I think makes the end result more
readable, as there's less quoting.
- In t7422 we can replace one loop, but sadly we have to leave the
loop directly above it. This is because that earlier loop wants to
include the seq value twice in the output, which test_seq does not
support (nor does regular seq). If you run:
test_seq -f "foo-%d %d" 10
the second "%d" will always be the empty string. You might naively
think that test_seq could add some extra arguments, like:
# 3 ought to be enough for anyone...
printf "$fmt\n" "$i "$i" $i"
but that just triggers printf to format multiple lines, one per
extra set of arguments.
So we'd have to actually parse the format string, figure out how
many "%" placeholders are there, and then feed it that many
instances of the sequence number. The complexity isn't worth it.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
130 lines
2.7 KiB
Bash
Executable File
130 lines
2.7 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
test_description='reftables are compatible with JGit'
|
|
|
|
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
|
|
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
|
GIT_TEST_DEFAULT_REF_FORMAT=reftable
|
|
export GIT_TEST_DEFAULT_REF_FORMAT
|
|
|
|
# JGit does not support the 'link' DIRC extension.
|
|
GIT_TEST_SPLIT_INDEX=0
|
|
export GIT_TEST_SPLIT_INDEX
|
|
|
|
. ./test-lib.sh
|
|
|
|
if ! test_have_prereq JGIT
|
|
then
|
|
skip_all='skipping reftable JGit tests; JGit is not present in PATH'
|
|
test_done
|
|
fi
|
|
|
|
if ! test_have_prereq SHA1
|
|
then
|
|
skip_all='skipping reftable JGit tests; JGit does not support SHA256 reftables'
|
|
test_done
|
|
fi
|
|
|
|
test_commit_jgit () {
|
|
touch "$1" &&
|
|
jgit add "$1" &&
|
|
jgit commit -m "$1"
|
|
}
|
|
|
|
test_same_refs () {
|
|
git show-ref --head >cgit.actual &&
|
|
jgit show-ref >jgit-tabs.actual &&
|
|
tr "\t" " " <jgit-tabs.actual >jgit.actual &&
|
|
test_cmp cgit.actual jgit.actual
|
|
}
|
|
|
|
test_same_ref () {
|
|
git rev-parse "$1" >cgit.actual &&
|
|
jgit rev-parse "$1" >jgit.actual &&
|
|
test_cmp cgit.actual jgit.actual
|
|
}
|
|
|
|
test_same_reflog () {
|
|
git reflog "$*" >cgit.actual &&
|
|
jgit reflog "$*" >jgit-newline.actual &&
|
|
sed '/^$/d' <jgit-newline.actual >jgit.actual &&
|
|
test_cmp cgit.actual jgit.actual
|
|
}
|
|
|
|
test_expect_success 'CGit repository can be read by JGit' '
|
|
test_when_finished "rm -rf repo" &&
|
|
git init repo &&
|
|
(
|
|
cd repo &&
|
|
test_commit A &&
|
|
test_same_refs &&
|
|
test_same_ref HEAD &&
|
|
test_same_reflog HEAD
|
|
)
|
|
'
|
|
|
|
test_expect_success 'JGit repository can be read by CGit' '
|
|
test_when_finished "rm -rf repo" &&
|
|
jgit init repo &&
|
|
(
|
|
cd repo &&
|
|
|
|
touch file &&
|
|
jgit add file &&
|
|
jgit commit -m "initial commit" &&
|
|
|
|
# Note that we must convert the ref storage after we have
|
|
# written the default branch. Otherwise JGit will end up with
|
|
# no HEAD at all.
|
|
jgit convert-ref-storage --format=reftable &&
|
|
|
|
test_same_refs &&
|
|
test_same_ref HEAD &&
|
|
# Interestingly, JGit cannot read its own reflog here. CGit can
|
|
# though.
|
|
printf "%s HEAD@{0}: commit (initial): initial commit" "$(git rev-parse --short HEAD)" >expect &&
|
|
git reflog HEAD >actual &&
|
|
test_cmp expect actual
|
|
)
|
|
'
|
|
|
|
test_expect_success 'mixed writes from JGit and CGit' '
|
|
test_when_finished "rm -rf repo" &&
|
|
git init repo &&
|
|
(
|
|
cd repo &&
|
|
|
|
test_commit A &&
|
|
test_commit_jgit B &&
|
|
test_commit C &&
|
|
test_commit_jgit D &&
|
|
|
|
test_same_refs &&
|
|
test_same_ref HEAD &&
|
|
test_same_reflog HEAD
|
|
)
|
|
'
|
|
|
|
test_expect_success 'JGit can read multi-level index' '
|
|
test_when_finished "rm -rf repo" &&
|
|
git init repo &&
|
|
(
|
|
cd repo &&
|
|
|
|
test_commit A &&
|
|
{
|
|
echo start &&
|
|
test_seq -f "create refs/heads/branch-%d HEAD" 10000 &&
|
|
echo commit
|
|
} >input &&
|
|
git update-ref --stdin <input &&
|
|
|
|
test_same_refs &&
|
|
test_same_ref refs/heads/branch-1 &&
|
|
test_same_ref refs/heads/branch-5738 &&
|
|
test_same_ref refs/heads/branch-9999
|
|
)
|
|
'
|
|
|
|
test_done
|