Skip to content

Commit a92ec7e

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6da2d95 commit a92ec7e

File tree

5 files changed

+10
-1
lines changed

5 files changed

+10
-1
lines changed

builtin/blame.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,8 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
844844
case PARSE_OPT_HELP:
845845
case PARSE_OPT_ERROR:
846846
exit(129);
847+
case PARSE_OPT_COMPLETE:
848+
exit(0);
847849
case PARSE_OPT_DONE:
848850
if (ctx.argv[0])
849851
dashdash_pos = ctx.cpidx;

builtin/shortlog.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
286286
case PARSE_OPT_HELP:
287287
case PARSE_OPT_ERROR:
288288
exit(129);
289+
case PARSE_OPT_COMPLETE:
290+
exit(0);
289291
case PARSE_OPT_DONE:
290292
goto parse_done;
291293
}

builtin/update-index.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,8 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
10711071
case PARSE_OPT_HELP:
10721072
case PARSE_OPT_ERROR:
10731073
exit(129);
1074+
case PARSE_OPT_COMPLETE:
1075+
exit(0);
10741076
case PARSE_OPT_NON_OPTION:
10751077
case PARSE_OPT_DONE:
10761078
{

parse-options.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ static int show_gitcomp(struct parse_opt_ctx_t *ctx,
516516
show_negated_gitcomp(original_opts, -1);
517517
show_negated_gitcomp(original_opts, nr_noopts);
518518
fputc('\n', stdout);
519-
exit(0);
519+
return PARSE_OPT_COMPLETE;
520520
}
521521

522522
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,
638638
case PARSE_OPT_HELP:
639639
case PARSE_OPT_ERROR:
640640
exit(129);
641+
case PARSE_OPT_COMPLETE:
642+
exit(0);
641643
case PARSE_OPT_NON_OPTION:
642644
case PARSE_OPT_DONE:
643645
break;

parse-options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ extern int opterror(const struct option *opt, const char *reason, int flags);
197197
/*----- incremental advanced APIs -----*/
198198

199199
enum {
200+
PARSE_OPT_COMPLETE = -2,
200201
PARSE_OPT_HELP = -1,
201202
PARSE_OPT_DONE,
202203
PARSE_OPT_NON_OPTION,

0 commit comments

Comments
 (0)