Merge branch 'jk/format-patch-multiline-header'
authorJunio C Hamano <gitster@pobox.com>
Wed, 4 May 2011 22:51:27 +0000 (15:51 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 4 May 2011 22:51:27 +0000 (15:51 -0700)
* jk/format-patch-multiline-header:
format-patch: wrap email addresses after long names

1  2 
pretty.c
t/t4014-format-patch.sh
diff --combined pretty.c
index e1d8a8f414bf052a59fbe78d022e611f44ed8361,305ff85d744e40ce00879fd087205567c156bc51..ba95de92cd66f9ba24d84e706b013d2679ef554a
+++ b/pretty.c
@@@ -287,6 -287,7 +287,7 @@@ void pp_user_info(const char *what, enu
        if (fmt == CMIT_FMT_EMAIL) {
                char *name_tail = strchr(line, '<');
                int display_name_length;
+               int final_line;
                if (!name_tail)
                        return;
                while (line < name_tail && isspace(name_tail[-1]))
                display_name_length = name_tail - line;
                strbuf_addstr(sb, "From: ");
                add_rfc2047(sb, line, display_name_length, encoding);
+               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 {
@@@ -876,7 -885,11 +885,7 @@@ static size_t format_commit_one(struct 
                                              c->abbrev_parent_hashes.off;
                return 1;
        case 'm':               /* left/right/bottom */
 -              strbuf_addch(sb, (commit->object.flags & BOUNDARY)
 -                               ? '-'
 -                               : (commit->object.flags & SYMMETRIC_LEFT)
 -                               ? '<'
 -                               : '>');
 +              strbuf_addstr(sb, get_revision_mark(NULL, commit));
                return 1;
        case 'd':
                format_decoration(sb, commit);
diff --combined t/t4014-format-patch.sh
index 37a4109c979d4ae27c0b625fab70eeee0d9a3dde,9f64a4e2a1119f21cec2fc99e749243333ed2855..a7060b75be60fd5d16128274e15344c6333de76f
@@@ -616,11 -616,11 +616,11 @@@ echo "fatal: --check does not make sens
  
  test_expect_success 'options no longer allowed for format-patch' '
        test_must_fail git format-patch --name-only 2> output &&
 -      test_cmp expect.name-only output &&
 +      test_i18ncmp expect.name-only output &&
        test_must_fail git format-patch --name-status 2> output &&
 -      test_cmp expect.name-status output &&
 +      test_i18ncmp expect.name-status output &&
        test_must_fail git format-patch --check 2> output &&
 -      test_cmp expect.check output'
 +      test_i18ncmp expect.check output'
  
  test_expect_success 'format-patch --numstat should produce a patch' '
        git format-patch --numstat --stdout master..side > output &&
@@@ -793,4 -793,19 +793,19 @@@ 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
+ From: $M64
+  <foobar@foo.bar>
+ EOF
+ test_expect_success 'format-patch wraps non-quotable headers' '
+       rm -rf patches/ &&
+       echo content >>file &&
+       git add file &&
+       git commit -mfoo --author "$M64 <foobar@foo.bar>" &&
+       git format-patch --stdout -1 >patch &&
+       sed -n "/^From: /p; /^ /p; /^$/q" <patch >from &&
+       test_cmp expect from
+ '
  test_done