git/t/t4213-log-tabexpand.sh
Ævar Arnfjörð Bjarmason 03267e8656 commit: discard partial cache before (re-)reading it
The read_cache() in prepare_to_commit() would end up clobbering the
pointer we had for a previously populated "the_index.cache_tree" in
the very common case of "git commit" stressed by e.g. the tests being
changed here.

We'd populate "the_index.cache_tree" by calling
"update_main_cache_tree" in prepare_index(), but would not end up with
a "fully prepared" index. What constitutes an existing index is
clearly overly fuzzy, here we'll check "active_nr" (aka
"the_index.cache_nr"), but our "the_index.cache_tree" might have been
malloc()'d already.

Thus the code added in 11c8a74a64 (commit: write cache-tree data when
writing index anyway, 2011-12-06) would end up allocating the
"cache_tree", and would interact here with code added in
7168624c35 (Do not generate full commit log message if it is not
going to be used, 2007-11-28). The result was a very common memory
leak.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
2022-11-21 12:32:48 +09:00

106 lines
2.2 KiB
Bash
Executable file

#!/bin/sh
test_description='log/show --expand-tabs'
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
HT=" "
title='tab indent at the beginning of the title line'
body='tab indent on a line in the body'
# usage: count_expand $indent $numSP $numHT @format_args
count_expand ()
{
expect=
count=$(( $1 + $2 )) ;# expected spaces
while test $count -gt 0
do
expect="$expect "
count=$(( $count - 1 ))
done
shift 2
count=$1 ;# expected tabs
while test $count -gt 0
do
expect="$expect$HT"
count=$(( $count - 1 ))
done
shift
# The remainder of the command line is "git show -s" options
case " $* " in
*' --pretty=short '*)
line=$title ;;
*)
line=$body ;;
esac
# Prefix the output with the command line arguments, and
# replace SP with a dot both in the expected and actual output
# so that test_cmp would show the difference together with the
# breakage in a way easier to consume by the debugging user.
{
echo "git show -s $*"
echo "$expect$line"
} | sed -e 's/ /./g' >expect
{
echo "git show -s $*"
git show -s "$@" |
sed -n -e "/$line\$/p"
} | sed -e 's/ /./g' >actual
test_cmp expect actual
}
test_expand ()
{
fmt=$1
case "$fmt" in
*=raw | *=short | *=email)
default="0 1" ;;
*)
default="8 0" ;;
esac
case "$fmt" in
*=email)
in=0 ;;
*)
in=4 ;;
esac
test_expect_success "expand/no-expand${fmt:+ for $fmt}" '
count_expand $in $default $fmt &&
count_expand $in 8 0 $fmt --expand-tabs &&
count_expand $in 8 0 --expand-tabs $fmt &&
count_expand $in 8 0 $fmt --expand-tabs=8 &&
count_expand $in 8 0 --expand-tabs=8 $fmt &&
count_expand $in 0 1 $fmt --no-expand-tabs &&
count_expand $in 0 1 --no-expand-tabs $fmt &&
count_expand $in 0 1 $fmt --expand-tabs=0 &&
count_expand $in 0 1 --expand-tabs=0 $fmt &&
count_expand $in 4 0 $fmt --expand-tabs=4 &&
count_expand $in 4 0 --expand-tabs=4 $fmt
'
}
test_expect_success 'setup' '
test_tick &&
sed -e "s/Q/$HT/g" <<-EOF >msg &&
Q$title
Q$body
EOF
git commit --allow-empty -F msg
'
test_expand ""
test_expand --pretty
test_expand --pretty=short
test_expand --pretty=medium
test_expand --pretty=full
test_expand --pretty=fuller
test_expand --pretty=raw
test_expand --pretty=email
test_done