]> git.ipfire.org Git - thirdparty/git.git/commit
format-patch: return an allocated string from log_write_email_headers()
authorJeff King <peff@peff.net>
Wed, 20 Mar 2024 00:35:33 +0000 (20:35 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 20 Mar 2024 00:54:16 +0000 (17:54 -0700)
commit305a68143cc0e9b714d71417efa9f0162dd07221
tree0ccc59a20ce1c784df5d6f2c3c1be90b5784c7c8
parent82363d967042ca2884b087b0895bbc566704388e
format-patch: return an allocated string from log_write_email_headers()

When pretty-printing a commit in the email format, we have to fill in
the "after subject" field of the pretty_print_context with any extra
headers the user provided (e.g., from "--to" or "--cc" options) plus any
special MIME headers.

We return an out-pointer that sometimes points to a newly heap-allocated
string and sometimes not. To avoid leaking, we store the allocated
version in a buffer with static lifetime, which is ugly. Worse, as we
extend the header feature, we'll end up having to repeat this ugly
pattern.

Instead, let's have our out-pointer pass ownership back to the caller,
and duplicate the string when necessary. This does mean one extra
allocation per commit when you use extra headers, but in the context of
format-patch which is showing diffs, I don't think that's even
measurable.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/log.c
log-tree.c
log-tree.h
pretty.h