diff options
author | Ævar Arnfjörð Bjarmason <avarab@gmail.com> | 2021-10-08 21:07:39 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2021-10-08 14:13:11 -0700 |
commit | 352e761388b5fa41bf40e7c04edf3cb07d888d94 (patch) | |
tree | 42e71438337eff815e66e988fa934f92369e99a5 /builtin | |
parent | parse-options.[ch]: consistently use "enum parse_opt_flags" (diff) | |
download | tgif-352e761388b5fa41bf40e7c04edf3cb07d888d94.tar.xz |
parse-options.[ch]: consistently use "enum parse_opt_result"
Use the "enum parse_opt_result" instead of an "int flags" as the
return value of the applicable functions in parse-options.c.
This will help catch future bugs, such as the missing "case" arms in
the two existing users of the API in "blame.c" and "shortlog.c". A
third caller in 309be813c9b (update-index: migrate to parse-options
API, 2010-12-01) was already checking for these.
As can be seen when trying to sort through the deluge of warnings
produced when compiling this with CC=g++ (mostly unrelated to this
change) we're not consistently using "enum parse_opt_result" even now,
i.e. we'll return error() and "return 0;". See f41179f16ba
(parse-options: avoid magic return codes, 2019-01-27) for a commit
which started changing some of that.
I'm not doing any more of that exhaustive migration here, and it's
probably not worthwhile past the point of being able to check "enum
parse_opt_result" in switch().
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/blame.c | 3 | ||||
-rw-r--r-- | builtin/shortlog.c | 3 |
2 files changed, 6 insertions, 0 deletions
diff --git a/builtin/blame.c b/builtin/blame.c index 641523ff9a..9273fb222d 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -917,6 +917,9 @@ int cmd_blame(int argc, const char **argv, const char *prefix) PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0); for (;;) { switch (parse_options_step(&ctx, options, blame_opt_usage)) { + case PARSE_OPT_NON_OPTION: + case PARSE_OPT_UNKNOWN: + break; case PARSE_OPT_HELP: case PARSE_OPT_ERROR: exit(129); diff --git a/builtin/shortlog.c b/builtin/shortlog.c index 3e7ab1ca82..e7f7af5de3 100644 --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@ -374,6 +374,9 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix) for (;;) { switch (parse_options_step(&ctx, options, shortlog_usage)) { + case PARSE_OPT_NON_OPTION: + case PARSE_OPT_UNKNOWN: + break; case PARSE_OPT_HELP: case PARSE_OPT_ERROR: exit(129); |