git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Erik Faye-Lund <kusmabite@gmail.com>,
	Git Mailing List <git@vger.kernel.org>
Subject: Re: [BUG] format-patch does not wrap From-field after author name
Date: Thu, 14 Apr 2011 13:50:34 -0400	[thread overview]
Message-ID: <20110414175034.GA23342@sigill.intra.peff.net> (raw)
In-Reply-To: <7v39lkiwoj.fsf@alter.siamese.dyndns.org>

On Thu, Apr 14, 2011 at 10:12:44AM -0700, Junio C Hamano wrote:

> Erik Faye-Lund <kusmabite@gmail.com> writes:
> 
> > With certain combinations of author name and email lengths, git
> > format-patch does not correctly wrap the From line to be below 78
> > characters, violating rfc2047.
> 
> Didn't we have this fixed quite a while ago with the series that ends at
> c22e7de (format-patch: rfc2047-encode newlines in headers, 2011-02-23)?
> 
> What version of git do you use?

No, that doesn't fix it. The problem is a short name and a long email
address. We rfc2047-encode and wrap the name, but then tack the email
onto the end without caring about line length.

According to rfc2047, we are specifically forbidden to use an
encoded-word in an addr-spec. So it would not make sense to assemble the
header first and then feed the whole thing to add_rfc2047.

Fortunately, this is an easy thing to wrap, since we can't actually
break the addr-spec across lines. We can just check if the line is long,
and if so, wrap the whole address to the next line, which is the best we
can do (and presumably nobody has an address portion over 78
characters). That patch looks something like:

diff --git a/pretty.c b/pretty.c
index e1d8a8f..63a7c2f 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,11 @@ 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');
 		strbuf_add(sb, name_tail, namelen - display_name_length);
 		strbuf_addch(sb, '\n');
 	} else {

Note that it relies on the commit header having a space before the "<",
which forms the continuation whitespace for the header. This is probably
reasonable, but we could double-check if we want to handle malformed
commit headers better.

Or we could just ignore it. AFAICS, this doesn't actually violate
rfc2047, nor rfc5322. The 78-character limit is simply a SHOULD, and
we have up to 998 for MUST. For a single-address header[1], this seems
kind of unlikely to me.

-Peff

[1] For multi-address headers like "format-patch --cc=foo --cc=bar", it
looks like we already break them across lines. No idea if "send-email"
is sensible in this area or not.

  reply	other threads:[~2011-04-14 17:50 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-14 17:01 [BUG] format-patch does not wrap From-field after author name Erik Faye-Lund
2011-04-14 17:12 ` Junio C Hamano
2011-04-14 17:50   ` Jeff King [this message]
2011-04-14 21:19     ` Erik Faye-Lund
2011-04-14 21:42       ` Jeff King
2011-04-14 22:18         ` Jeff King
2011-04-14 22:21         ` Erik Faye-Lund
2011-04-14 22:29           ` Jeff King
2011-04-14 22:43             ` Erik Faye-Lund
2011-04-15  3:30               ` Jeff King
2011-04-15  8:32                 ` Erik Faye-Lund
2011-04-16  1:45                   ` Jeff King
2011-04-14 17:52 ` Jeff King
2011-04-14 21:06   ` Erik Faye-Lund
2011-04-14 21:07   ` Erik Faye-Lund

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110414175034.GA23342@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=kusmabite@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).