Use the after_subject member of struct pretty_print_context to pass the
extra_headers unchanged, and construct and add the MIME boundary headers
directly in pretty.c::pp_title_line() instead of writing both to a
static buffer in log-tree.c::log_write_email_headers() first.  That's
easier, quicker and gets rid of said static buffer.

Signed-off-by: Rene Scharfe <l....@web.de>
---
 builtin/log.c |  3 ++-
 log-tree.c    | 26 ++------------------------
 log-tree.h    |  1 -
 pretty.c      | 15 +++++++++++++++
 4 files changed, 19 insertions(+), 26 deletions(-)

diff --git a/builtin/log.c b/builtin/log.c
index 281af8c1ec..be564039c1 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -989,7 +989,8 @@ static void make_cover_letter(struct rev_info *rev, int 
use_stdout,
            open_next_file(NULL, rev->numbered_files ? NULL : "cover-letter", 
rev, quiet))
                return;
 
-       log_write_email_headers(rev, head, &pp.after_subject, &need_8bit_cte);
+       log_write_email_headers(rev, head, &need_8bit_cte);
+       pp.after_subject = rev->extra_headers;
 
        for (i = 0; !need_8bit_cte && i < nr; i++) {
                const char *buf = get_commit_buffer(list[i], NULL);
diff --git a/log-tree.c b/log-tree.c
index 4618dd04ca..7049a17781 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -349,10 +349,8 @@ void fmt_output_email_subject(struct strbuf *sb, struct 
rev_info *opt)
 }
 
 void log_write_email_headers(struct rev_info *opt, struct commit *commit,
-                            const char **extra_headers_p,
                             int *need_8bit_cte_p)
 {
-       const char *extra_headers = opt->extra_headers;
        const char *name = oid_to_hex(opt->zero_commit ?
                                      &null_oid : &commit->object.oid);
 
@@ -374,26 +372,9 @@ void log_write_email_headers(struct rev_info *opt, struct 
commit *commit,
                graph_show_oneline(opt->graph);
        }
        if (opt->mime_boundary) {
-               static char subject_buffer[1024];
                static char buffer[1024];
                struct strbuf filename =  STRBUF_INIT;
                *need_8bit_cte_p = -1; /* NEVER */
-               snprintf(subject_buffer, sizeof(subject_buffer) - 1,
-                        "%s"
-                        "MIME-Version: 1.0\n"
-                        "Content-Type: multipart/mixed;"
-                        " boundary=\"%s%s\"\n"
-                        "\n"
-                        "This is a multi-part message in MIME "
-                        "format.\n"
-                        "--%s%s\n"
-                        "Content-Type: text/plain; "
-                        "charset=UTF-8; format=fixed\n"
-                        "Content-Transfer-Encoding: 8bit\n\n",
-                        extra_headers ? extra_headers : "",
-                        mime_boundary_leader, opt->mime_boundary,
-                        mime_boundary_leader, opt->mime_boundary);
-               extra_headers = subject_buffer;
 
                if (opt->numbered_files)
                        strbuf_addf(&filename, "%d", opt->nr);
@@ -413,7 +394,6 @@ void log_write_email_headers(struct rev_info *opt, struct 
commit *commit,
                opt->diffopt.stat_sep = buffer;
                strbuf_release(&filename);
        }
-       *extra_headers_p = extra_headers;
 }
 
 static void show_sig_lines(struct rev_info *opt, int status, const char *bol)
@@ -537,7 +517,6 @@ void show_log(struct rev_info *opt)
        struct log_info *log = opt->loginfo;
        struct commit *commit = log->commit, *parent = log->parent;
        int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40;
-       const char *extra_headers = opt->extra_headers;
        struct pretty_print_context ctx = {0};
 
        opt->loginfo = NULL;
@@ -597,8 +576,7 @@ void show_log(struct rev_info *opt)
         */
 
        if (cmit_fmt_is_mail(opt->commit_format)) {
-               log_write_email_headers(opt, commit, &extra_headers,
-                                       &ctx.need_8bit_cte);
+               log_write_email_headers(opt, commit, &ctx.need_8bit_cte);
                ctx.rev = opt;
                ctx.print_email_subject = 1;
        } else if (opt->commit_format != CMIT_FMT_USERFORMAT) {
@@ -672,7 +650,7 @@ void show_log(struct rev_info *opt)
        ctx.date_mode = opt->date_mode;
        ctx.date_mode_explicit = opt->date_mode_explicit;
        ctx.abbrev = opt->diffopt.abbrev;
-       ctx.after_subject = extra_headers;
+       ctx.after_subject = opt->extra_headers;
        ctx.preserve_subject = opt->preserve_subject;
        ctx.reflog_info = opt->reflog_info;
        ctx.fmt = opt->commit_format;
diff --git a/log-tree.h b/log-tree.h
index 48f11fb740..7f9c4f22b5 100644
--- a/log-tree.h
+++ b/log-tree.h
@@ -22,7 +22,6 @@ void format_decorations_extended(struct strbuf *sb, const 
struct commit *commit,
                             format_decorations_extended((strbuf), (commit), 
(color), " (", ", ", ")")
 void show_decorations(struct rev_info *opt, struct commit *commit);
 void log_write_email_headers(struct rev_info *opt, struct commit *commit,
-                            const char **extra_headers_p,
                             int *need_8bit_cte_p);
 void load_ref_decorations(int flags);
 
diff --git a/pretty.c b/pretty.c
index d0f86f5d85..56e668781a 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1641,6 +1641,21 @@ void pp_title_line(struct pretty_print_context *pp,
        if (pp->after_subject) {
                strbuf_addstr(sb, pp->after_subject);
        }
+       if (pp->print_email_subject && pp->rev && pp->rev->mime_boundary) {
+               strbuf_addf(sb,
+                           "MIME-Version: 1.0\n"
+                           "Content-Type: multipart/mixed;"
+                           " boundary=\"%s%s\"\n"
+                           "\n"
+                           "This is a multi-part message in MIME "
+                           "format.\n"
+                           "--%s%s\n"
+                           "Content-Type: text/plain; "
+                           "charset=UTF-8; format=fixed\n"
+                           "Content-Transfer-Encoding: 8bit\n\n",
+                           mime_boundary_leader, pp->rev->mime_boundary,
+                           mime_boundary_leader, pp->rev->mime_boundary);
+       }
        if (cmit_fmt_is_mail(pp->fmt)) {
                strbuf_addch(sb, '\n');
        }
-- 
2.12.2

Reply via email to