From: "Kristoffer Haugsbakk" <code@khaugsbakk.name>
To: "Jeff King" <peff@peff.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 5/6] format-patch: return an allocated string from log_write_email_headers()
Date: Fri, 22 Mar 2024 23:06:53 +0100 [thread overview]
Message-ID: <c94e0ba2-87b9-4272-afce-67f5faf0275f@app.fastmail.com> (raw)
In-Reply-To: <20240320003533.GE904136@coredump.intra.peff.net>
On Wed, Mar 20, 2024, at 01:35, Jeff King wrote:
> 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>
Good presentation of motivation here.
> ---
> I don't think the extra allocation is a big deal, but if we do, there
> are some other options:
>
> - instead of an out-pointer we could take a strbuf, and the caller
> could reset and reuse a strbuf for each commit
>
> - the after_subject stuff could become a callback; we discussed this a
> long time ago (I had no recollection of the thread until finding it
> in the archive just now):
>
>
> https://lore.kernel.org/git/20170325211149.yyvocmdfw4zbjyoi@sigill.intra.peff.net/
>
> - this log_write_email_headers() function prints part of its output to
> stdout, and shoves part of it into the after_subject field to be
> shown by the pretty-printer. I wonder if it could just format the
> subject itself (though that would make "rev-list --format=email"
> even more awkward, I guess).
I don’t quite understand all of these alternatives but the first one
makes sense. Leave the responsibility to the caller. That could work.
--
Kristoffer Haugsbakk
next prev parent reply other threads:[~2024-03-22 22:07 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-07 19:59 [PATCH 0/3] format-patch: teach `--header-cmd` Kristoffer Haugsbakk
2024-03-07 19:59 ` [PATCH 1/3] log-tree: take ownership of pointer Kristoffer Haugsbakk
2024-03-12 9:29 ` Jeff King
2024-03-12 17:43 ` Kristoffer Haugsbakk
2024-03-13 6:54 ` Jeff King
2024-03-13 17:49 ` Kristoffer Haugsbakk
2024-03-07 19:59 ` [PATCH 2/3] format-patch: teach `--header-cmd` Kristoffer Haugsbakk
2024-03-08 18:30 ` Kristoffer Haugsbakk
2024-03-11 21:29 ` Jean-Noël Avila
2024-03-12 8:13 ` Kristoffer Haugsbakk
2024-03-07 19:59 ` [PATCH 3/3] format-patch: check if header output looks valid Kristoffer Haugsbakk
2024-03-19 18:35 ` [PATCH v2 0/3] format-patch: teach `--header-cmd` Kristoffer Haugsbakk
2024-03-19 18:35 ` [PATCH v2 1/3] revision: add a per-email field to rev-info Kristoffer Haugsbakk
2024-03-19 21:29 ` Jeff King
2024-03-19 21:41 ` Kristoffer Haugsbakk
2024-03-20 0:25 ` Jeff King
2024-03-20 0:27 ` [PATCH 1/6] shortlog: stop setting pp.print_email_subject Jeff King
2024-03-20 0:28 ` [PATCH 2/6] pretty: split oneline and email subject printing Jeff King
2024-03-22 22:00 ` Kristoffer Haugsbakk
2024-03-20 0:30 ` [PATCH 3/6] pretty: drop print_email_subject flag Jeff King
2024-03-20 0:31 ` [PATCH 4/6] log: do not set up extra_headers for non-email formats Jeff King
2024-03-22 22:04 ` Kristoffer Haugsbakk
2024-03-20 0:35 ` [PATCH 5/6] format-patch: return an allocated string from log_write_email_headers() Jeff King
2024-03-22 22:06 ` Kristoffer Haugsbakk [this message]
2024-03-20 0:35 ` [PATCH 6/6] format-patch: simplify after-subject MIME header handling Jeff King
2024-03-22 22:08 ` Kristoffer Haugsbakk
2024-03-20 0:43 ` [PATCH v2 1/3] revision: add a per-email field to rev-info Jeff King
2024-03-22 22:31 ` Kristoffer Haugsbakk
2024-03-22 9:59 ` [PATCH 7/6] format-patch: fix leak of empty header string Jeff King
2024-03-22 10:03 ` Kristoffer Haugsbakk
2024-03-22 16:50 ` Junio C Hamano
2024-03-22 22:16 ` Kristoffer Haugsbakk
2024-03-19 18:35 ` [PATCH v2 2/3] format-patch: teach `--header-cmd` Kristoffer Haugsbakk
2024-03-19 18:35 ` [PATCH v2 3/3] format-patch: check if header output looks valid Kristoffer Haugsbakk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c94e0ba2-87b9-4272-afce-67f5faf0275f@app.fastmail.com \
--to=code@khaugsbakk.name \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).