{"thread":{"id":"31221","subject":"git am and the wrong chunk of ---","startedAt":"2012-08-10T00:13:51Z","lastAt":"2012-08-10T16:39:21Z","messageCount":8,"participants":["H. Peter Anvin","Junio C Hamano","Jeff King","Andreas Ericsson"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"196767","messageId":"5024523F.3050208@zytor.com","threadId":"31221","inReplyTo":null,"subject":"git am and the wrong chunk of ---","fromName":"H. Peter Anvin","fromEmail":"hpa@zytor.com","sentAt":"2012-08-10T00:13:51Z","receivedAt":"2012-08-10T00:13:51Z","isPatch":false,"sender":{"key":"hpa@zytor.com","avatar":null},"body":"Hello,\n\nI have some contributors who consistently put their commentary *before* \nthe \"---\" line rather than *after* it, presumably with the notion that \nit is some kind of \"cover text\".  This messes with \"git am\", and so I \nend up having to edit those posts manually.\n\nI have tried git am --scissors and it doesn't seem to solve the problem.\n\nIs there any other option which can be used to automatically process \nsuch a patch?\n\n\t-hpa\n\n-- \nH. Peter Anvin, Intel Open Source Technology Center\nI work for Intel.  I don't speak on their behalf.\n"},{"id":"196772","messageId":"7v393vmtaa.fsf@alter.siamese.dyndns.org","threadId":"31221","inReplyTo":"5024523F.3050208@zytor.com","subject":"Re: git am and the wrong chunk of ---","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-08-10T01:26:21Z","receivedAt":"2012-08-10T01:26:21Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"H. Peter Anvin\" <hpa@zytor.com> writes:\n\n> Hello,\n>\n> I have some contributors who consistently put their commentary\n> *before* the \"---\" line rather than *after* it, presumably with the\n> notion that it is some kind of \"cover text\".  This messes with \"git\n> am\", and so I end up having to edit those posts manually.\n>\n> I have tried git am --scissors and it doesn't seem to solve the problem.\n>\n> Is there any other option which can be used to automatically process\n> such a patch?\n\nI hate to be the one who is telling you this, but if the submitter\ncannot be trained to write supporting material after \"---\" as the\nconvention across git using projects suggest him to do, it is likely\nthat he didn't write supporting material before the scissors, or did\nnot resist the temptation to deviate from the accepted shape of the\nscissors (e.g. \"-- >8 --\") just to be creative.  For that matter, I\nwould be mildly surprised if the material in the middle is usable as\nis as an acceptable log message from such a submitter X-<.\n\nSo in short, no, --scissors (or -c in short) is not any more magical\nthan the traditional \"---\".\n"},{"id":"196788","messageId":"20120810103612.GA21562@sigill.intra.peff.net","threadId":"31221","inReplyTo":"5024523F.3050208@zytor.com","subject":"Re: git am and the wrong chunk of ---","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2012-08-10T10:36:13Z","receivedAt":"2012-08-10T10:36:13Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Aug 09, 2012 at 05:13:51PM -0700, H. Peter Anvin wrote:\n\n> I have some contributors who consistently put their commentary\n> *before* the \"---\" line rather than *after* it, presumably with the\n> notion that it is some kind of \"cover text\".  This messes with \"git\n> am\", and so I end up having to edit those posts manually.\n> \n> I have tried git am --scissors and it doesn't seem to solve the problem.\n> \n> Is there any other option which can be used to automatically process\n> such a patch?\n\nIf I understand your issue, somebody is writing:\n\n\n    From: them\n    To: you\n    Date: ...\n    Subject: [PATCH] subject line\n\n    commit message body\n    ....\n\n    some cover letter material that should go below the \"---\"\n    ---\n      [diffstat + diff]\n\n\nHow do you know when the commit message body ends, and the cover letter\nbegins? We already have two machine-readable formats for separating the\ntwo (\"---\" after the commit message, and \"-- >8 --\" scissors before). Is\nthere some machine-readable hint? Is it always the paragraph before the\n\"---\"? Chopping that off unconditionally seems like a dangerous\nheuristic.\n\n-Peff\n"},{"id":"196789","messageId":"5024E9B7.1070004@op5.se","threadId":"31221","inReplyTo":"20120810103612.GA21562@sigill.intra.peff.net","subject":"Re: git am and the wrong chunk of ---","fromName":"Andreas Ericsson","fromEmail":"ae@op5.se","sentAt":"2012-08-10T11:00:07Z","receivedAt":"2012-08-10T11:00:07Z","isPatch":false,"sender":{"key":"ae@op5.se","avatar":"https://gravatar.com/avatar/426e89595c75a8f5252dd0c989e5fabe5bcac616e68557427ad9aef6b0ca342a?d=mp&s=160"},"body":"On 08/10/2012 12:36 PM, Jeff King wrote:\n> On Thu, Aug 09, 2012 at 05:13:51PM -0700, H. Peter Anvin wrote:\n> \n>> I have some contributors who consistently put their commentary\n>> *before* the \"---\" line rather than *after* it, presumably with the\n>> notion that it is some kind of \"cover text\".  This messes with \"git\n>> am\", and so I end up having to edit those posts manually.\n>>\n>> I have tried git am --scissors and it doesn't seem to solve the problem.\n>>\n>> Is there any other option which can be used to automatically process\n>> such a patch?\n> \n> If I understand your issue, somebody is writing:\n> \n> \n>      From: them\n>      To: you\n>      Date: ...\n>      Subject: [PATCH] subject line\n> \n>      commit message body\n>      ....\n> \n>      some cover letter material that should go below the \"---\"\n>      ---\n>        [diffstat + diff]\n> \n> \n> How do you know when the commit message body ends, and the cover letter\n> begins? We already have two machine-readable formats for separating the\n> two (\"---\" after the commit message, and \"-- >8 --\" scissors before). Is\n> there some machine-readable hint? Is it always the paragraph before the\n> \"---\"? Chopping that off unconditionally seems like a dangerous\n> heuristic.\n> \n\nEnd of SOB lines might be a good cutoff, if they're present. I've never\nseen anyone put commit message text below them anyway.\n\n-- \nAndreas Ericsson                   andreas.ericsson@op5.se\nOP5 AB                             www.op5.se\nTel: +46 8-230225                  Fax: +46 8-230231\n\nConsidering the successes of the wars on alcohol, poverty, drugs and\nterror, I think we should give some serious thought to declaring war\non peace.\n"},{"id":"196793","messageId":"7vsjbuls9h.fsf@alter.siamese.dyndns.org","threadId":"31221","inReplyTo":"20120810103612.GA21562@sigill.intra.peff.net","subject":"Re: git am and the wrong chunk of ---","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-08-10T14:46:02Z","receivedAt":"2012-08-10T14:46:02Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> If I understand your issue, somebody is writing:\n>\n>\n>     From: them\n>     To: you\n>     Date: ...\n>     Subject: [PATCH] subject line\n>\n>     commit message body\n>     ....\n>\n>     some cover letter material that should go below the \"---\"\n>     ---\n>       [diffstat + diff]\n>\n> How do you know when the commit message body ends, and the cover letter\n> begins? We already have two machine-readable formats for separating the\n> two (\"---\" after the commit message, and \"-- >8 --\" scissors before). Is\n> there some machine-readable hint? Is it always the paragraph before the\n> \"---\"? Chopping that off unconditionally seems like a dangerous\n> heuristic.\n\nOr it could be like this:\n\n    ...\n    Subject: [PATCH] patch title\n\n    Heya,\n\n    I was walking my dog when I found a solution to this\n    problem the other day.  Here it is.\n\n    commit message body\n\n    S-o-b: ...\n    ---\n\nAnd I agree that clever heuristics are dangerous.  We need to draw a\nline somewhere anyway, and the line should be at the place that is\neasily understandable to people.  That means mechanically parseable\nand easy to follow convention to use markers e.g. \"---\".\n"},{"id":"196794","messageId":"b661ef79-510e-4be6-bed2-451e9967db6f@email.android.com","threadId":"31221","inReplyTo":"7vsjbuls9h.fsf@alter.siamese.dyndns.org","subject":"Re: git am and the wrong chunk of ---","fromName":"H. Peter Anvin","fromEmail":"hpa@zytor.com","sentAt":"2012-08-10T14:48:39Z","receivedAt":"2012-08-10T14:48:39Z","isPatch":false,"sender":{"key":"hpa@zytor.com","avatar":null},"body":"The users I am referring to generally have a --- line, rather than a scissor, between the cover text and commit.  Also, there is (almost) always a From: line and subject at the top of the patch proper.\n\nJunio C Hamano <gitster@pobox.com> wrote:\n\n>Jeff King <peff@peff.net> writes:\n>\n>> If I understand your issue, somebody is writing:\n>>\n>>\n>>     From: them\n>>     To: you\n>>     Date: ...\n>>     Subject: [PATCH] subject line\n>>\n>>     commit message body\n>>     ....\n>>\n>>     some cover letter material that should go below the \"---\"\n>>     ---\n>>       [diffstat + diff]\n>>\n>> How do you know when the commit message body ends, and the cover\n>letter\n>> begins? We already have two machine-readable formats for separating\n>the\n>> two (\"---\" after the commit message, and \"-- >8 --\" scissors before).\n>Is\n>> there some machine-readable hint? Is it always the paragraph before\n>the\n>> \"---\"? Chopping that off unconditionally seems like a dangerous\n>> heuristic.\n>\n>Or it could be like this:\n>\n>    ...\n>    Subject: [PATCH] patch title\n>\n>    Heya,\n>\n>    I was walking my dog when I found a solution to this\n>    problem the other day.  Here it is.\n>\n>    commit message body\n>\n>    S-o-b: ...\n>    ---\n>\n>And I agree that clever heuristics are dangerous.  We need to draw a\n>line somewhere anyway, and the line should be at the place that is\n>easily understandable to people.  That means mechanically parseable\n>and easy to follow convention to use markers e.g. \"---\".\n\n-- \nSent from my mobile phone. Please excuse brevity and lack of formatting.\n"},{"id":"196803","messageId":"7v628qlo53.fsf@alter.siamese.dyndns.org","threadId":"31221","inReplyTo":"b661ef79-510e-4be6-bed2-451e9967db6f@email.android.com","subject":"Re: git am and the wrong chunk of ---","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-08-10T16:15:04Z","receivedAt":"2012-08-10T16:15:04Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"H. Peter Anvin\" <hpa@zytor.com> writes:\n\n> The users I am referring to generally have a --- line, rather than\n> a scissor, between the cover text and commit.  Also, there is\n> (almost) always a From: line and subject at the top of the patch\n> proper.\n\nOh, so it is more like this?\n\n    From: author name <author@address.xz>\n    Date: author date\n    Subject: patch title\n\n    Heya,\n\n    I was walking my dog when I found a solution to this\n    problem the other day.  Here it is.\n\n    ---\n    >From 755e8b3f35e3991a735a6be740eda4567d45a741 Mon Sep 17 00:00:00 2001\n    From: author name <author@address.xz>\n    Date: random date we do not care\n    Subject: patch title\n\n    commit message body\n\n    ---\n\nWe could teach \"am -c\" to recognize the format-patch file magic\n\n    \"^[>]From [0-9a-f]{40} Mon Sep 17 00:00:00 2001\"\n\nas another form of accepted scissors, I guess.\n\nSomething like the attached (untested) patch, perhaps.\n\nBut I am fairly negative on it.\n\nWhere would it end?  After all, the top \"---\" is not something our\ntools are generating, but is manually typed by the users.\n\nI do not think it is unreasonable to expect that they are capable\nand intelligent enough to guess that \"---\" is _not_ the way to say\n\"cut here and what follows are the log message\", when \"---\" is\nalready the way to say \"cut here, and what we saw up to this point\nis the log message\".\n\n builtin/mailinfo.c | 18 +++++++++++++++++-\n 1 file changed, 17 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/mailinfo.c b/builtin/mailinfo.c\nindex eaf9e15..62ea09d 100644\n--- a/builtin/mailinfo.c\n+++ b/builtin/mailinfo.c\n@@ -730,6 +730,22 @@ static inline int patchbreak(const struct strbuf *line)\n \treturn 0;\n }\n \n+static int is_format_patch_magic(const struct strbuf *line)\n+{\n+\tconst char *buf = line->buf;\n+\tsize_t len = line->len;\n+\n+\tif (len && *buf == '>') {\n+\t\tbuf++;\n+\t\tlen--;\n+\t}\n+\tif (len < 70)\n+\t\treturn 0;\n+\treturn (!memcmp(buf, \"From \", 5) &&\n+\t\tstrspn(buf + 5, \"0123456789abcdef\") == 40 &&\n+\t\t!memcmp(buf + 46, \"Mon Sep 17 00:00:00 2001\", 24));\n+}\n+\n static int is_scissors_line(const struct strbuf *line)\n {\n \tsize_t i, len = line->len;\n@@ -807,7 +823,7 @@ static int handle_commit_msg(struct strbuf *line)\n \tif (metainfo_charset)\n \t\tconvert_to_utf8(line, charset.buf);\n \n-\tif (use_scissors && is_scissors_line(line)) {\n+\tif (use_scissors && (is_scissors_line(line) || is_format_patch_magic(line))) {\n \t\tint i;\n \t\tif (fseek(cmitmsg, 0L, SEEK_SET))\n \t\t\tdie_errno(\"Could not rewind output message file\");\n"},{"id":"196807","messageId":"50253939.7080908@zytor.com","threadId":"31221","inReplyTo":"7v628qlo53.fsf@alter.siamese.dyndns.org","subject":"Re: git am and the wrong chunk of ---","fromName":"H. Peter Anvin","fromEmail":"hpa@zytor.com","sentAt":"2012-08-10T16:39:21Z","receivedAt":"2012-08-10T16:39:21Z","isPatch":false,"sender":{"key":"hpa@zytor.com","avatar":null},"body":"On 08/10/2012 09:15 AM, Junio C Hamano wrote:\n> \"H. Peter Anvin\" <hpa@zytor.com> writes:\n> \n>> The users I am referring to generally have a --- line, rather than\n>> a scissor, between the cover text and commit.  Also, there is\n>> (almost) always a From: line and subject at the top of the patch\n>> proper.\n> \n> Oh, so it is more like this?\n> \n>     From: author name <author@address.xz>\n>     Date: author date\n>     Subject: patch title\n> \n>     Heya,\n> \n>     I was walking my dog when I found a solution to this\n>     problem the other day.  Here it is.\n> \n>     ---\n>     >From 755e8b3f35e3991a735a6be740eda4567d45a741 Mon Sep 17 00:00:00 2001\n>     From: author name <author@address.xz>\n>     Date: random date we do not care\n>     Subject: patch title\n> \n>     commit message body\n> \n>     ---\n> \n\nThat is exactly what I see, except usually with the mbox header.\n\nHowever, it makes sense to me to treat From: as a scissor (we can then\nignore the preceding --- completely).\n\n\t-hpa\n"}]}