Re: [PATCH 51/83] builtin/apply: make apply_patch() return -1 instead of die()ing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Apr 26, 2016 at 3:20 AM, Eric Sunshine <sunshine@xxxxxxxxxxxxxx> wrote:
> On Sun, Apr 24, 2016 at 9:33 AM, Christian Couder
> <christian.couder@xxxxxxxxx> wrote:
>> To libify `git apply` functionality we have to signal errors
>> to the caller instead of die()ing.
>>
>> As a first step in this direction, let's make apply_patch() return
>> -1 in case of errors instead of dying. For now its only caller
>> apply_all_patches() will exit(1) when apply_patch() return -1.
>>
>> In a later patch, apply_all_patches() will return -1 too instead of
>> exiting.
>>
>> Signed-off-by: Christian Couder <chriscool@xxxxxxxxxxxxx>
>> ---
>> diff --git a/builtin/apply.c b/builtin/apply.c
>> @@ -4522,6 +4522,14 @@ static int write_out_results(struct apply_state *state, struct patch *list)
>>  static int apply_patch(struct apply_state *state,
>>                        int fd,
>>                        const char *filename,
>> @@ -4564,7 +4572,7 @@ static int apply_patch(struct apply_state *state,
>>         }
>>
>>         if (!list && !skipped_patch)
>> -               die(_("unrecognized input"));
>> +               return error(_("unrecognized input"));
>>
>>         if (state->whitespace_error && (state->ws_error_action == die_on_ws_error))
>>                 state->apply = 0;
>> @@ -4575,19 +4583,17 @@ static int apply_patch(struct apply_state *state,
>>                 hold_locked_index(state->lock_file, 1);
>>         }
>>
>> -       if (state->check_index) {
>> -               if (read_cache() < 0)
>> -                       die(_("unable to read index file"));
>> -       }
>> +       if (state->check_index && read_cache() < 0)
>> +               return error(_("unable to read index file"));
>>
>>         if ((state->check || state->apply) &&
>>             check_patch_list(state, list) < 0 &&
>>             !state->apply_with_reject)
>> -               exit(1);
>> +               return -1;
>>
>>         if (state->apply && write_out_results(state, list)) {
>>                 if (state->apply_with_reject)
>> -                       exit(1);
>> +                       return -1;
>>                 /* with --3way, we still need to write the index out */
>>                 return 1;
>>         }
>
> Are these new 'returns' leaking 'list', 'buf', and 'fn_table' which
> otherwise get released at the end of the function?

Yeah, you are right, I will fix that. Thanks.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]