git/t/t3425-rebase-topology-merges.sh
Ævar Arnfjörð Bjarmason 9ff2f06069 sequencer API users: fix get_replay_opts() leaks
Make the replay_opts_release() function added in the preceding commit
non-static, and use it for freeing the "struct replay_opts"
constructed for "rebase" and "revert".

To safely call our new replay_opts_release() we'll need to stop
calling it in sequencer_remove_state(), and instead call it where we
allocate the "struct replay_opts" itself.

This is because in e.g. do_interactive_rebase() we construct a "struct
replay_opts" with "get_replay_opts()", and then call
"complete_action()". If we get far enough in that function without
encountering errors we'll call "pick_commits()" which (indirectly)
calls sequencer_remove_state() at the end.

But if we encounter errors anywhere along the way we'd punt out early,
and not free() the memory we allocated. Remembering whether we
previously called sequencer_remove_state() would be a hassle.

Using a FREE_AND_NULL() pattern would also work, as it would be safe
to call replay_opts_release() repeatedly. But let's fix this properly
instead, by having the owner of the data free() it.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-02-06 16:03:52 -08:00

111 lines
2.2 KiB
Bash
Executable file

#!/bin/sh
test_description='rebase topology tests with merges'
TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-rebase.sh
test_revision_subjects () {
expected="$1"
shift
set -- $(git log --format=%s --no-walk=unsorted "$@")
test "$expected" = "$*"
}
# a---b-----------c
# \ \
# d-------e \
# \ \ \
# n---o---w---v
# \
# z
test_expect_success 'setup of non-linear-history' '
test_commit a &&
test_commit b &&
test_commit c &&
git checkout b &&
test_commit d &&
test_commit e &&
git checkout c &&
test_commit g &&
revert h g &&
git checkout d &&
cherry_pick gp g &&
test_commit i &&
git checkout b &&
test_commit f &&
git checkout d &&
test_commit n &&
test_commit o &&
test_merge w e &&
test_merge v c &&
git checkout o &&
test_commit z
'
test_run_rebase () {
result=$1
shift
test_expect_$result "rebase $* after merge from upstream" "
reset_rebase &&
git rebase $* e w &&
test_cmp_rev e HEAD~2 &&
test_linear_range 'n o' e..
"
}
test_run_rebase success --apply
test_run_rebase success -m
test_run_rebase success -i
test_run_rebase () {
result=$1
shift
expected=$1
shift
test_expect_$result "rebase $* of non-linear history is linearized in place" "
reset_rebase &&
git rebase $* d w &&
test_cmp_rev d HEAD~3 &&
test_linear_range "\'"$expected"\'" d..
"
}
test_run_rebase success 'n o e' --apply
test_run_rebase success 'n o e' -m
test_run_rebase success 'n o e' -i
test_run_rebase () {
result=$1
shift
expected=$1
shift
test_expect_$result "rebase $* of non-linear history is linearized upstream" "
reset_rebase &&
git rebase $* c w &&
test_cmp_rev c HEAD~4 &&
test_linear_range "\'"$expected"\'" c..
"
}
test_run_rebase success 'd n o e' --apply
test_run_rebase success 'd n o e' -m
test_run_rebase success 'd n o e' -i
test_run_rebase () {
result=$1
shift
expected=$1
shift
test_expect_$result "rebase $* of non-linear history with merges after upstream merge is linearized" "
reset_rebase &&
git rebase $* c v &&
test_cmp_rev c HEAD~4 &&
test_linear_range "\'"$expected"\'" c..
"
}
test_run_rebase success 'd n o e' --apply
test_run_rebase success 'd n o e' -m
test_run_rebase success 'd n o e' -i
test_done