diff options
| author | René Scharfe <l.s.r@web.de> | 2026-08-25 20:03:50 +0200 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2026-08-26 09:03:34 -0700 |
| commit | 2e8a9d94b009c69628e29bc7c50d9a3fc12e14ba (patch) | |
| tree | 16196e765cd3474c0120bfc5b09c90586ea2a30e /t/t4013/diff.diff_initial..side | |
| parent | a6de316efde124a132d38e50c6407477df47f9cd (diff) | |
worktree add: let worktree_basename() return string copy
worktree_basename() requires callers to do pointer arithmetic to get the
actual basename. Simplify them by doing the calculations in the
function and returning a copy of the basename directly.
Remind programmers to free the result by renaming the function to
worktree_basename_dup(). Among the three callers of the original
function, two immediately make copies of the returned string before
using and freeing it, which makes for an easy conversion. Convert
the other one from resetting a shared strbuf to freeing the
allocated string, which requires the same number of lines, but no
arithmetic. The added allocation is negligible because it's small
and there's only one per run of "git worktree add".
Signed-off-by: René Scharfe <l.s.r@web.de>
[jc: rephrased the second paragraph a bit.]
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t4013/diff.diff_initial..side')
0 files changed, 0 insertions, 0 deletions
