{"thread":{"id":"50555","subject":"[PATCH] format-patch: notice failure to open cover letter for writing","startedAt":"2019-02-21T23:50:16Z","lastAt":"2019-02-22T17:54:44Z","messageCount":4,"participants":["Junio C Hamano","Jeff King","Duy Nguyen"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"369873","messageId":"xmqqlg28snv0.fsf@gitster-ct.c.googlers.com","threadId":"50555","inReplyTo":null,"subject":"[PATCH] format-patch: notice failure to open cover letter for writing","fromName":"Junio C Hamano","fromEmail":"junio@pobox.com","sentAt":"2019-02-21T23:50:11Z","receivedAt":"2019-02-21T23:50:16Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"The make_cover_letter() function is supposed to open a new file for\nwriting, and let the caller write into it via FILE *rev->diffopt.file\nbut because the function does not return anything, the caller does not\nbother checking the return value.\n\nMake sure it dies, instead of keep going with a NULL output\nfilestream and relying on it to cause a crash.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n builtin/log.c           | 2 +-\n t/t4014-format-patch.sh | 6 ++++++\n 2 files changed, 7 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 3e145fe502..43fc9a07df 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -1047,7 +1047,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,\n \n \tif (!use_stdout &&\n \t    open_next_file(NULL, rev->numbered_files ? NULL : \"cover-letter\", rev, quiet))\n-\t\treturn;\n+\t\tdie(_(\"Failed to create cover-letter file\"));\n \n \tlog_write_email_headers(rev, head, &pp.after_subject, &need_8bit_cte, 0);\n \ndiff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh\nindex 909c743c13..b6e2fdbc44 100755\n--- a/t/t4014-format-patch.sh\n+++ b/t/t4014-format-patch.sh\n@@ -589,6 +589,12 @@ test_expect_success 'excessive subject' '\n \tls patches/0004-This-is-an-excessively-long-subject-line-for-a-messa.patch\n '\n \n+test_expect_success 'failure to write cover-letter aborts gracefully' '\n+\ttest_when_finished \"rmdir 0000-cover-letter.patch\" &&\n+\tmkdir 0000-cover-letter.patch &&\n+\ttest_must_fail git format-patch --no-renames --cover-letter -1\n+'\n+\n test_expect_success 'cover-letter inherits diff options' '\n \tgit mv file foo &&\n \tgit commit -m foo &&\n"},{"id":"369888","messageId":"20190222062606.GD10248@sigill.intra.peff.net","threadId":"50555","inReplyTo":"xmqqlg28snv0.fsf@gitster-ct.c.googlers.com","subject":"Re: [PATCH] format-patch: notice failure to open cover letter for writing","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2019-02-22T06:26:07Z","receivedAt":"2019-02-22T06:26:10Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Feb 21, 2019 at 03:50:11PM -0800, Junio C Hamano wrote:\n\n> The make_cover_letter() function is supposed to open a new file for\n> writing, and let the caller write into it via FILE *rev->diffopt.file\n> but because the function does not return anything, the caller does not\n> bother checking the return value.\n> \n> Make sure it dies, instead of keep going with a NULL output\n> filestream and relying on it to cause a crash.\n\nDefinitely makes sense.\n\n> diff --git a/builtin/log.c b/builtin/log.c\n> index 3e145fe502..43fc9a07df 100644\n> --- a/builtin/log.c\n> +++ b/builtin/log.c\n> @@ -1047,7 +1047,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,\n>  \n>  \tif (!use_stdout &&\n>  \t    open_next_file(NULL, rev->numbered_files ? NULL : \"cover-letter\", rev, quiet))\n> -\t\treturn;\n> +\t\tdie(_(\"Failed to create cover-letter file\"));\n\nI wondered if we should be showing errno here, but it looks like\nopen_next_file() will give us a more specific error (including errno if\napplicable).\n\nI'd suggest s/F/f/ in the message to match our usual style, though I see\nthis code has a lot of capitalized errors already. :)\n\n> +test_expect_success 'failure to write cover-letter aborts gracefully' '\n> +\ttest_when_finished \"rmdir 0000-cover-letter.patch\" &&\n> +\tmkdir 0000-cover-letter.patch &&\n> +\ttest_must_fail git format-patch --no-renames --cover-letter -1\n> +'\n\nCute test. :)\n\n-Peff\n"},{"id":"369889","messageId":"CACsJy8A1cqWkomePW8i6veNT+WP2nq_kAZHay74ZgZFsz-d+nw@mail.gmail.com","threadId":"50555","inReplyTo":"20190222062606.GD10248@sigill.intra.peff.net","subject":"Re: [PATCH] format-patch: notice failure to open cover letter for writing","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2019-02-22T07:50:49Z","receivedAt":"2019-02-22T07:51:18Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Fri, Feb 22, 2019 at 1:28 PM Jeff King <peff@peff.net> wrote:\n> > diff --git a/builtin/log.c b/builtin/log.c\n> > index 3e145fe502..43fc9a07df 100644\n> > --- a/builtin/log.c\n> > +++ b/builtin/log.c\n> > @@ -1047,7 +1047,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,\n> >\n> >       if (!use_stdout &&\n> >           open_next_file(NULL, rev->numbered_files ? NULL : \"cover-letter\", rev, quiet))\n> > -             return;\n> > +             die(_(\"Failed to create cover-letter file\"));\n>\n> I'd suggest s/F/f/ in the message to match our usual style, though I see\n> this code has a lot of capitalized errors already. :)\n\nThanks! The lowercase wins over uppercase [1] 1517 to 327.\nUnfortunately it's a tie in this file. But I think it's still good\nthat new messages stick to lowercase.\n\n[1] counting error/warn/die only with\n\ngit grep 'die[_a-z]*(_(\"[A-Z]\\|error[_a-z]*(_(\"[A-Z]\\|warning[_a-z]*(_(\"[A-Z]'\n-- \\*.c\n-- \nDuy\n"},{"id":"369961","messageId":"xmqqo973r9nk.fsf@gitster-ct.c.googlers.com","threadId":"50555","inReplyTo":"20190222062606.GD10248@sigill.intra.peff.net","subject":"Re: [PATCH] format-patch: notice failure to open cover letter for writing","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-02-22T17:54:39Z","receivedAt":"2019-02-22T17:54:44Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> I'd suggest s/F/f/ in the message to match our usual style, though I see\n> this code has a lot of capitalized errors already. :)\n\nYup, I'd prepare a prelim clean-up before this step.\n\n>> +test_expect_success 'failure to write cover-letter aborts gracefully' '\n>> +\ttest_when_finished \"rmdir 0000-cover-letter.patch\" &&\n>> +\tmkdir 0000-cover-letter.patch &&\n>> +\ttest_must_fail git format-patch --no-renames --cover-letter -1\n>> +'\n>\n> Cute test. :)\n\nThose who can find this \"cute\" would probably know, but for others,\nthis is a trick to test codepath for \"cannot create a file\" error\nwithout requiring SANITY prerequisite.\n"}]}