builtin/apply: make remove_file() return -1 on error
To libify `git apply` functionality we have to signal errors to the caller instead of die()ing. To do that in a compatible manner with the rest of the error handling in "builtin/apply.c", remove_file() should return -1 instead of calling die(). 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
6e8df314692105e7d3e69f548440e4b817bf3211
1 file changed
+11
-6
builtin/apply.c
+11
-6
@@ -4085,17 +4085,18 @@ static void patch_stats(struct apply_state *state, struct patch *patch)
4085
}
4086
}
4087
4088
-static void remove_file(struct apply_state *state, struct patch *patch, int rmdir_empty)
4088
+static int remove_file(struct apply_state *state, struct patch *patch, int rmdir_empty)
4089
{
4090
if (state->update_index) {
4091
if (remove_file_from_cache(patch->old_name) < 0)
4092
- die(_("unable to remove %s from index"), patch->old_name);
4092
+ return error(_("unable to remove %s from index"), patch->old_name);
4093
}
4094
if (!state->cached) {
4095
if (!remove_or_warn(patch->old_mode, patch->old_name) && rmdir_empty) {
4096
remove_path(patch->old_name);
4097
}
4098
}
4099
+ return 0;
4100
}
4101
4102
static void add_index_file(struct apply_state *state,
@@ -4274,8 +4275,10 @@ static void write_out_one_result(struct apply_state *state,
4275
int phase)
4276
{
4277
if (patch->is_delete > 0) {
4277
- if (phase == 0)
4278
- remove_file(state, patch, 1);
4278
+ if (phase == 0) {
4279
+ if (remove_file(state, patch, 1))
4280
+ exit(128);
4281
+ }
4282
return;
4283
}
4284
if (patch->is_new > 0 || patch->is_copy) {
@@ -4287,8 +4290,10 @@ static void write_out_one_result(struct apply_state *state,
4290
* Rename or modification boils down to the same
4291
* thing: remove the old, write the new
4292
*/
4290
- if (phase == 0)
4291
- remove_file(state, patch, patch->is_rename);
4293
+ if (phase == 0) {
4294
+ if (remove_file(state, patch, patch->is_rename))
4295
+ exit(128);
4296
+ }
4297
if (phase == 1)
4298
create_file(state, patch);
4299
}