Skip to content
  • Jeff King's avatar
    format-patch: return an allocated string from log_write_email_headers() · 305a6814
    Jeff King authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    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: default avatarJeff King <peff@peff.net>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    305a6814