@@ -470,16 +470,19 @@ void fmt_output_email_subject(struct strbuf *sb, struct rev_info *opt)
470470}
471471
472472void log_write_email_headers (struct rev_info * opt , struct commit * commit ,
473- const char * * extra_headers_p ,
473+ char * * extra_headers_p ,
474474 int * need_8bit_cte_p ,
475475 int maybe_multipart )
476476{
477- const char * extra_headers = 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 && * 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,16 +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- static 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
504- strbuf_reset (& subject_buffer );
505506 strbuf_reset (& buffer );
506507
507- strbuf_addf (& subject_buffer ,
508- "%s"
508+ strbuf_addf (& headers ,
509509 "MIME-Version: 1.0\n"
510510 "Content-Type: multipart/mixed;"
511511 " boundary=\"%s%s\"\n"
@@ -516,10 +516,8 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
516516 "Content-Type: text/plain; "
517517 "charset=UTF-8; format=fixed\n"
518518 "Content-Transfer-Encoding: 8bit\n\n" ,
519- extra_headers ? extra_headers : "" ,
520519 mime_boundary_leader , opt -> mime_boundary ,
521520 mime_boundary_leader , opt -> mime_boundary );
522- extra_headers = subject_buffer .buf ;
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
545543static void show_sig_lines (struct rev_info * opt , int status , const char * bol )
@@ -678,7 +676,6 @@ void show_log(struct rev_info *opt)
678676 struct log_info * log = opt -> loginfo ;
679677 struct commit * commit = log -> commit , * parent = log -> parent ;
680678 int abbrev_commit = opt -> abbrev_commit ? opt -> abbrev : the_hash_algo -> hexsz ;
681- const char * extra_headers = opt -> extra_headers ;
682679 struct pretty_print_context ctx = {0 };
683680
684681 opt -> loginfo = NULL ;
@@ -739,10 +736,9 @@ void show_log(struct rev_info *opt)
739736 */
740737
741738 if (cmit_fmt_is_mail (opt -> commit_format )) {
742- log_write_email_headers (opt , commit , & extra_headers ,
739+ log_write_email_headers (opt , commit , & ctx . after_subject ,
743740 & ctx .need_8bit_cte , 1 );
744741 ctx .rev = opt ;
745- ctx .print_email_subject = 1 ;
746742 } else if (opt -> commit_format != CMIT_FMT_USERFORMAT ) {
747743 fputs (diff_get_color_opt (& opt -> diffopt , DIFF_COMMIT ), opt -> diffopt .file );
748744 if (opt -> commit_format != CMIT_FMT_ONELINE )
@@ -808,7 +804,6 @@ void show_log(struct rev_info *opt)
808804 ctx .date_mode = opt -> date_mode ;
809805 ctx .date_mode_explicit = opt -> date_mode_explicit ;
810806 ctx .abbrev = opt -> diffopt .abbrev ;
811- ctx .after_subject = extra_headers ;
812807 ctx .preserve_subject = opt -> preserve_subject ;
813808 ctx .encode_email_headers = opt -> encode_email_headers ;
814809 ctx .reflog_info = opt -> reflog_info ;
@@ -857,6 +852,7 @@ void show_log(struct rev_info *opt)
857852
858853 strbuf_release (& msgbuf );
859854 free (ctx .notes_message );
855+ free (ctx .after_subject );
860856
861857 if (cmit_fmt_is_mail (ctx .fmt ) && opt -> idiff_oid1 ) {
862858 struct diff_queue_struct dq ;
0 commit comments