Skip to content

Commit 838ba01

Browse files
peffgitster
authored andcommitted
format-patch: simplify after-subject MIME header handling
In log_write_email_headers(), we append our MIME headers to the set of extra headers by creating a new strbuf, adding the existing headers, and then adding our new ones. We had to do it this way when our output buffer might point to the constant opt->extra_headers variable. But since the previous commit, we always make a local copy of that variable. Let's turn that into a strbuf, which lets the MIME code simply append to it. That simplifies the function and avoids a pointless extra copy of the headers. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 305a681 commit 838ba01

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

log-tree.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -474,12 +474,15 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
474474
int *need_8bit_cte_p,
475475
int maybe_multipart)
476476
{
477-
char *extra_headers = xstrdup_or_null(opt->extra_headers);
477+
struct strbuf headers = STRBUF_INIT;
478478
const char *name = oid_to_hex(opt->zero_commit ?
479479
null_oid() : &commit->object.oid);
480480

481481
*need_8bit_cte_p = 0; /* unknown */
482482

483+
if (opt->extra_headers)
484+
strbuf_addstr(&headers, opt->extra_headers);
485+
483486
fprintf(opt->diffopt.file, "From %s Mon Sep 17 00:00:00 2001\n", name);
484487
graph_show_oneline(opt->graph);
485488
if (opt->message_id) {
@@ -496,15 +499,13 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
496499
graph_show_oneline(opt->graph);
497500
}
498501
if (opt->mime_boundary && maybe_multipart) {
499-
struct strbuf subject_buffer = STRBUF_INIT;
500502
static struct strbuf buffer = STRBUF_INIT;
501503
struct strbuf filename = STRBUF_INIT;
502504
*need_8bit_cte_p = -1; /* NEVER */
503505

504506
strbuf_reset(&buffer);
505507

506-
strbuf_addf(&subject_buffer,
507-
"%s"
508+
strbuf_addf(&headers,
508509
"MIME-Version: 1.0\n"
509510
"Content-Type: multipart/mixed;"
510511
" boundary=\"%s%s\"\n"
@@ -515,11 +516,8 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
515516
"Content-Type: text/plain; "
516517
"charset=UTF-8; format=fixed\n"
517518
"Content-Transfer-Encoding: 8bit\n\n",
518-
extra_headers ? extra_headers : "",
519519
mime_boundary_leader, opt->mime_boundary,
520520
mime_boundary_leader, opt->mime_boundary);
521-
free(extra_headers);
522-
extra_headers = strbuf_detach(&subject_buffer, NULL);
523521

524522
if (opt->numbered_files)
525523
strbuf_addf(&filename, "%d", opt->nr);
@@ -539,7 +537,7 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
539537
opt->diffopt.stat_sep = buffer.buf;
540538
strbuf_release(&filename);
541539
}
542-
*extra_headers_p = extra_headers;
540+
*extra_headers_p = headers.len ? strbuf_detach(&headers, NULL) : NULL;
543541
}
544542

545543
static void show_sig_lines(struct rev_info *opt, int status, const char *bol)

0 commit comments

Comments
 (0)