builtin/mv: refactor `add_slash()` to always return allocated strings
commit3d231f7b8236787252cb336878e3ace75c1df545
authorPatrick Steinhardt <ps@pks.im>
Mon, 27 May 2024 11:47:09 +0000 (27 13:47 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 27 May 2024 18:20:02 +0000 (27 11:20 -0700)
tree1036a446d15bc320dd6d6ed1669362ceab2bd0d8
parent11ce77b5cc04e2a42b98f0f9f42d367f50f3b1fc
builtin/mv: refactor `add_slash()` to always return allocated strings

The `add_slash()` function will only conditionally return an allocated
string when the passed-in string did not yet have a trailing slash. This
makes the memory ownership harder to track than really necessary.

It's dubious whether this optimization really buys us all that much. The
number of times we execute this function is bounded by the number of
arguments to git-mv(1), so in the typical case we may end up saving an
allocation or two.

Simplify the code to unconditionally return allocated strings.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/mv.c