From: Junio C Hamano Date: Fri, 6 May 2011 17:50:18 +0000 (-0700) Subject: Merge branch 'jk/format-patch-quote-special-in-from' X-Git-Tag: v1.7.6-rc0~102 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ace8ebbcf5f07a5519cbeb0ae0571d8b40222e34;p=git.git Merge branch 'jk/format-patch-quote-special-in-from' * jk/format-patch-quote-special-in-from: pretty: quote rfc822 specials in email addresses Conflicts: pretty.c t/t4014-format-patch.sh --- ace8ebbcf5f07a5519cbeb0ae0571d8b40222e34 diff --cc pretty.c index ba95de92c,0252a21a0..dff5c8d18 --- a/pretty.c +++ b/pretty.c @@@ -294,15 -345,14 +346,22 @@@ void pp_user_info(const char *what, enu name_tail--; display_name_length = name_tail - line; strbuf_addstr(sb, "From: "); - add_rfc2047(sb, line, display_name_length, encoding); + if (!has_rfc822_specials(line, display_name_length)) { + add_rfc2047(sb, line, display_name_length, encoding); + } else { + struct strbuf quoted = STRBUF_INIT; + add_rfc822_quoted("ed, line, display_name_length); + add_rfc2047(sb, quoted.buf, quoted.len, encoding); + strbuf_release("ed); + } + for (final_line = 0; final_line < sb->len; final_line++) + if (sb->buf[sb->len - final_line - 1] == '\n') + break; + if (namelen - display_name_length + final_line > 78) { + strbuf_addch(sb, '\n'); + if (!isspace(name_tail[0])) + strbuf_addch(sb, ' '); + } strbuf_add(sb, name_tail, namelen - display_name_length); strbuf_addch(sb, '\n'); } else { diff --cc t/t4014-format-patch.sh index a7060b75b,6f8a96cd8..045cee312 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@@ -793,19 -793,46 +793,62 @@@ test_expect_success 'format-patch wrap test_cmp expect subject ' +M8="foo_bar_" +M64=$M8$M8$M8$M8$M8$M8$M8$M8 +cat >expect < +EOF +test_expect_success 'format-patch wraps non-quotable headers' ' + rm -rf patches/ && + echo content >>file && + git add file && + git commit -mfoo --author "$M64 " && + git format-patch --stdout -1 >patch && + sed -n "/^From: /p; /^ /p; /^$/q" from && + test_cmp expect from +' ++ + check_author() { + echo content >>file && + git add file && + GIT_AUTHOR_NAME=$1 git commit -m author-check && + git format-patch --stdout -1 >patch && + grep ^From: patch >actual && + test_cmp expect actual + } + + cat >expect <<'EOF' + From: "Foo B. Bar" + EOF + test_expect_success 'format-patch quotes dot in headers' ' + check_author "Foo B. Bar" + ' + + cat >expect <<'EOF' + From: "Foo \"The Baz\" Bar" + EOF + test_expect_success 'format-patch quotes double-quote in headers' ' + check_author "Foo \"The Baz\" Bar" + ' + + cat >expect <<'EOF' + From: =?UTF-8?q?"F=C3=B6o=20B.=20Bar"?= + EOF + test_expect_success 'rfc2047-encoded headers also double-quote 822 specials' ' + check_author "Föo B. Bar" + ' + + cat >expect <<'EOF' + Subject: header with . in it + EOF + test_expect_success 'subject lines do not have 822 atom-quoting' ' + echo content >>file && + git add file && + git commit -m "header with . in it" && + git format-patch -k -1 --stdout >patch && + grep ^Subject: patch >actual && + test_cmp expect actual + ' + test_done