format-patch: generate MIME header as needed even when there is format.header
Earlier, the callchain from pretty_print_commit() down to pp_title_line()
had an unwarranted assumption that the presense of "after_subject"
parameter, means the caller has already output MIME headers for
attachments. The parameter's primary purpose is to give extra header
lines the caller wants to place after pp_title_line() generates the
"Subject: " line.
This assumption does not hold when the user used the format.header
configuration variable to pass extra headers, and caused a message with
non-ASCII character to lack proper MIME headers (e.g. 8-bit CTE header).
The earlier logic also failed to suppress duplicated MIME headers when
"format-patch -s --attach" is asked for and the signer's name demanded
8-bit clean transport.
This patch fixes the logic by introducing a separate need_8bit_cte
parameter passed down the callchain. This can have one of these values:
-1 : we've already done MIME crap and we do not want to add extra header
to say this is 8bit in pp_title_line();
0 : we haven't done MIME and we have not seen anything that is 8bit yet;
1 : we haven't done MIME and we have seen something that is 8bit;
pp_title_line() must add MIME header.
It adds two tests by Jeff King who independently diagnosed this issue.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
@ -146,6 +146,7 @@ void show_log(struct rev_info *opt, const char *sep)
|
||||
int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40;
|
||||
const char *extra;
|
||||
const char *subject = NULL, *extra_headers = opt->extra_headers;
|
||||
int need_8bit_cte = 0;
|
||||
|
||||
opt->loginfo = NULL;
|
||||
if (!opt->verbose_header) {
|
||||
@ -214,6 +215,8 @@ void show_log(struct rev_info *opt, const char *sep)
|
||||
if (opt->mime_boundary) {
|
||||
static char subject_buffer[1024];
|
||||
static char buffer[1024];
|
||||
|
||||
need_8bit_cte = -1; /* never */
|
||||
snprintf(subject_buffer, sizeof(subject_buffer) - 1,
|
||||
"%s"
|
||||
"MIME-Version: 1.0\n"
|
||||
@ -282,9 +285,11 @@ void show_log(struct rev_info *opt, const char *sep)
|
||||
* And then the pretty-printed message itself
|
||||
*/
|
||||
strbuf_init(&msgbuf, 0);
|
||||
if (need_8bit_cte >= 0)
|
||||
need_8bit_cte = has_non_ascii(opt->add_signoff);
|
||||
pretty_print_commit(opt->commit_format, commit, &msgbuf,
|
||||
abbrev, subject, extra_headers, opt->date_mode,
|
||||
has_non_ascii(opt->add_signoff));
|
||||
need_8bit_cte);
|
||||
|
||||
if (opt->add_signoff)
|
||||
append_signoff(&msgbuf, opt->add_signoff);
|
||||
|
||||
Reference in New Issue
Block a user