Browse Source

Merge branch 'maint'

* maint:
  format-patch: generate MIME header as needed even when there is format.header
maint
Junio C Hamano 17 years ago
parent
commit
267123b429
  1. 6
      builtin-log.c
  2. 4
      commit.h
  3. 15
      log-tree.c
  4. 4
      log-tree.h
  5. 20
      pretty.c
  6. 10
      t/t4021-format-patch-signer-mime.sh
  7. 30
      t/t4028-format-patch-mime-headers.sh

6
builtin-log.c

@ -662,6 +662,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
int i; int i;
const char *encoding = "utf-8"; const char *encoding = "utf-8";
struct diff_options opts; struct diff_options opts;
int need_8bit_cte = 0;


if (rev->commit_format != CMIT_FMT_EMAIL) if (rev->commit_format != CMIT_FMT_EMAIL)
die("Cover letter needs email format"); die("Cover letter needs email format");
@ -672,7 +673,8 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,


head_sha1 = sha1_to_hex(head->object.sha1); head_sha1 = sha1_to_hex(head->object.sha1);


log_write_email_headers(rev, head_sha1, &subject_start, &extra_headers); log_write_email_headers(rev, head_sha1, &subject_start, &extra_headers,
&need_8bit_cte);


committer = git_committer_info(0); committer = git_committer_info(0);


@ -681,7 +683,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
pp_user_info(NULL, CMIT_FMT_EMAIL, &sb, committer, DATE_RFC2822, pp_user_info(NULL, CMIT_FMT_EMAIL, &sb, committer, DATE_RFC2822,
encoding); encoding);
pp_title_line(CMIT_FMT_EMAIL, &msg, &sb, subject_start, extra_headers, pp_title_line(CMIT_FMT_EMAIL, &msg, &sb, subject_start, extra_headers,
encoding, 0); encoding, need_8bit_cte);
pp_remainder(CMIT_FMT_EMAIL, &msg, &sb, 0); pp_remainder(CMIT_FMT_EMAIL, &msg, &sb, 0);
printf("%s\n", sb.buf); printf("%s\n", sb.buf);



4
commit.h

@ -70,7 +70,7 @@ extern void pretty_print_commit(enum cmit_fmt fmt, const struct commit*,
struct strbuf *, struct strbuf *,
int abbrev, const char *subject, int abbrev, const char *subject,
const char *after_subject, enum date_mode, const char *after_subject, enum date_mode,
int non_ascii_present); int need_8bit_cte);
void pp_user_info(const char *what, enum cmit_fmt fmt, struct strbuf *sb, void pp_user_info(const char *what, enum cmit_fmt fmt, struct strbuf *sb,
const char *line, enum date_mode dmode, const char *line, enum date_mode dmode,
const char *encoding); const char *encoding);
@ -80,7 +80,7 @@ void pp_title_line(enum cmit_fmt fmt,
const char *subject, const char *subject,
const char *after_subject, const char *after_subject,
const char *encoding, const char *encoding,
int plain_non_ascii); int need_8bit_cte);
void pp_remainder(enum cmit_fmt fmt, void pp_remainder(enum cmit_fmt fmt,
const char **msg_p, const char **msg_p,
struct strbuf *sb, struct strbuf *sb,

15
log-tree.c

@ -138,10 +138,14 @@ static int has_non_ascii(const char *s)
} }


