mirror of
https://github.com/git/git
synced 2024-11-04 16:17:49 +00:00
52a7dab439
Memory allocation patterns in git-mv(1) are extremely hard to follow: We copy around string pointers into manually-managed arrays, some of which alias each other, but only sometimes, while we also drop some of those strings at other times without ever daring to free them. While this may be my own subjective feeling, it seems like others have given up as the code has multiple calls to `UNLEAK()`. These are not sufficient though, and git-mv(1) is still leaking all over the place even with them. Refactor the code to instead track strings in `struct strvec`. While this has the effect of effectively duplicating some of the strings without an actual need, it is way easier to reason about and fixes all of the aliasing of memory that has been going on. It allows us to get rid of the `UNLEAK()` calls and also fixes leaks that those calls did not paper over. Mark tests which are now leak-free accordingly. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
46 lines
875 B
Bash
Executable file
46 lines
875 B
Bash
Executable file
#!/bin/sh
|
|
#
|
|
# Copyright (c) 2010 Jakub Narebski, Christian Couder
|
|
#
|
|
|
|
test_description='Move a binary file'
|
|
|
|
TEST_PASSES_SANITIZE_LEAK=true
|
|
. ./test-lib.sh
|
|
|
|
|
|
test_expect_success 'prepare repository' '
|
|
git init &&
|
|
echo foo > foo &&
|
|
echo "barQ" | q_to_nul > bar &&
|
|
git add . &&
|
|
git commit -m "Initial commit"
|
|
'
|
|
|
|
test_expect_success 'move the files into a "sub" directory' '
|
|
mkdir sub &&
|
|
git mv bar foo sub/ &&
|
|
git commit -m "Moved to sub/"
|
|
'
|
|
|
|
cat > expected <<\EOF
|
|
- - bar => sub/bar
|
|
0 0 foo => sub/foo
|
|
|
|
diff --git a/bar b/sub/bar
|
|
similarity index 100%
|
|
rename from bar
|
|
rename to sub/bar
|
|
diff --git a/foo b/sub/foo
|
|
similarity index 100%
|
|
rename from foo
|
|
rename to sub/foo
|
|
EOF
|
|
|
|
test_expect_success 'git show -C -C report renames' '
|
|
git show -C -C --raw --binary --numstat >patch-with-stat &&
|
|
tail -n 11 patch-with-stat >current &&
|
|
test_cmp expected current
|
|
'
|
|
|
|
test_done
|