mirror of
https://github.com/git/git.git
synced 2024-09-30 07:51:31 +02:00
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>
This commit is contained in:
parent
fe41b80225
commit
6e8df31469
@ -4085,17 +4085,18 @@ static void patch_stats(struct apply_state *state, struct patch *patch)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void remove_file(struct apply_state *state, struct patch *patch, int rmdir_empty)
|
static int remove_file(struct apply_state *state, struct patch *patch, int rmdir_empty)
|
||||||
{
|
{
|
||||||
if (state->update_index) {
|
if (state->update_index) {
|
||||||
if (remove_file_from_cache(patch->old_name) < 0)
|
if (remove_file_from_cache(patch->old_name) < 0)
|
||||||
die(_("unable to remove %s from index"), patch->old_name);
|
return error(_("unable to remove %s from index"), patch->old_name);
|
||||||
}
|
}
|
||||||
if (!state->cached) {
|
if (!state->cached) {
|
||||||
if (!remove_or_warn(patch->old_mode, patch->old_name) && rmdir_empty) {
|
if (!remove_or_warn(patch->old_mode, patch->old_name) && rmdir_empty) {
|
||||||
remove_path(patch->old_name);
|
remove_path(patch->old_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_index_file(struct apply_state *state,
|
static void add_index_file(struct apply_state *state,
|
||||||
@ -4274,8 +4275,10 @@ static void write_out_one_result(struct apply_state *state,
|
|||||||
int phase)
|
int phase)
|
||||||
{
|
{
|
||||||
if (patch->is_delete > 0) {
|
if (patch->is_delete > 0) {
|
||||||
if (phase == 0)
|
if (phase == 0) {
|
||||||
remove_file(state, patch, 1);
|
if (remove_file(state, patch, 1))
|
||||||
|
exit(128);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (patch->is_new > 0 || patch->is_copy) {
|
if (patch->is_new > 0 || patch->is_copy) {
|
||||||
@ -4287,8 +4290,10 @@ static void write_out_one_result(struct apply_state *state,
|
|||||||
* Rename or modification boils down to the same
|
* Rename or modification boils down to the same
|
||||||
* thing: remove the old, write the new
|
* thing: remove the old, write the new
|
||||||
*/
|
*/
|
||||||
if (phase == 0)
|
if (phase == 0) {
|
||||||
remove_file(state, patch, patch->is_rename);
|
if (remove_file(state, patch, patch->is_rename))
|
||||||
|
exit(128);
|
||||||
|
}
|
||||||
if (phase == 1)
|
if (phase == 1)
|
||||||
create_file(state, patch);
|
create_file(state, patch);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user