]> git.ipfire.org Git - thirdparty/git.git/commitdiff
parse-options: fix SunCC compiler warning
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Tue, 11 Dec 2018 15:35:01 +0000 (16:35 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 12 Dec 2018 08:21:33 +0000 (17:21 +0900)
The compiler reports this because show_gitcomp() never actually
returns a value:

    "parse-options.c", line 520: warning: Function has no return
    statement : show_gitcomp

We could shut the compiler up. But instead let's not bury exit() too
deep. Do the same as internal -h handling, return a special error code
and handle the exit() in parse_options() (and other
parse_options_step() callers) instead.

Reported-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/blame.c
builtin/shortlog.c
builtin/update-index.c
parse-options.c
parse-options.h

index 5a0388aaef580e8d3592e1b5b767618fe638ca0b..7e880392a63262078d0dc7291d04e4fa5cf2e4e1 100644 (file)
@@ -844,6 +844,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
                case PARSE_OPT_HELP:
                case PARSE_OPT_ERROR:
                        exit(129);
+               case PARSE_OPT_COMPLETE:
+                       exit(0);
                case PARSE_OPT_DONE:
                        if (ctx.argv[0])
                                dashdash_pos = ctx.cpidx;
index 608d6ba77bdfb4673513444651053d0e8e789020..e9c12bd392db811669ed7d7a0c1664155eee2c6c 100644 (file)
@@ -286,6 +286,8 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
                case PARSE_OPT_HELP:
                case PARSE_OPT_ERROR:
                        exit(129);
+               case PARSE_OPT_COMPLETE:
+                       exit(0);
                case PARSE_OPT_DONE:
                        goto parse_done;
                }
index a8709a26ec4b8bb79cbb20bfa4a7892e063c804d..9d41ba0ad4649fe2a87df2cff84dec3b7e03bdde 100644 (file)
@@ -1071,6 +1071,8 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
                case PARSE_OPT_HELP:
                case PARSE_OPT_ERROR:
                        exit(129);
+               case PARSE_OPT_COMPLETE:
+                       exit(0);
                case PARSE_OPT_NON_OPTION:
                case PARSE_OPT_DONE:
                {
index 7db84227ab34cb33849f4327af58acd925f782c8..92e40994492c3158a5a2e23f2b135354305a27f7 100644 (file)
@@ -516,7 +516,7 @@ static int show_gitcomp(struct parse_opt_ctx_t *ctx,
        show_negated_gitcomp(original_opts, -1);
        show_negated_gitcomp(original_opts, nr_noopts);
        fputc('\n', stdout);
-       exit(0);
+       return PARSE_OPT_COMPLETE;
 }
 
 static int usage_with_options_internal(struct parse_opt_ctx_t *,
@@ -638,6 +638,8 @@ int parse_options(int argc, const char **argv, const char *prefix,
        case PARSE_OPT_HELP:
        case PARSE_OPT_ERROR:
                exit(129);
+       case PARSE_OPT_COMPLETE:
+               exit(0);
        case PARSE_OPT_NON_OPTION:
        case PARSE_OPT_DONE:
                break;
index dd14911a297a5b10705ecb31243c55a7dc2f193c..c433c428283d844ac549d51a124fc8834511381e 100644 (file)
@@ -197,6 +197,7 @@ extern int opterror(const struct option *opt, const char *reason, int flags);
 /*----- incremental advanced APIs -----*/
 
 enum {
+       PARSE_OPT_COMPLETE = -2,
        PARSE_OPT_HELP = -1,
        PARSE_OPT_DONE,
        PARSE_OPT_NON_OPTION,