git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: "Problems" with git format-patch --thread email header ordering

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 15, 2019, 04:47 UTC
Message-ID
<xmqqk1h09224.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<CAHk-=whP1stFZNAaJiMi5eZ9rj0MRt20Y_yHVczZPH+O01d+sA@mail.gmail.com>
Linus Torvalds <torvalds@linux-foundation.org> writes:
Show 24 quoted lines
> While it's true that header ordering isn't specified, there's a common
> "canonical" order that the headers are listed in. To quote rfc822:
> ...
>             body must occur AFTER  the  headers.   It  is  recommended
>             that,  if  present,  headers be sent in the order "Return-
>             Path", "Received", "Date",  "From",  "Subject",  "Sender",
>             "To", "cc", etc.
>
> But git format-patch does create the email headers out in a different
> order than the one recommended.  When you do "git format-patch
> --thread" to create the emails, the header ordering looks roughly like
> this:
>
>   Message-Id: <cover.1552606170.git.torvalds@linux-foundation.org>
>   From: Linus Torvalds <torvalds@linux-foundation.org>
>   Date: Thu, 14 Mar 2019 16:29:30 -0700
>   Subject: [PATCH 0/6] *** SUBJECT HERE ***
>   MIME-Version: 1.0
>   Content-Type: text/plain; charset=UTF-8
>   Content-Transfer-Encoding: 8bit
> ...
> And yes, if somebody from Google on this list wants to bring this up
> with the gmail team, I wish you the best of luck. Let me know how it
> goes.

I obviously won't do the last one myself, but if the issue is only to swap from and date, then this may be sufficient, perhaps?

I suspect that there would be fallouts in t/ directory before we can call this a fix.

 pretty.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/pretty.c b/pretty.c
index f496f0f128..40c7236fbc 100644
--- a/pretty.c
+++ b/pretty.c
@@ -452,6 +452,14 @@ void pp_user_info(struct pretty_print_context *pp,
 		map_user(pp->mailmap, &mailbuf, &maillen, &namebuf, &namelen);
 
 	if (cmit_fmt_is_mail(pp->fmt)) {
+
+		/* 
+		 * Date: before From:
+		 * cf. <CAHk-=whP1stFZNAaJiMi5eZ9rj0MRt20Y_yHVczZPH+O01d+sA@mail.gmail.com>
+		 */
+		strbuf_addf(sb, "Date: %s\n",
+			    show_ident_date(&ident, DATE_MODE(RFC2822)));
+
 		if (pp->from_ident && ident_cmp(pp->from_ident, &ident)) {
 			struct strbuf buf = STRBUF_INIT;
 
@@ -502,8 +510,7 @@ void pp_user_info(struct pretty_print_context *pp,
 		break;
 	case CMIT_FMT_EMAIL:
 	case CMIT_FMT_MBOXRD:
-		strbuf_addf(sb, "Date: %s\n",
-			    show_ident_date(&ident, DATE_MODE(RFC2822)));
+		/* has been done much earlier */
 		break;
 	case CMIT_FMT_FULLER:
 		strbuf_addf(sb, "%sDate: %s\n", what,
Previous: Linus TorvaldsNext: Linus Torvalds
Message 2 of 5 in “"Problems" with git format-patch --thread email header ordering”
  1. Linus TorvaldsMar 14, 2019
  2. Junio C HamanoMar 15, 2019
  3. Linus TorvaldsMar 15, 2019
  4. Julian Andres KlodeApr 4, 2019
  5. Junio C HamanoApr 5, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.