]> git.ipfire.org Git - thirdparty/git.git/commitdiff
parse-options.c: use "enum parse_opt_result" for parse_nodash_opt()
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Wed, 10 Nov 2021 01:27:04 +0000 (02:27 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 10 Nov 2021 23:17:29 +0000 (15:17 -0800)
Change the parse_nodash_opt() function to use "enum
parse_opt_result". In 352e761388b (parse-options.[ch]: consistently
use "enum parse_opt_result", 2021-10-08) its only caller
parse_options_step() started using that return type, and the
get_value() which will be called and return from it uses the same
enum.

Let's do the same here so that this function always returns an "enum
parse_opt_result" value.

We could go for either PARSE_OPT_HELP (-2) or PARSE_OPT_ERROR (-1)
here. The reason we ended up with "-2" is that in code added in
07fe54db3cd (parse-opt: do not print errors on unknown options, return
"-2" instead., 2008-06-23) we used that value in a meaningful way.

Then in 51a9949eda7 (parseopt: add PARSE_OPT_NODASH, 2009-05-07) the
use of "-2" was seemingly copy/pasted from parse_long_opt(), which was
the function immediately above the parse_nodash_opt() function added
in that commit.

Since we only care about whether the return value here is non-zero
let's use the more generic PARSE_OPT_ERROR.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
parse-options.c

index e7885844be513f3d2b12396515fe1d3b53c7bbef..386b870b646a32ca66ad71ce05cb66b0263c30db 100644 (file)
@@ -404,8 +404,9 @@ is_abbreviated:
        return PARSE_OPT_UNKNOWN;
 }
 
-static int parse_nodash_opt(struct parse_opt_ctx_t *p, const char *arg,
-                           const struct option *options)
+static enum parse_opt_result parse_nodash_opt(struct parse_opt_ctx_t *p,
+                                             const char *arg,
+                                             const struct option *options)
 {
        const struct option *all_opts = options;
 
@@ -415,7 +416,7 @@ static int parse_nodash_opt(struct parse_opt_ctx_t *p, const char *arg,
                if (options->short_name == arg[0] && arg[1] == '\0')
                        return get_value(p, options, all_opts, OPT_SHORT);
        }
-       return -2;
+       return PARSE_OPT_ERROR;
 }
 
 static void check_typos(const char *arg, const struct option *options)