Skip to content

Commit 434389d

Browse files
chriscoolgitster
authored andcommitted
builtin/apply: make write_out_one_result() 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_one_result() should just return what remove_file() and create_file() are returning instead of calling exit(). Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8f5b544 commit 434389d

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

builtin/apply.c

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4287,36 +4287,29 @@ static int create_file(struct apply_state *state, struct patch *patch)
42874287
}
42884288

42894289
/* phase zero is to remove, phase one is to create */
4290-
static void write_out_one_result(struct apply_state *state,
4291-
struct patch *patch,
4292-
int phase)
4290+
static int write_out_one_result(struct apply_state *state,
4291+
struct patch *patch,
4292+
int phase)
42934293
{
42944294
if (patch->is_delete > 0) {
4295-
if (phase == 0) {
4296-
if (remove_file(state, patch, 1))
4297-
exit(128);
4298-
}
4299-
return;
4295+
if (phase == 0)
4296+
return remove_file(state, patch, 1);
4297+
return 0;
43004298
}
43014299
if (patch->is_new > 0 || patch->is_copy) {
4302-
if (phase == 1) {
4303-
if (create_file(state, patch))
4304-
exit(128);
4305-
}
4306-
return;
4300+
if (phase == 1)
4301+
return create_file(state, patch);
4302+
return 0;
43074303
}
43084304
/*
43094305
* Rename or modification boils down to the same
43104306
* thing: remove the old, write the new
43114307
*/
4312-
if (phase == 0) {
4313-
if (remove_file(state, patch, patch->is_rename))
4314-
exit(128);
4315-
}
4316-
if (phase == 1) {
4317-
if (create_file(state, patch))
4318-
exit(128);
4319-
}
4308+
if (phase == 0)
4309+
return remove_file(state, patch, patch->is_rename);
4310+
if (phase == 1)
4311+
return create_file(state, patch);
4312+
return 0;
43204313
}
43214314

43224315
static int write_out_one_reject(struct apply_state *state, struct patch *patch)
@@ -4403,7 +4396,8 @@ static int write_out_results(struct apply_state *state, struct patch *list)
44034396
if (l->rejected)
44044397
errs = 1;
44054398
else {
4406-
write_out_one_result(state, l, phase);
4399+
if (write_out_one_result(state, l, phase))
4400+
exit(128);
44074401
if (phase == 1) {
44084402
if (write_out_one_reject(state, l))
44094403
errs = 1;

0 commit comments

Comments
 (0)