Skip to content

Commit 990f6e3

Browse files
peffgitster
authored andcommitted
format-patch: wrap email addresses after long names
We already wrap names in "from" headers, which tend to be the long part of an address. But it's also possible for a long name to not be wrapped, but to make us want to wrap the email address. For example (imagine for the sake of readability we want to wrap at 50 characters instead of 78): From: this is my really long git name <[email protected]> The name does not overflow the line, but the name and email together do. So we would rather see: From: this is my really long git name <[email protected]> Because we wrap the name separately during add_rfc2047, we neglected this case. Instead, we should see how long the final line of the wrapped name ended up, and decide whether or not to wrap based on that. We can't break the address into multiple parts, so we either leave it with the name, or put it by itself on a line. Test by Erik Faye-Lund. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c22e7de commit 990f6e3

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

pretty.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,22 @@ void pp_user_info(const char *what, enum cmit_fmt fmt, struct strbuf *sb,
287287
if (fmt == CMIT_FMT_EMAIL) {
288288
char *name_tail = strchr(line, '<');
289289
int display_name_length;
290+
int final_line;
290291
if (!name_tail)
291292
return;
292293
while (line < name_tail && isspace(name_tail[-1]))
293294
name_tail--;
294295
display_name_length = name_tail - line;
295296
strbuf_addstr(sb, "From: ");
296297
add_rfc2047(sb, line, display_name_length, encoding);
298+
for (final_line = 0; final_line < sb->len; final_line++)
299+
if (sb->buf[sb->len - final_line - 1] == '\n')
300+
break;
301+
if (namelen - display_name_length + final_line > 78) {
302+
strbuf_addch(sb, '\n');
303+
if (!isspace(name_tail[0]))
304+
strbuf_addch(sb, ' ');
305+
}
297306
strbuf_add(sb, name_tail, namelen - display_name_length);
298307
strbuf_addch(sb, '\n');
299308
} else {

t/t4014-format-patch.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,4 +793,19 @@ test_expect_success 'format-patch wraps extremely long headers (rfc2047)' '
793793
test_cmp expect subject
794794
'
795795

796+
M8="foo_bar_"
797+
M64=$M8$M8$M8$M8$M8$M8$M8$M8
798+
cat >expect <<EOF
799+
From: $M64
800+
801+
EOF
802+
test_expect_success 'format-patch wraps non-quotable headers' '
803+
rm -rf patches/ &&
804+
echo content >>file &&
805+
git add file &&
806+
git commit -mfoo --author "$M64 <[email protected]>" &&
807+
git format-patch --stdout -1 >patch &&
808+
sed -n "/^From: /p; /^ /p; /^$/q" <patch >from &&
809+
test_cmp expect from
810+
'
796811
test_done

0 commit comments

Comments
 (0)