{"thread":{"id":"51953","subject":"git mailinfo with patch parser","startedAt":"2019-10-02T04:52:44Z","lastAt":"2019-10-02T05:41:20Z","messageCount":3,"participants":["Florian Weimer","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"383240","messageId":"87imp77o5k.fsf@mid.deneb.enyo.de","threadId":"51953","inReplyTo":null,"subject":"git mailinfo with patch parser","fromName":"Florian Weimer","fromEmail":"fw@deneb.enyo.de","sentAt":"2019-10-02T04:43:35Z","receivedAt":"2019-10-02T04:52:44Z","isPatch":false,"sender":{"key":"fw@deneb.enyo.de","avatar":null},"body":"git mailinfo splits a message into headers, commit message, and patch\ntext, but does not actually parse the patch text.  As a result, the\npatch portion produced by git mailinfo can contain something that\nlooks like a patch, but actually isn't.\n\nIs there a way to get the patch data, as parsed by git apply or git\nam, and dump it back in patch format, without actually applying the\npatch to a working tree?\n"},{"id":"383241","messageId":"xmqq1rvvhfq2.fsf@gitster-ct.c.googlers.com","threadId":"51953","inReplyTo":"87imp77o5k.fsf@mid.deneb.enyo.de","subject":"Re: git mailinfo with patch parser","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-10-02T05:35:33Z","receivedAt":"2019-10-02T05:35:38Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Florian Weimer <fw@deneb.enyo.de> writes:\n\n> git mailinfo splits a message into headers, commit message, and patch\n> text, but does not actually parse the patch text.  As a result, the\n> patch portion produced by git mailinfo can contain something that\n> looks like a patch, but actually isn't.\n\nYes, mailinfo is about splitting the header, log message and the\nremainder, and parsing the remainder to use it as a patch text is\nleft to the consumer of the \"patch\" file it produces.\n\n> Is there a way to get the patch data, as parsed by git apply or git\n> am, and dump it back in patch format, without actually applying the\n> patch to a working tree?\n\nSo, \"the patch data as used by apply\" is what you get from mailinfo.\nIf it is a patch that applies to what you have in the working tree\nand/or the index is something you can/must ask \"git apply\".  IOW,\nwhen \"git mailinfo\" stored in $GIT_DIR/rebase-apply/patch the\n\"remainder\" of the message, you could\n\n\tgit apply --check [--index] $GIT_DIR/rebase-apply/patch\n\nto see if it is an OK patch.  If it is, then there is no need to\nfurther \"dump it back in patch format\"; what you just fed to \"apply\n--check\" is already in the patch format.\n\n\n\n"},{"id":"383243","messageId":"878sq366wy.fsf@mid.deneb.enyo.de","threadId":"51953","inReplyTo":"xmqq1rvvhfq2.fsf@gitster-ct.c.googlers.com","subject":"Re: git mailinfo with patch parser","fromName":"Florian Weimer","fromEmail":"fw@deneb.enyo.de","sentAt":"2019-10-02T05:41:17Z","receivedAt":"2019-10-02T05:41:20Z","isPatch":false,"sender":{"key":"fw@deneb.enyo.de","avatar":null},"body":"* Junio C. Hamano:\n\n>> Is there a way to get the patch data, as parsed by git apply or git\n>> am, and dump it back in patch format, without actually applying the\n>> patch to a working tree?\n>\n> So, \"the patch data as used by apply\" is what you get from mailinfo.\n> If it is a patch that applies to what you have in the working tree\n> and/or the index is something you can/must ask \"git apply\".  IOW,\n> when \"git mailinfo\" stored in $GIT_DIR/rebase-apply/patch the\n> \"remainder\" of the message, you could\n>\n> \tgit apply --check [--index] $GIT_DIR/rebase-apply/patch\n>\n> to see if it is an OK patch.  If it is, then there is no need to\n> further \"dump it back in patch format\"; what you just fed to \"apply\n> --check\" is already in the patch format.\n\nYes, but that requires a fully patched up Git repository containing\nthe right blobs.\n\nWe know from experience that it is easy for humans to misread patches\nand fail to notice that certain patch hunks are actually ignored by\ngit apply and similar tools.  If there was a way to feed the patch\nthrough the parser and serialize it back, these discrepancies would be\nmore noticeable, I think.  Any data ignored by git apply/git am would\nbe missing from the output.\n"}]}