]> git.ipfire.org Git - thirdparty/git.git/commit
builtin/mv: refactor to use `struct strvec`
authorPatrick Steinhardt <ps@pks.im>
Mon, 27 May 2024 11:47:18 +0000 (13:47 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 27 May 2024 18:20:02 +0000 (11:20 -0700)
commit52a7dab439e53d05adb9edc870c92a446e5a9143
treec520f44ceb27fc00369d9871033ae46e9e690213
parent9fcd9e4e72ff2ef2b96379d8caf03429fea279eb
builtin/mv: refactor to use `struct strvec`

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>
builtin/mv.c
t/t4001-diff-rename.sh
t/t4043-diff-rename-binary.sh
t/t4120-apply-popt.sh
t/t6400-merge-df.sh
t/t6412-merge-large-rename.sh
t/t6426-merge-skip-unneeded-updates.sh
t/t6429-merge-sequence-rename-caching.sh