@matheusbsbs / matheus-bagliano / commits / c831da6647
Fork 0

builtin format-patch: squelch content-type for 7-bit ASCII

When --attach is not used, usually we do not say Content-Type: and fluff, but if the commit message is not 7-bit ASCII, mark it as "text/plain; charset=UTF-8". This unclutters output somewhat. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed May 21, 2006 at 23:55 UTC c831da664799eb4dbf082a843c34c66889548768
1 file changed +15 -2
commit.c
+15 -2
@@ -559,10 +559,24 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit
559 int indent = 4;
560 int parents_shown = 0;
561 const char *msg = commit->buffer;
562 + int plain_non_ascii = 0;
563
564 if (fmt == CMIT_FMT_ONELINE || fmt == CMIT_FMT_EMAIL)
565 indent = 0;
566
567 + /* After-subject is used to pass in Content-Type: multipart
568 + * MIME header; in that case we do not have to do the
569 + * plaintext content type even if the commit message has
570 + * non 7-bit ASCII character. Otherwise, check if we need
571 + * to say this is not a 7-bit ASCII.
572 + */
573 + if (fmt == CMIT_FMT_EMAIL && !after_subject) {
574 + int i;
575 + for (i = 0; !plain_non_ascii && msg[i] && i < len; i++)
576 + if (msg[i] & 0x80)
577 + plain_non_ascii = 1;
578 + }
579 +
580 for (;;) {
581 const char *line = msg;
582 int linelen = get_one_line(msg, len);
@@ -648,13 +662,12 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit
662 buf[offset++] = '\n';
663 if (fmt == CMIT_FMT_ONELINE)
664 break;
651 - if (subject) {
665 + if (subject && plain_non_ascii) {
666 static const char header[] =
667 "Content-Type: text/plain; charset=UTF-8\n"
668 "Content-Transfer-Encoding: 8bit\n";
669 memcpy(buf + offset, header, sizeof(header)-1);
670 offset += sizeof(header)-1;
657 - subject = NULL;
671 }
672 if (after_subject) {
673 int slen = strlen(after_subject);