diff mbox series

[v2,1/5] am: don't die in read_author_script()

Message ID 20181018100023.7327-2-phillip.wood@talktalk.net (mailing list archive)
State New, archived
Headers show
Series am/rebase: share read_author_script() | expand

Commit Message

Phillip Wood Oct. 18, 2018, 10 a.m. UTC
From: Phillip Wood <phillip.wood@dunelm.org.uk>

The caller is already prepared to handle errors returned from this
function so there is no need for it to die if it cannot read the file.

Suggested-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 builtin/am.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Junio C Hamano Oct. 25, 2018, 8:44 a.m. UTC | #1
Phillip Wood <phillip.wood@talktalk.net> writes:

> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> The caller is already prepared to handle errors returned from this
> function so there is no need for it to die if it cannot read the file.
>
> Suggested-by: Eric Sunshine <sunshine@sunshineco.com>
> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
> ---
>  builtin/am.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

OK.  Having fewer die's in reusable codepath can only be a good
thing.

>
> diff --git a/builtin/am.c b/builtin/am.c
> index 5e866d17c7..b68578bc3f 100644
> --- a/builtin/am.c
> +++ b/builtin/am.c
> @@ -318,7 +318,8 @@ static int read_author_script(struct am_state *state)
>  	if (fd < 0) {
>  		if (errno == ENOENT)
>  			return 0;
> -		die_errno(_("could not open '%s' for reading"), filename);
> +		return error_errno(_("could not open '%s' for reading"),
> +				   filename);
>  	}
>  	strbuf_read(&buf, fd, 0);
>  	close(fd);
diff mbox series

Patch

diff --git a/builtin/am.c b/builtin/am.c
index 5e866d17c7..b68578bc3f 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -318,7 +318,8 @@  static int read_author_script(struct am_state *state)
 	if (fd < 0) {
 		if (errno == ENOENT)
 			return 0;
-		die_errno(_("could not open '%s' for reading"), filename);
+		return error_errno(_("could not open '%s' for reading"),
+				   filename);
 	}
 	strbuf_read(&buf, fd, 0);
 	close(fd);