{"thread":{"id":"24047","subject":"[PATCH] format-patch: Emit bare email rather than mbox for single messages.","startedAt":"2010-06-08T23:43:35Z","lastAt":"2010-06-08T23:43:35Z","messageCount":1,"participants":["Carl Worth"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"143298","messageId":"1276040615-26008-1-git-send-email-cworth@cworth.org","threadId":"24047","inReplyTo":null,"subject":"[PATCH] format-patch: Emit bare email rather than mbox for single messages.","fromName":"Carl Worth","fromEmail":"cworth@cworth.org","sentAt":"2010-06-08T23:43:35Z","receivedAt":"2010-06-08T23:43:35Z","isPatch":true,"sender":{"key":"cworth@cworth.org","avatar":"https://gravatar.com/avatar/3746dc28cde609bdbd7f939058356e7e2bbd16d21e32274df0725eb3d998bc5b?d=mp&s=160"},"body":"We don't need an mbox when generating a file with just a single\nmessage. And tools tools such as \"git am\" and \"git send-email\" already\nhandle a bare email rather than an mbox just fine. Users wanting to\nmanually insert the output into an MUA are not likely to want an\nmbox-formatted file either.\n\nFinally, git's current mbox formatting is not robust, (does not yet\ndeal well with a commit message containing a line matching \"^From \").\n\nFor all of these reasons, it's better to just generate an email\nmessage rather than an mbox when generating a file with a single\nmessage.\n\nNote that \"format-patch --stdout\" will still use the (less than\ntotally robust) mbox format, even if there is only a single\ncommit. This is because \"git rebase\" uses \"format-patch --stdout\" with\n\"am --rebasing\" which looks at the generated \"From \" line to find the\ncommit identifier that is embedded there.\n\nSigned-off-by: Carl Worth <cworth@cworth.org>\n---\n\nThis is as recently discussed by myself and H. Peter Anvin on the\nlist.\n\nNote that I originally claimed that git-send-email would need to be\nupdated to support this mode, but I found that it actually already has\nthe necessary code.\n\nAlso, this patch doesn't add any new test cases only because the test\nsuite seems to provide good coverange of \"git format-patch\" usage\nalready, (generating and using both mbox and non-mbox output after\nthis patch). Indeed the test suite showed me a problem I had with\n\"git rebase\" in an early version of this patch.\n\n builtin/log.c |    4 +++-\n log-tree.c    |    6 ++++--\n revision.h    |    3 ++-\n 3 files changed, 9 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 976e16f..adbec9f 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -1205,7 +1205,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\tget_patch_ids(&rev, &ids, prefix);\n \t}\n \n-\tif (!use_stdout)\n+\tif (use_stdout)\n+\t\trev.format_mbox = 1;\n+\telse\n \t\trealstdout = xfdopen(xdup(1), \"w\");\n \n \tif (prepare_revision_walk(&rev))\ndiff --git a/log-tree.c b/log-tree.c\nindex d3ae969..6aab273 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -217,8 +217,10 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,\n \t\tsubject = \"Subject: \";\n \t}\n \n-\tprintf(\"From %s Mon Sep 17 00:00:00 2001\\n\", name);\n-\tgraph_show_oneline(opt->graph);\n+\tif (opt->format_mbox) {\n+\t\tprintf(\"From %s Mon Sep 17 00:00:00 2001\\n\", name);\n+\t\tgraph_show_oneline(opt->graph);\n+\t}\n \tif (opt->message_id) {\n \t\tprintf(\"Message-Id: <%s>\\n\", opt->message_id);\n \t\tgraph_show_oneline(opt->graph);\ndiff --git a/revision.h b/revision.h\nindex 568f1c9..10cc747 100644\n--- a/revision.h\n+++ b/revision.h\n@@ -88,7 +88,8 @@ struct rev_info {\n \t\t\tabbrev_commit:1,\n \t\t\tuse_terminator:1,\n \t\t\tmissing_newline:1,\n-\t\t\tdate_mode_explicit:1;\n+\t\t\tdate_mode_explicit:1,\n+\t\t\tformat_mbox:1;\n \tunsigned int\tdisable_stdin:1;\n \n \tenum date_mode date_mode;\n-- \n1.7.0.4\n"}]}