git/t/t4126-apply-empty.sh
Ævar Arnfjörð Bjarmason f6bfea0ad0 revisions API users: use release_revisions() in builtin/log.c
In preparation for having the "log" family of functions make wider use
of release_revisions() let's have them call it just before
exiting. This changes the "log", "whatchanged", "show",
"format-patch", etc. commands, all of which live in this file.

The release_revisions() API still only frees the "pending" member, but
will learn to release more members of "struct rev_info" in subsequent
commits.

In the case of "format-patch" revert the addition of UNLEAK() in
dee839a263 (format-patch: mark rev_info with UNLEAK, 2021-12-16),
which will cause several tests that previously passed under
"TEST_PASSES_SANITIZE_LEAK=true" to start failing.

In subsequent commits we'll now be able to use those tests to check
whether that part of the API is really leaking memory, and will fix
all of those memory leaks. Removing the UNLEAK() allows us to make
incremental progress in that direction. See [1] for further details
about this approach.

Note that the release_revisions() will not be sufficient to deal with
the code in cmd_show() added in 5d7eeee2ac (git-show: grok blobs,
trees and tags, too, 2006-12-14) which clobbers the "pending" array in
the case of "OBJ_COMMIT". That will need to be dealt with by some
future follow-up work.

1. https://lore.kernel.org/git/220218.861r00ib86.gmgdl@evledraar.gmail.com/

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-04-13 23:56:09 -07:00

68 lines
1.5 KiB
Bash
Executable file

#!/bin/sh
test_description='apply empty'
. ./test-lib.sh
test_expect_success setup '
>empty &&
git add empty &&
test_tick &&
git commit -m initial &&
git commit --allow-empty -m "empty commit" &&
git format-patch --always HEAD~ >empty.patch &&
test_write_lines a b c d e >empty &&
cat empty >expect &&
git diff |
sed -e "/^diff --git/d" \
-e "/^index /d" \
-e "s|a/empty|empty.orig|" \
-e "s|b/empty|empty|" >patch0 &&
sed -e "s|empty|missing|" patch0 >patch1 &&
>empty &&
git update-index --refresh
'
test_expect_success 'apply empty' '
rm -f missing &&
test_when_finished "git reset --hard" &&
git apply patch0 &&
test_cmp expect empty
'
test_expect_success 'apply empty patch fails' '
test_when_finished "git reset --hard" &&
test_must_fail git apply empty.patch &&
test_must_fail git apply - </dev/null
'
test_expect_success 'apply with --allow-empty succeeds' '
test_when_finished "git reset --hard" &&
git apply --allow-empty empty.patch &&
git apply --allow-empty - </dev/null
'
test_expect_success 'apply --index empty' '
rm -f missing &&
test_when_finished "git reset --hard" &&
git apply --index patch0 &&
test_cmp expect empty &&
git diff --exit-code
'
test_expect_success 'apply create' '
rm -f missing &&
test_when_finished "git reset --hard" &&
git apply patch1 &&
test_cmp expect missing
'
test_expect_success 'apply --index create' '
rm -f missing &&
test_when_finished "git reset --hard" &&
git apply --index patch1 &&
test_cmp expect missing &&
git diff --exit-code
'
test_done