builtin/apply: make check_apply_state() return -1 instead of die()ing
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", check_apply_state() 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
f36538d88b12595d527c60ae1b882c89bb5d1b2a
1 file changed
+11
-8
builtin/apply.c
+11
-8
@@ -4551,17 +4551,17 @@ static int option_parse_directory(const struct option *opt,
4551
return 0;
4552
}
4553
4554
-static void check_apply_state(struct apply_state *state, int force_apply)
4554
+static int check_apply_state(struct apply_state *state, int force_apply)
4555
{
4556
int is_not_gitdir = !startup_info->have_repository;
4557
4558
if (state->apply_with_reject && state->threeway)
4559
- die("--reject and --3way cannot be used together.");
4559
+ return error("--reject and --3way cannot be used together.");
4560
if (state->cached && state->threeway)
4561
- die("--cached and --3way cannot be used together.");
4561
+ return error("--cached and --3way cannot be used together.");
4562
if (state->threeway) {
4563
if (is_not_gitdir)
4564
- die(_("--3way outside a repository"));
4564
+ return error(_("--3way outside a repository"));
4565
state->check_index = 1;
4566
}
4567
if (state->apply_with_reject)
@@ -4569,16 +4569,18 @@ static void check_apply_state(struct apply_state *state, int force_apply)
4569
if (!force_apply && (state->diffstat || state->numstat || state->summary || state->check || state->fake_ancestor))
4570
state->apply = 0;
4571
if (state->check_index && is_not_gitdir)
4572
- die(_("--index outside a repository"));
4572
+ return error(_("--index outside a repository"));
4573
if (state->cached) {
4574
if (is_not_gitdir)
4575
- die(_("--cached outside a repository"));
4575
+ return error(_("--cached outside a repository"));
4576
state->check_index = 1;
4577
}
4578
if (state->check_index)
4579
state->unsafe_paths = 0;
4580
if (!state->lock_file)
4581
- die("BUG: state->lock_file should not be NULL");
4581
+ return error("BUG: state->lock_file should not be NULL");
4582
+
4583
+ return 0;
4584
}
4585
4586
static int apply_all_patches(struct apply_state *state,
@@ -4747,7 +4749,8 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
4749
argc = parse_options(argc, argv, state.prefix, builtin_apply_options,
4750
apply_usage, 0);
4751
4750
- check_apply_state(&state, force_apply);
4752
+ if (check_apply_state(&state, force_apply))
4753
+ exit(128);
4754
4755
ret = apply_all_patches(&state, argc, argv, options);
4756