Re: [PATCH v2 54/94] builtin/apply: make parse_chunk() return a negative integer on error
From: Christian Couder <hidden>
Date: 2016-06-16 02:19:25
On Mon, May 16, 2016 at 5:04 AM, Eric Sunshine [off-list ref] wrote:
On Wed, May 11, 2016 at 9:17 AM, Christian Couder [off-list ref] wrote:quoted
To libify `git apply` functionality we have to signal errors to the caller instead of die()ing or exit()ing. To do that in a compatible manner with the rest of the error handling in builtin/apply.c, find_header() should return -1 instead of calling die() or exit().Why is this talking about making find_header() return -1? Didn't that happen in the previous patch?quoted
As parse_chunk() is called only by apply_patch() which already returns -1 when an error happened, let's make apply_patch() return -1 when parse_chunk() returns -1. If find_header() returns -2 because no patch header has been found, it is ok for parse_chunk() to also return -2. If find_header() returns -1 because an error happened, it is ok for parse_chunk() to do the same. Helped-by: Eric Sunshine [off-list ref] Signed-off-by: Christian Couder <redacted> ---diff --git a/builtin/apply.c b/builtin/apply.c@@ -2176,8 +2176,9 @@ static int parse_chunk(struct apply_state *state, char *buffer, unsigned long si * empty to us here. */ if ((state->apply || state->check) && - (!patch->is_binary && !metadata_changes(patch))) - die(_("patch with only garbage at line %d"), state->linenr); + (!patch->is_binary && !metadata_changes(patch))) { + return error(_("patch with only garbage at line %d"), state->linenr); + }Unnecessary braces.
Ok, will remove.