On Mon, May 16, 2016 at 5:04 AM, Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 35 quoted lines
> On Wed, May 11, 2016 at 9:17 AM, Christian Couder
> <christian.couder@gmail.com> wrote:
>> 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?
>
>> 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 <sunshine@sunshineco.com>
>> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
>> ---
>> 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.