Skip to content

Commit 8f5b544

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

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

builtin/apply.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4269,7 +4269,7 @@ static int add_conflicted_stages_file(struct apply_state *state,
42694269
return 0;
42704270
}
42714271

4272-
static void create_file(struct apply_state *state, struct patch *patch)
4272+
static int create_file(struct apply_state *state, struct patch *patch)
42734273
{
42744274
char *path = patch->new_name;
42754275
unsigned mode = patch->new_mode;
@@ -4280,13 +4280,10 @@ static void create_file(struct apply_state *state, struct patch *patch)
42804280
mode = S_IFREG | 0644;
42814281
create_one_file(state, path, mode, buf, size);
42824282

4283-
if (patch->conflicted_threeway) {
4284-
if (add_conflicted_stages_file(state, patch))
4285-
exit(128);
4286-
} else {
4287-
if (add_index_file(state, path, mode, buf, size))
4288-
exit(128);
4289-
}
4283+
if (patch->conflicted_threeway)
4284+
return add_conflicted_stages_file(state, patch);
4285+
else
4286+
return add_index_file(state, path, mode, buf, size);
42904287
}
42914288

42924289
/* phase zero is to remove, phase one is to create */
@@ -4302,8 +4299,10 @@ static void write_out_one_result(struct apply_state *state,
43024299
return;
43034300
}
43044301
if (patch->is_new > 0 || patch->is_copy) {
4305-
if (phase == 1)
4306-
create_file(state, patch);
4302+
if (phase == 1) {
4303+
if (create_file(state, patch))
4304+
exit(128);
4305+
}
43074306
return;
43084307
}
43094308
/*
@@ -4314,8 +4313,10 @@ static void write_out_one_result(struct apply_state *state,
43144313
if (remove_file(state, patch, patch->is_rename))
43154314
exit(128);
43164315
}
4317-
if (phase == 1)
4318-
create_file(state, patch);
4316+
if (phase == 1) {
4317+
if (create_file(state, patch))
4318+
exit(128);
4319+
}
43194320
}
43204321

43214322
static int write_out_one_reject(struct apply_state *state, struct patch *patch)

0 commit comments

Comments
 (0)