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 <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed Aug 8, 2016 at 23:03 UTC 8f5b5445d7c015dc5f2bbf65d23779d355c0c36e
1 file changed +13 -12
builtin/apply.c
+13 -12
@@ -4269,7 +4269,7 @@ static int add_conflicted_stages_file(struct apply_state *state,
4269 return 0;
4270 }
4271
4272 -static void create_file(struct apply_state *state, struct patch *patch)
4272 +static int create_file(struct apply_state *state, struct patch *patch)
4273 {
4274 char *path = patch->new_name;
4275 unsigned mode = patch->new_mode;
@@ -4280,13 +4280,10 @@ static void create_file(struct apply_state *state, struct patch *patch)
4280 mode = S_IFREG | 0644;
4281 create_one_file(state, path, mode, buf, size);
4282
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);
4287 }
4288
4289 /* phase zero is to remove, phase one is to create */
@@ -4302,8 +4299,10 @@ static void write_out_one_result(struct apply_state *state,
4299 return;
4300 }
4301 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 + }
4306 return;
4307 }
4308 /*
@@ -4314,8 +4313,10 @@ static void write_out_one_result(struct apply_state *state,
4313 if (remove_file(state, patch, patch->is_rename))
4314 exit(128);
4315 }
4317 - if (phase == 1)
4318 - create_file(state, patch);
4316 + if (phase == 1) {
4317 + if (create_file(state, patch))
4318 + exit(128);
4319 + }
4320 }
4321
4322 static int write_out_one_reject(struct apply_state *state, struct patch *patch)