summaryrefslogtreecommitdiff
path: root/commit.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2006-05-22 06:55:00 (GMT)
committerJunio C Hamano <junkio@cox.net>2006-05-22 06:55:00 (GMT)
commitc831da664799eb4dbf082a843c34c66889548768 (patch)
tree94c532ee014a80c74b1ba54a188ef3d4910b7784 /commit.c
parentcdd406e389bd6e0b2ad9394340a366c0c5ae27fc (diff)
downloadgit-c831da664799eb4dbf082a843c34c66889548768.zip
git-c831da664799eb4dbf082a843c34c66889548768.tar.gz
git-c831da664799eb4dbf082a843c34c66889548768.tar.bz2
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>
Diffstat (limited to 'commit.c')
-rw-r--r--commit.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/commit.c b/commit.c
index 7597fba..94f470b 100644
--- a/commit.c
+++ b/commit.c
@@ -559,10 +559,24 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit
int indent = 4;
int parents_shown = 0;
const char *msg = commit->buffer;
+ int plain_non_ascii = 0;
if (fmt == CMIT_FMT_ONELINE || fmt == CMIT_FMT_EMAIL)
indent = 0;
+ /* After-subject is used to pass in Content-Type: multipart
+ * MIME header; in that case we do not have to do the
+ * plaintext content type even if the commit message has
+ * 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) {
+ int i;
+ for (i = 0; !plain_non_ascii && msg[i] && i < len; i++)
+ if (msg[i] & 0x80)
+ plain_non_ascii = 1;
+ }
+
for (;;) {
const char *line = msg;
int linelen = get_one_line(msg, len);
@@ -648,13 +662,12 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit
buf[offset++] = '\n';
if (fmt == CMIT_FMT_ONELINE)
break;
- if (subject) {
+ if (subject && plain_non_ascii) {
static const char header[] =
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n";
memcpy(buf + offset, header, sizeof(header)-1);
offset += sizeof(header)-1;
- subject = NULL;
}
if (after_subject) {
int slen = strlen(after_subject);