git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] format-patch: notice failure to open cover letter for writing

From
Jeff King <peff@peff.net>
Date
Feb 22, 2019, 06:26 UTC
Message-ID
<20190222062606.GD10248@sigill.intra.peff.net>
In-Reply-To
<xmqqlg28snv0.fsf@gitster-ct.c.googlers.com>
On Thu, Feb 21, 2019 at 03:50:11PM -0800, Junio C Hamano wrote:
Show 7 quoted lines
> The make_cover_letter() function is supposed to open a new file for
> writing, and let the caller write into it via FILE *rev->diffopt.file
> but because the function does not return anything, the caller does not
> bother checking the return value.
> 
> Make sure it dies, instead of keep going with a NULL output
> filestream and relying on it to cause a crash.
Definitely makes sense.
Show 10 quoted lines
> diff --git a/builtin/log.c b/builtin/log.c
> index 3e145fe502..43fc9a07df 100644
> --- a/builtin/log.c
> +++ b/builtin/log.c
> @@ -1047,7 +1047,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
>  
>  	if (!use_stdout &&
>  	    open_next_file(NULL, rev->numbered_files ? NULL : "cover-letter", rev, quiet))
> -		return;
> +		die(_("Failed to create cover-letter file"));

I wondered if we should be showing errno here, but it looks like open_next_file() will give us a more specific error (including errno if applicable).

I'd suggest s/F/f/ in the message to match our usual style, though I see this code has a lot of capitalized errors already. :)

Show 5 quoted lines
> +test_expect_success 'failure to write cover-letter aborts gracefully' '
> +	test_when_finished "rmdir 0000-cover-letter.patch" &&
> +	mkdir 0000-cover-letter.patch &&
> +	test_must_fail git format-patch --no-renames --cover-letter -1
> +'
Cute test. :)
-Peff
Previous: Junio C HamanoNext: Duy Nguyen
Message 2 of 4 in “format-patch: notice failure to open cover letter for writing”
  1. format-patch: notice failure to open cover letter for writingJunio C Hamano, Feb 21, 2019
  2. Jeff KingFeb 22, 2019
  3. Duy NguyenFeb 22, 2019
  4. Junio C HamanoFeb 22, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.