aboutsummaryrefslogtreecommitdiff
path: root/pretty.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2011-04-14 18:18:09 -0400
committerJunio C Hamano <gitster@pobox.com>2011-04-14 15:42:04 -0700
commit990f6e30eb00adeb8cad75c3be34c0fc9ff6abb0 (patch)
tree685bbcb7ee8cebd6facdbad4cafa0268077b49cb /pretty.c
parentc22e7de340df2e0ebc0e98347aa02a32a459835f (diff)
downloadgit-990f6e30eb00adeb8cad75c3be34c0fc9ff6abb0.tar.gz
git-990f6e30eb00adeb8cad75c3be34c0fc9ff6abb0.tar.xz
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 <foo@example.com> 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 <git@example.com> 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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'pretty.c')
-rw-r--r--pretty.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/pretty.c b/pretty.c
index 65d20a7a2..305ff85d7 100644
--- a/pretty.c
+++ b/pretty.c
@@ -287,6 +287,7 @@ void pp_user_info(const char *what, enum cmit_fmt fmt, struct strbuf *sb,
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]))
@@ -294,6 +295,14 @@ void pp_user_info(const char *what, enum cmit_fmt fmt, struct strbuf *sb,
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 {