{"thread":{"id":"58366","subject":"forcing an in-body From header","startedAt":"2022-08-26T13:17:44Z","lastAt":"2022-08-29T12:14:05Z","messageCount":5,"participants":["Rasmus Villemoes","Konstantin Ryabitsev","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"461995","messageId":"c403e526-7455-4f26-fcef-97c99f9af539@rasmusvillemoes.dk","threadId":"58366","inReplyTo":null,"subject":"forcing an in-body From header","fromName":"Rasmus Villemoes","fromEmail":"rv@rasmusvillemoes.dk","sentAt":"2022-08-26T13:17:34Z","receivedAt":"2022-08-26T13:17:44Z","isPatch":false,"sender":{"key":"rv@rasmusvillemoes.dk","avatar":"https://avatars.githubusercontent.com/u/4375908?v=4"},"body":"Hi,\n\nSome mailing lists mangle the real From: header, making it a little hard\nfor maintainers to apply patches directly using 'git am'. See e.g.\nhttps://lists.openembedded.org/g/openembedded-core/message/166515 . One\nway to work around that is by having an in-body From: \"header\".\n\nHowever, merely setting sendemail.from or format.from is not enough to\nget such a header, if the value happens to be identical to the patch\nauthor (which it would usually be). So, could we get some config knob\nand/or command line switch to force an in-body from header? Then one\ncould set that on a per-project basis, for projects with such mailing lists.\n\nI looked into the code, and while this is obviously just a hacky patch\nto see that I found the right spot, it doesn't seem to be too hard to\nimplement properly.\n\ndiff --git a/pretty.c b/pretty.c\nindex ee6114e3f0..8b9ef6f644 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -503,7 +503,7 @@ void pp_user_info(struct pretty_print_context *pp,\n                map_user(pp->mailmap, &mailbuf, &maillen, &namebuf,\n&namelen);\n\n        if (cmit_fmt_is_mail(pp->fmt)) {\n-               if (pp->from_ident && ident_cmp(pp->from_ident, &ident)) {\n+               if (pp->from_ident && (ident_cmp(pp->from_ident, &ident)\n|| getenv(\"GIT_FORCE_BODY_FROM\"))) {\n                        struct strbuf buf = STRBUF_INIT;\n\n                        strbuf_addstr(&buf, \"From: \");\n\nThanks,\nRasmus\n"},{"id":"462005","messageId":"20220826164828.cxsveqtjiyimdj7s@meerkat.local","threadId":"58366","inReplyTo":"c403e526-7455-4f26-fcef-97c99f9af539@rasmusvillemoes.dk","subject":"Re: forcing an in-body From header","fromName":"Konstantin Ryabitsev","fromEmail":"konstantin@linuxfoundation.org","sentAt":"2022-08-26T16:48:28Z","receivedAt":"2022-08-26T16:50:26Z","isPatch":false,"sender":{"key":"konstantin@linuxfoundation.org","avatar":"https://gravatar.com/avatar/7cb8827c6de56e1bd2dea16508c6708aa43feed3bf3813bcdacecdf96ceadd79?d=mp&s=160"},"body":"On Fri, Aug 26, 2022 at 03:17:34PM +0200, Rasmus Villemoes wrote:\n> Hi,\n> \n> Some mailing lists mangle the real From: header, making it a little hard\n> for maintainers to apply patches directly using 'git am'. See e.g.\n> https://lists.openembedded.org/g/openembedded-core/message/166515 . One\n> way to work around that is by having an in-body From: \"header\".\n\nThis is only tangentially related to the problem at hand, but the list in\nquestion is also mirrored on lore.kernel.org:\n\nhttps://lore.kernel.org/openembedded-core/20220531151052.3667079-1-sean.anderson@seco.com/\n\nThe mirroring is done with a direct push hook from groups.io, which is why we\nget messages without all the groups.io mangling.\n\n> However, merely setting sendemail.from or format.from is not enough to\n> get such a header, if the value happens to be identical to the patch\n> author (which it would usually be). So, could we get some config knob\n> and/or command line switch to force an in-body from header? Then one\n> could set that on a per-project basis, for projects with such mailing lists.\n\nI agree that it's a nice feature to have, though I would put this into the\nsendemail config instead of using an env variable, something like:\n\n    [sendemail]\n      in-body-headers = From\n\n-K\n"},{"id":"462008","messageId":"xmqqtu5zx74e.fsf@gitster.g","threadId":"58366","inReplyTo":"c403e526-7455-4f26-fcef-97c99f9af539@rasmusvillemoes.dk","subject":"Re: forcing an in-body From header","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-08-26T17:11:13Z","receivedAt":"2022-08-26T17:11:20Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Rasmus Villemoes <rv@rasmusvillemoes.dk> writes:\n\n> I looked into the code, and while this is obviously just a hacky patch\n> to see that I found the right spot, it doesn't seem to be too hard to\n> implement properly.\n\nI agree with you on all points in the above sentence ;-) I do not\nthink anybody minds if a command line option to \"git format-patch\"\nadded in builtin/log.c::cmd_format_patch() and a new configuration\nvariable taught to builtin/log.c::git_format_config() that gives\nthe default value for the new \"force_in_body_from\" member that will\nbe added to \"struct rev_info\" and relayed to \"pretty_print_context\"\nwhen log-tree.c::fmt_output_commit() calls format_commit_messages().\n\nOr something like that.\n"},{"id":"462009","messageId":"xmqqo7w6yl8y.fsf@gitster.g","threadId":"58366","inReplyTo":"20220826164828.cxsveqtjiyimdj7s@meerkat.local","subject":"Re: forcing an in-body From header","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-08-26T17:20:45Z","receivedAt":"2022-08-26T17:20:58Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Konstantin Ryabitsev <konstantin@linuxfoundation.org> writes:\n\n> I agree that it's a nice feature to have, though I would put this into the\n> sendemail config instead of using an env variable, something like:\n>\n>     [sendemail]\n>       in-body-headers = From\n\nA change only for send-email does sound quite attractive.\n\nI encourage folks to run format-patch first, make amends as needed\nin the output files, proofread the result once again, all before\nfinally handing it to send-email for sending out.  If a \"force\nin-body headers\" command line option plus a configuration variable\nadded to \"git send-email\" would work for them, I would be OK with\nsuch a change.\n\nThere may be folks who do not use \"git send-email\" to send out their\npatches, and a change to \"git format-patch\" may help them, though.\n\nThanks.\n"},{"id":"462081","messageId":"f07a2387-dbbc-fd13-9817-069767c75165@rasmusvillemoes.dk","threadId":"58366","inReplyTo":"xmqqo7w6yl8y.fsf@gitster.g","subject":"Re: forcing an in-body From header","fromName":"Rasmus Villemoes","fromEmail":"rv@rasmusvillemoes.dk","sentAt":"2022-08-29T11:56:58Z","receivedAt":"2022-08-29T12:14:05Z","isPatch":false,"sender":{"key":"rv@rasmusvillemoes.dk","avatar":"https://avatars.githubusercontent.com/u/4375908?v=4"},"body":"On 26/08/2022 19.20, Junio C Hamano wrote:\n> Konstantin Ryabitsev <konstantin@linuxfoundation.org> writes:\n> \n>> I agree that it's a nice feature to have, though I would put this into the\n>> sendemail config instead of using an env variable, something like:\n>>\n>>     [sendemail]\n>>       in-body-headers = From\n> \n> A change only for send-email does sound quite attractive.\n> \n> I encourage folks to run format-patch first, make amends as needed\n> in the output files, proofread the result once again, all before\n> finally handing it to send-email for sending out. \n\nThat's at least my usual workflow, yes.\n\n If a \"force\n> in-body headers\" command line option plus a configuration variable\n> added to \"git send-email\" would work for them, I would be OK with\n> such a change.\n\nIt would work for me, except that if I am to rely on git send-email to\nmunge the body of the file(s) I pass to it, I'd really like a way for\n--dry-run to reassure me that that will actually happen. Currently that\nonly prints the headers, which is quite useful to check that the To and\nCc are as expected (especially when one has some to-cmd or cc-cmd\nconfigured).\n\n> There may be folks who do not use \"git send-email\" to send out their\n> patches, and a change to \"git format-patch\" may help them, though.\n\nMaybe, yes. I also stumbled on this paragraph in git format-patch --help\nwhich would probably need some adjustment\n\n           Note that this option is only useful if you are actually\nsending the\n           emails and want to identify yourself as the sender, but\nretain the\n           original author (and git am will correctly pick up the in-body\n           header). Note also that git send-email already handles this\n           transformation for you, and this option should not be used if\nyou are\n           feeding the result to git send-email.\n\nI don't know how git send-email behaves if there already is an in-body\nFrom, or if it is different than the one that send-email was about to\nadd itself.\n\nSomehow I got the cover letter of the mini-series, but neither of the\ntwo actual patches. I can't answer the big-picture question of whether\nthis belongs in format-patch, send-email or both, but:\n\n> * Should it be \"inbody\" or \"in-body\"?\n\nin-body, I think.\n\n> * Should it have a corresponding configuration variable?\n\nMost definitely yes, it's something I'd want to set for certain projects\nin the local .git/config file, and not a command line option I want to\nhave to remember when doing the occasional contribution for those projects.\n\nThanks for the quick responses and initial draft work on this.\n\nRasmus\n"}]}