builtin/apply: make parse_whitespace_option() 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, parse_whitespace_option() 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 aaf6c447aabb16ed71345d5baf8b12ced26c5c95
1 file changed +12 -11
builtin/apply.c
+12 -11
@@ -27,34 +27,34 @@ static const char * const apply_usage[] = {
27 NULL
28 };
29
30 -static void parse_whitespace_option(struct apply_state *state, const char *option)
30 +static int parse_whitespace_option(struct apply_state *state, const char *option)
31 {
32 if (!option) {
33 state->ws_error_action = warn_on_ws_error;
34 - return;
34 + return 0;
35 }
36 if (!strcmp(option, "warn")) {
37 state->ws_error_action = warn_on_ws_error;
38 - return;
38 + return 0;
39 }
40 if (!strcmp(option, "nowarn")) {
41 state->ws_error_action = nowarn_ws_error;
42 - return;
42 + return 0;
43 }
44 if (!strcmp(option, "error")) {
45 state->ws_error_action = die_on_ws_error;
46 - return;
46 + return 0;
47 }
48 if (!strcmp(option, "error-all")) {
49 state->ws_error_action = die_on_ws_error;
50 state->squelch_whitespace_errors = 0;
51 - return;
51 + return 0;
52 }
53 if (!strcmp(option, "strip") || !strcmp(option, "fix")) {
54 state->ws_error_action = correct_ws_error;
55 - return;
55 + return 0;
56 }
57 - die(_("unrecognized whitespace option '%s'"), option);
57 + return error(_("unrecognized whitespace option '%s'"), option);
58 }
59
60 static void parse_ignorewhitespace_option(struct apply_state *state,
@@ -4589,7 +4589,8 @@ static int option_parse_whitespace(const struct option *opt,
4589 {
4590 struct apply_state *state = opt->value;
4591 state->whitespace_option = arg;
4592 - parse_whitespace_option(state, arg);
4592 + if (parse_whitespace_option(state, arg))
4593 + exit(1);
4594 return 0;
4595 }
4596
@@ -4626,8 +4627,8 @@ static void init_apply_state(struct apply_state *state,
4627 strbuf_init(&state->root, 0);
4628
4629 git_apply_config();
4629 - if (apply_default_whitespace)
4630 - parse_whitespace_option(state, apply_default_whitespace);
4630 + if (apply_default_whitespace && parse_whitespace_option(state, apply_default_whitespace))
4631 + exit(1);
4632 if (apply_default_ignorewhitespace)
4633 parse_ignorewhitespace_option(state, apply_default_ignorewhitespace);
4634 }