Skip to content

Commit 2f5a6d1

Browse files
chriscoolgitster
authored andcommitted
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>
1 parent bb493a5 commit 2f5a6d1

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

apply.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ int parse_ignorewhitespace_option(struct apply_state *state,
5555
return error(_("unrecognized whitespace ignore option '%s'"), option);
5656
}
5757

58-
void init_apply_state(struct apply_state *state,
59-
const char *prefix,
60-
struct lock_file *lock_file)
58+
int init_apply_state(struct apply_state *state,
59+
const char *prefix,
60+
struct lock_file *lock_file)
6161
{
6262
memset(state, 0, sizeof(*state));
6363
state->prefix = prefix;
@@ -79,9 +79,10 @@ void init_apply_state(struct apply_state *state,
7979

8080
git_apply_config();
8181
if (apply_default_whitespace && parse_whitespace_option(state, apply_default_whitespace))
82-
exit(1);
82+
return -1;
8383
if (apply_default_ignorewhitespace && parse_ignorewhitespace_option(state, apply_default_ignorewhitespace))
84-
exit(1);
84+
return -1;
85+
return 0;
8586
}
8687

8788
void clear_apply_state(struct apply_state *state)

apply.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ extern int parse_whitespace_option(struct apply_state *state,
102102
extern int parse_ignorewhitespace_option(struct apply_state *state,
103103
const char *option);
104104

105-
extern void init_apply_state(struct apply_state *state,
106-
const char *prefix,
107-
struct lock_file *lock_file);
105+
extern int init_apply_state(struct apply_state *state,
106+
const char *prefix,
107+
struct lock_file *lock_file);
108108
extern void clear_apply_state(struct apply_state *state);
109109

110110
#endif

builtin/apply.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4741,7 +4741,8 @@ int cmd_apply(int argc, const char **argv, const char *prefix)
47414741
OPT_END()
47424742
};
47434743

4744-
init_apply_state(&state, prefix, &lock_file);
4744+
if (init_apply_state(&state, prefix, &lock_file))
4745+
exit(128);
47454746

47464747
argc = parse_options(argc, argv, state.prefix, builtin_apply_options,
47474748
apply_usage, 0);

0 commit comments

Comments
 (0)