summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorChristian Couder <christian.couder@gmail.com>2016-08-08 21:03:21 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-08-11 19:41:47 (GMT)
commit434389deb193016464702b25af2b79bb5c6fd098 (patch)
treea0f8f119116a1cabd2562ff7610d1e5f80dbd30a /builtin
parent8f5b5445d7c015dc5f2bbf65d23779d355c0c36e (diff)
downloadgit-434389deb193016464702b25af2b79bb5c6fd098.zip
git-434389deb193016464702b25af2b79bb5c6fd098.tar.gz
git-434389deb193016464702b25af2b79bb5c6fd098.tar.bz2
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 <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/apply.c38
1 files changed, 16 insertions, 22 deletions
diff --git a/builtin/apply.c b/builtin/apply.c
index fdfeab0..003acec 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -4287,36 +4287,29 @@ static int create_file(struct apply_state *state, struct patch *patch)
}
/* phase zero is to remove, phase one is to create */
-static void write_out_one_result(struct apply_state *state,
- struct patch *patch,
- int phase)
+static int write_out_one_result(struct apply_state *state,
+ struct patch *patch,
+ int phase)
{
if (patch->is_delete > 0) {
- if (phase == 0) {
- if (remove_file(state, patch, 1))
- exit(128);
- }
- return;
+ if (phase == 0)
+ return remove_file(state, patch, 1);
+ return 0;
}
if (patch->is_new > 0 || patch->is_copy) {
- if (phase == 1) {
- if (create_file(state, patch))
- exit(128);
- }
- return;
+ if (phase == 1)
+ return create_file(state, patch);
+ return 0;
}
/*
* Rename or modification boils down to the same
* thing: remove the old, write the new
*/
- if (phase == 0) {
- if (remove_file(state, patch, patch->is_rename))
- exit(128);
- }
- if (phase == 1) {
- if (create_file(state, patch))
- exit(128);
- }
+ if (phase == 0)
+ return remove_file(state, patch, patch->is_rename);
+ if (phase == 1)
+ return create_file(state, patch);
+ return 0;
}
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)
if (l->rejected)
errs = 1;
else {
- write_out_one_result(state, l, phase);
+ if (write_out_one_result(state, l, phase))
+ exit(128);
if (phase == 1) {
if (write_out_one_reject(state, l))
errs = 1;