[prev in list] [next in list] [prev in thread] [next in thread] 

List:       git
Subject:    Re: [PATCH 51/83] builtin/apply: make apply_patch() return -1 instead of die()ing
From:       Christian Couder <christian.couder () gmail ! com>
Date:       2016-04-30 19:41:07
Message-ID: CAP8UFD2SzSXWSH8uB2iJ8-QpkYhXDNGbSks4Ua3TLrVH0a7Acw () mail ! gmail ! com
[Download RAW message or body]

On Tue, Apr 26, 2016 at 3:20 AM, Eric Sunshine <sunshine@sunshineco.com> wrote:
> On Sun, Apr 24, 2016 at 9:33 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.
>>
>> 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@tuxfamily.org>
>> ---
>> 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@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic