1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-10-30 22:07:53 +01:00

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>
This commit is contained in:
Christian Couder 2016-08-08 23:03:05 +02:00 committed by Junio C Hamano
parent dae197f753
commit aaf6c447aa

View file

@ -27,34 +27,34 @@ static const char * const apply_usage[] = {
NULL NULL
}; };
static void parse_whitespace_option(struct apply_state *state, const char *option) static int parse_whitespace_option(struct apply_state *state, const char *option)
{ {
if (!option) { if (!option) {
state->ws_error_action = warn_on_ws_error; state->ws_error_action = warn_on_ws_error;
return; return 0;
} }
if (!strcmp(option, "warn")) { if (!strcmp(option, "warn")) {
state->ws_error_action = warn_on_ws_error; state->ws_error_action = warn_on_ws_error;
return; return 0;
} }
if (!strcmp(option, "nowarn")) { if (!strcmp(option, "nowarn")) {
state->ws_error_action = nowarn_ws_error; state->ws_error_action = nowarn_ws_error;
return; return 0;
} }
if (!strcmp(option, "error")) { if (!strcmp(option, "error")) {
state->ws_error_action = die_on_ws_error; state->ws_error_action = die_on_ws_error;
return; return 0;
} }
if (!strcmp(option, "error-all")) { if (!strcmp(option, "error-all")) {
state->ws_error_action = die_on_ws_error; state->ws_error_action = die_on_ws_error;
state->squelch_whitespace_errors = 0; state->squelch_whitespace_errors = 0;
return; return 0;
} }
if (!strcmp(option, "strip") || !strcmp(option, "fix")) { if (!strcmp(option, "strip") || !strcmp(option, "fix")) {
state->ws_error_action = correct_ws_error; state->ws_error_action = correct_ws_error;
return; return 0;
} }
die(_("unrecognized whitespace option '%s'"), option); return error(_("unrecognized whitespace option '%s'"), option);
} }
static void parse_ignorewhitespace_option(struct apply_state *state, static void parse_ignorewhitespace_option(struct apply_state *state,
@ -4589,7 +4589,8 @@ static int option_parse_whitespace(const struct option *opt,
{ {
struct apply_state *state = opt->value; struct apply_state *state = opt->value;
state->whitespace_option = arg; state->whitespace_option = arg;
parse_whitespace_option(state, arg); if (parse_whitespace_option(state, arg))
exit(1);
return 0; return 0;
} }
@ -4626,8 +4627,8 @@ static void init_apply_state(struct apply_state *state,
strbuf_init(&state->root, 0); strbuf_init(&state->root, 0);
git_apply_config(); git_apply_config();
if (apply_default_whitespace) if (apply_default_whitespace && parse_whitespace_option(state, apply_default_whitespace))
parse_whitespace_option(state, apply_default_whitespace); exit(1);
if (apply_default_ignorewhitespace) if (apply_default_ignorewhitespace)
parse_ignorewhitespace_option(state, apply_default_ignorewhitespace); parse_ignorewhitespace_option(state, apply_default_ignorewhitespace);
} }