builtin/apply: make write_out_results() return -1 on error
To libify `git apply` functionality we have to signal errors to the caller instead of exit()ing. To do that in a compatible manner with the rest of the error handling in "builtin/apply.c", write_out_results() should return -1 instead of calling exit(). Helped-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
434389deb1
commit
ccceb7bb13
|
@ -4383,6 +4383,12 @@ static int write_out_one_reject(struct apply_state *state, struct patch *patch)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns:
|
||||||
|
* -1 if an error happened
|
||||||
|
* 0 if the patch applied cleanly
|
||||||
|
* 1 if the patch did not apply cleanly
|
||||||
|
*/
|
||||||
static int write_out_results(struct apply_state *state, struct patch *list)
|
static int write_out_results(struct apply_state *state, struct patch *list)
|
||||||
{
|
{
|
||||||
int phase;
|
int phase;
|
||||||
|
@ -4396,8 +4402,10 @@ static int write_out_results(struct apply_state *state, struct patch *list)
|
||||||
if (l->rejected)
|
if (l->rejected)
|
||||||
errs = 1;
|
errs = 1;
|
||||||
else {
|
else {
|
||||||
if (write_out_one_result(state, l, phase))
|
if (write_out_one_result(state, l, phase)) {
|
||||||
exit(128);
|
string_list_clear(&cpath, 0);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
if (phase == 1) {
|
if (phase == 1) {
|
||||||
if (write_out_one_reject(state, l))
|
if (write_out_one_reject(state, l))
|
||||||
errs = 1;
|
errs = 1;
|
||||||
|
@ -4517,10 +4525,17 @@ static int apply_patch(struct apply_state *state,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state->apply && write_out_results(state, list)) {
|
if (state->apply) {
|
||||||
/* with --3way, we still need to write the index out */
|
int write_res = write_out_results(state, list);
|
||||||
res = state->apply_with_reject ? -1 : 1;
|
if (write_res < 0) {
|
||||||
goto end;
|
res = -128;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
if (write_res > 0) {
|
||||||
|
/* with --3way, we still need to write the index out */
|
||||||
|
res = state->apply_with_reject ? -1 : 1;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state->fake_ancestor &&
|
if (state->fake_ancestor &&
|
||||||
|
|
Loading…
Reference in New Issue