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 <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>
Nguyễn Thái Ngọc Duy committed
Dec 11, 2018 at 16:35 UTC
a92ec7efe0ad25f1c2047230c0324dcb54ce1cfc
5 files changed
+10
-1
builtin/blame.c
+2
@@ -844,6 +844,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
844
case PARSE_OPT_HELP:
845
case PARSE_OPT_ERROR:
846
exit(129);
847
+ case PARSE_OPT_COMPLETE:
848
+ exit(0);
849
case PARSE_OPT_DONE:
850
if (ctx.argv[0])
851
dashdash_pos = ctx.cpidx;
builtin/shortlog.c
+2
@@ -286,6 +286,8 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
286
case PARSE_OPT_HELP:
287
case PARSE_OPT_ERROR:
288
exit(129);
289
+ case PARSE_OPT_COMPLETE:
290
+ exit(0);
291
case PARSE_OPT_DONE:
292
goto parse_done;
293
}
builtin/update-index.c
+2
@@ -1071,6 +1071,8 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
1071
case PARSE_OPT_HELP:
1072
case PARSE_OPT_ERROR:
1073
exit(129);
1074
+ case PARSE_OPT_COMPLETE:
1075
+ exit(0);
1076
case PARSE_OPT_NON_OPTION:
1077
case PARSE_OPT_DONE:
1078
{
parse-options.c
+3
-1
@@ -516,7 +516,7 @@ static int show_gitcomp(struct parse_opt_ctx_t *ctx,
516
show_negated_gitcomp(original_opts, -1);
517
show_negated_gitcomp(original_opts, nr_noopts);
518
fputc('\n', stdout);
519
- exit(0);
519
+ return PARSE_OPT_COMPLETE;
520
}
521
522
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,
638
case PARSE_OPT_HELP:
639
case PARSE_OPT_ERROR:
640
exit(129);
641
+ case PARSE_OPT_COMPLETE:
642
+ exit(0);
643
case PARSE_OPT_NON_OPTION:
644
case PARSE_OPT_DONE:
645
break;
parse-options.h
+1
@@ -197,6 +197,7 @@ extern int opterror(const struct option *opt, const char *reason, int flags);
197
/*----- incremental advanced APIs -----*/
198
199
enum {
200
+ PARSE_OPT_COMPLETE = -2,
201
PARSE_OPT_HELP = -1,
202
PARSE_OPT_DONE,
203
PARSE_OPT_NON_OPTION,