Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2021-10-08 22:07:39 +0300
committerJunio C Hamano <gitster@pobox.com>2021-10-09 00:13:11 +0300
commit352e761388b5fa41bf40e7c04edf3cb07d888d94 (patch)
tree42e71438337eff815e66e988fa934f92369e99a5 /parse-options.c
parent3f9ab7ccdea91b8312a14d39ce752b4d6685d067 (diff)
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 'parse-options.c')
-rw-r--r--parse-options.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/parse-options.c b/parse-options.c
index 9c8ba96340..f718242096 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -699,13 +699,14 @@ static void free_preprocessed_options(struct option *options)
free(options);
}
-static int usage_with_options_internal(struct parse_opt_ctx_t *,
- const char * const *,
- const struct option *, int, int);
-
-int parse_options_step(struct parse_opt_ctx_t *ctx,
- const struct option *options,
- const char * const usagestr[])
+static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t *,
+ const char * const *,
+ const struct option *,
+ int, int);
+
+enum parse_opt_result parse_options_step(struct parse_opt_ctx_t *ctx,
+ const struct option *options,
+ const char * const usagestr[])
{
int internal_help = !(ctx->flags & PARSE_OPT_NO_INTERNAL_HELP);
@@ -839,10 +840,11 @@ int parse_options_end(struct parse_opt_ctx_t *ctx)
return ctx->cpidx + ctx->argc;
}
-int parse_options(int argc, const char **argv, const char *prefix,
- const struct option *options,
- const char * const usagestr[],
- enum parse_opt_flags flags)
+enum parse_opt_result parse_options(int argc, const char **argv,
+ const char *prefix,
+ const struct option *options,
+ const char * const usagestr[],
+ enum parse_opt_flags flags)
{
struct parse_opt_ctx_t ctx;
struct option *real_options;
@@ -900,9 +902,10 @@ static int usage_argh(const struct option *opts, FILE *outfile)
#define USAGE_OPTS_WIDTH 24
#define USAGE_GAP 2
-static int usage_with_options_internal(struct parse_opt_ctx_t *ctx,
- const char * const *usagestr,
- const struct option *opts, int full, int err)
+static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t *ctx,
+ const char * const *usagestr,
+ const struct option *opts,
+ int full, int err)
{
FILE *outfile = err ? stderr : stdout;
int need_newline;