apply: make init_apply_state() return -1 instead of exit()ing
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", init_apply_state() should return -1 instead of calling exit(). Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
bb493a5c14
commit
2f5a6d1218
7
apply.c
7
apply.c
@ -55,7 +55,7 @@ int parse_ignorewhitespace_option(struct apply_state *state,
|
||||
return error(_("unrecognized whitespace ignore option '%s'"), option);
|
||||
}
|
||||
|
||||
void init_apply_state(struct apply_state *state,
|
||||
int init_apply_state(struct apply_state *state,
|
||||
const char *prefix,
|
||||
struct lock_file *lock_file)
|
||||
{
|
||||
@ -79,9 +79,10 @@ void init_apply_state(struct apply_state *state,
|
||||
|
||||
git_apply_config();
|
||||
if (apply_default_whitespace && parse_whitespace_option(state, apply_default_whitespace))
|
||||
exit(1);
|
||||
return -1;
|
||||
if (apply_default_ignorewhitespace && parse_ignorewhitespace_option(state, apply_default_ignorewhitespace))
|
||||
exit(1);
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void clear_apply_state(struct apply_state *state)
|
||||
|
2
apply.h
2
apply.h
@ -102,7 +102,7 @@ extern int parse_whitespace_option(struct apply_state *state,
|
||||
extern int parse_ignorewhitespace_option(struct apply_state *state,
|
||||
const char *option);
|
||||
|
||||
extern void init_apply_state(struct apply_state *state,
|
||||
extern int init_apply_state(struct apply_state *state,
|
||||
const char *prefix,
|
||||
struct lock_file *lock_file);
|
||||
extern void clear_apply_state(struct apply_state *state);
|
||||
|
@ -4741,7 +4741,8 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
|
||||
OPT_END()
|
||||
};
|
||||
|
||||
init_apply_state(&state, prefix, &lock_file);
|
||||
if (init_apply_state(&state, prefix, &lock_file))
|
||||
exit(128);
|
||||
|
||||
argc = parse_options(argc, argv, state.prefix, builtin_apply_options,
|
||||
apply_usage, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user