void log_write_email_headers(struct rev_info *opt, const char *name, void log_write_email_headers(struct rev_info *opt, const char *name,
const char **subject_p, const char **extra_headers_p) const char **subject_p,
const char **extra_headers_p,
int *need_8bit_cte_p)
{ {
const char *subject = NULL; const char *subject = NULL;
const char *extra_headers = opt->extra_headers; const char *extra_headers = opt->extra_headers;

*need_8bit_cte_p = 0; /* unknown */
if (opt->total > 0) { if (opt->total > 0) {
static char buffer[64]; static char buffer[64];
snprintf(buffer, sizeof(buffer), snprintf(buffer, sizeof(buffer),
@ -169,6 +173,7 @@ void log_write_email_headers(struct rev_info *opt, const char *name,
if (opt->mime_boundary) { if (opt->mime_boundary) {
static char subject_buffer[1024]; static char subject_buffer[1024];
static char buffer[1024]; static char buffer[1024];
*need_8bit_cte_p = -1; /* NEVER */
snprintf(subject_buffer, sizeof(subject_buffer) - 1, snprintf(subject_buffer, sizeof(subject_buffer) - 1,
"%s" "%s"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
@ -212,6 +217,7 @@ void show_log(struct rev_info *opt, const char *sep)
int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40; int abbrev_commit = opt->abbrev_commit ? opt->abbrev : 40;
const char *extra; const char *extra;
const char *subject = NULL, *extra_headers = opt->extra_headers; const char *subject = NULL, *extra_headers = opt->extra_headers;
int need_8bit_cte = 0;


opt->loginfo = NULL; opt->loginfo = NULL;
if (!opt->verbose_header) { if (!opt->verbose_header) {
@ -255,7 +261,8 @@ void show_log(struct rev_info *opt, const char *sep)


if (opt->commit_format == CMIT_FMT_EMAIL) { if (opt->commit_format == CMIT_FMT_EMAIL) {
log_write_email_headers(opt, sha1_to_hex(commit->object.sha1), log_write_email_headers(opt, sha1_to_hex(commit->object.sha1),
&subject, &extra_headers); &subject, &extra_headers,
&need_8bit_cte);
} else if (opt->commit_format != CMIT_FMT_USERFORMAT) { } else if (opt->commit_format != CMIT_FMT_USERFORMAT) {
fputs(diff_get_color_opt(&opt->diffopt, DIFF_COMMIT), stdout); fputs(diff_get_color_opt(&opt->diffopt, DIFF_COMMIT), stdout);
if (opt->commit_format != CMIT_FMT_ONELINE) if (opt->commit_format != CMIT_FMT_ONELINE)
@ -299,9 +306,11 @@ void show_log(struct rev_info *opt, const char *sep)
* And then the pretty-printed message itself * And then the pretty-printed message itself
*/ */
strbuf_init(&msgbuf, 0); 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, pretty_print_commit(opt->commit_format, commit, &msgbuf,
abbrev, subject, extra_headers, opt->date_mode, abbrev, subject, extra_headers, opt->date_mode,
has_non_ascii(opt->add_signoff)); need_8bit_cte);


if (opt->add_signoff) if (opt->add_signoff)
append_signoff(&msgbuf, opt->add_signoff); append_signoff(&msgbuf, opt->add_signoff);

4
log-tree.h

@ -14,6 +14,8 @@ int log_tree_opt_parse(struct rev_info *, const char **, int);
void show_log(struct rev_info *opt, const char *sep); void show_log(struct rev_info *opt, const char *sep);
void show_decorations(struct commit *commit); void show_decorations(struct commit *commit);
void log_write_email_headers(struct rev_info *opt, const char *name, void log_write_email_headers(struct rev_info *opt, const char *name,
const char **subject_p, const char **extra_headers_p); const char **subject_p,
const char **extra_headers_p,
int *need_8bit_cte_p);


#endif #endif

20
pretty.c

@ -636,7 +636,7 @@ void pp_title_line(enum cmit_fmt fmt,
const char *subject, const char *subject,
const char *after_subject, const char *after_subject,
const char *encoding, const char *encoding,
int plain_non_ascii) int need_8bit_cte)
{ {
struct strbuf title; struct strbuf title;


@ -669,7 +669,7 @@ void pp_title_line(enum cmit_fmt fmt,
} }
strbuf_addch(sb, '\n'); strbuf_addch(sb, '\n');


if (plain_non_ascii) { if (need_8bit_cte > 0) {
const char *header_fmt = const char *header_fmt =
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=%s\n" "Content-Type: text/plain; charset=%s\n"
@ -720,7 +720,7 @@ void pp_remainder(enum cmit_fmt fmt,
void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit, void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
struct strbuf *sb, int abbrev, struct strbuf *sb, int abbrev,
const char *subject, const char *after_subject, const char *subject, const char *after_subject,
enum date_mode dmode, int plain_non_ascii) enum date_mode dmode, int need_8bit_cte)
{ {
unsigned long beginning_of_body; unsigned long beginning_of_body;
int indent = 4; int indent = 4;
@ -746,13 +746,11 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
if (fmt == CMIT_FMT_ONELINE || fmt == CMIT_FMT_EMAIL) if (fmt == CMIT_FMT_ONELINE || fmt == CMIT_FMT_EMAIL)
indent = 0; indent = 0;


/* After-subject is used to pass in Content-Type: multipart /*
* MIME header; in that case we do not have to do the * We need to check and emit Content-type: to mark it
* plaintext content type even if the commit message has * as 8-bit if we haven't done so.
* non 7-bit ASCII character. Otherwise, check if we need
* to say this is not a 7-bit ASCII.
*/ */
if (fmt == CMIT_FMT_EMAIL && !after_subject) { if (fmt == CMIT_FMT_EMAIL && need_8bit_cte == 0) {
int i, ch, in_body; int i, ch, in_body;


for (in_body = i = 0; (ch = msg[i]); i++) { for (in_body = i = 0; (ch = msg[i]); i++) {
@ -765,7 +763,7 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
in_body = 1; in_body = 1;
} }
else if (non_ascii(ch)) { else if (non_ascii(ch)) {
plain_non_ascii = 1; need_8bit_cte = 1;
break; break;
} }
} }
@ -790,7 +788,7 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
/* These formats treat the title line specially. */ /* These formats treat the title line specially. */
if (fmt == CMIT_FMT_ONELINE || fmt == CMIT_FMT_EMAIL) if (fmt == CMIT_FMT_ONELINE || fmt == CMIT_FMT_EMAIL)
pp_title_line(fmt, &msg, sb, subject, pp_title_line(fmt, &msg, sb, subject,
after_subject, encoding, plain_non_ascii); after_subject, encoding, need_8bit_cte);


beginning_of_body = sb->len; beginning_of_body = sb->len;
if (fmt != CMIT_FMT_ONELINE) if (fmt != CMIT_FMT_ONELINE)

10
t/t4021-format-patch-signer-mime.sh

@ -32,11 +32,19 @@ test_expect_success 'format with signoff without funny signer name' '


test_expect_success 'format with non ASCII signer name' ' test_expect_success 'format with non ASCII signer name' '


GIT_COMMITTER_NAME="$B$O$^$N(B $B$U$K$*$&(B" \ GIT_COMMITTER_NAME="はまの ふにおう" \
git format-patch -s --stdout -1 >output && git format-patch -s --stdout -1 >output &&
grep Content-Type output grep Content-Type output


' '


test_expect_success 'attach and signoff do not duplicate mime headers' '

GIT_COMMITTER_NAME="はまの ふにおう" \
git format-patch -s --stdout -1 --attach >output &&
test `grep -ci ^MIME-Version: output` = 1

'

test_done test_done



30
t/t4028-format-patch-mime-headers.sh

@ -0,0 +1,30 @@
#!/bin/sh

test_description='format-patch mime headers and extra headers do not conflict'
. ./test-lib.sh

test_expect_success 'create commit with utf-8 body' '
echo content >file &&
git add file &&
git commit -m one &&
echo more >>file &&
git commit -a -m "two

utf-8 body: ñ"
'

test_expect_success 'patch has mime headers' '
rm -f 0001-two.patch &&
git format-patch HEAD^ &&
grep -i "content-type: text/plain; charset=utf-8" 0001-two.patch
'

test_expect_success 'patch has mime and extra headers' '
rm -f 0001-two.patch &&
git config format.headers "x-foo: bar" &&
git format-patch HEAD^ &&
grep -i "x-foo: bar" 0001-two.patch &&
grep -i "content-type: text/plain; charset=utf-8" 0001-two.patch
'

test_done
Loading…
Cancel
Save