apply: make init_apply_state() return -1 instead of exit()ing
authorChristian Couder <christian.couder@gmail.com>
Mon, 8 Aug 2016 21:03:08 +0000 (23:03 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 11 Aug 2016 19:41:47 +0000 (12:41 -0700)
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>
apply.c
apply.h
builtin/apply.c
diff --git a/apply.c b/apply.c
index c858ca4be9aab155a280d659b134fab8f98c2fab..6e0e9928396b0f86ed52d411aa455ead3a390621 100644 (file)
--- a/apply.c
+++ b/apply.c
@@ -55,9 +55,9 @@ int parse_ignorewhitespace_option(struct apply_state *state,
        return error(_("unrecognized whitespace ignore option '%s'"), option);
 }
 
-void init_apply_state(struct apply_state *state,
-                     const char *prefix,
-                     struct lock_file *lock_file)
+int init_apply_state(struct apply_state *state,
+                    const char *prefix,
+                    struct lock_file *lock_file)
 {
        memset(state, 0, sizeof(*state));
        state->prefix = prefix;
@@ -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)
diff --git a/apply.h b/apply.h
index 08c0a252cbe898f087107123ea10bb142f8d43b2..e18a18a96438bff6990e574cb9c31fc6a5a42d4e 100644 (file)
--- a/apply.h
+++ b/apply.h
@@ -102,9 +102,9 @@ 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,
-                            const char *prefix,
-                            struct lock_file *lock_file);
+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);
 
 #endif
index bb6ff7703820aa2c68e23c67ca44b9954ca25135..61fd3163638f892f238c9e7f8140cf1f207db3bd 100644 (file)
@@ -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);