From: Nguyễn Thái Ngọc Duy Date: Tue, 11 Dec 2018 15:35:01 +0000 (+0100) Subject: parse-options: fix SunCC compiler warning X-Git-Tag: v2.20.1~3^2 X-Git-Url: http://git.ipfire.org/?p=thirdparty%2Fgit.git;a=commitdiff_plain;h=a92ec7efe0ad25f1c2047230c0324dcb54ce1cfc parse-options: fix SunCC compiler warning 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 Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- diff --git a/builtin/blame.c b/builtin/blame.c index 5a0388aaef..7e880392a6 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -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; diff --git a/builtin/shortlog.c b/builtin/shortlog.c index 608d6ba77b..e9c12bd392 100644 --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@ -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; } diff --git a/builtin/update-index.c b/builtin/update-index.c index a8709a26ec..9d41ba0ad4 100644 --- a/builtin/update-index.c +++ b/builtin/update-index.c @@ -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: { diff --git a/parse-options.c b/parse-options.c index 7db84227ab..92e4099449 100644 --- a/parse-options.c +++ b/parse-options.c @@ -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; diff --git a/parse-options.h b/parse-options.h index dd14911a29..c433c42828 100644 --- a/parse-options.h +++ b/parse-options.h @@ -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,