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 in309be813c9
(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;". Seef41179f16b
(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>
This commit is contained in:
parent
3f9ab7ccde
commit
352e761388
@ -917,6 +917,9 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
|
|||||||
PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0);
|
PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
switch (parse_options_step(&ctx, options, blame_opt_usage)) {
|
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_HELP:
|
||||||
case PARSE_OPT_ERROR:
|
case PARSE_OPT_ERROR:
|
||||||
exit(129);
|
exit(129);
|
||||||
|
@ -374,6 +374,9 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
|
|||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
switch (parse_options_step(&ctx, options, shortlog_usage)) {
|
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_HELP:
|
||||||
case PARSE_OPT_ERROR:
|
case PARSE_OPT_ERROR:
|
||||||
exit(129);
|
exit(129);
|
||||||
|
@ -699,11 +699,12 @@ static void free_preprocessed_options(struct option *options)
|
|||||||
free(options);
|
free(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int usage_with_options_internal(struct parse_opt_ctx_t *,
|
static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t *,
|
||||||
const char * const *,
|
const char * const *,
|
||||||
const struct option *, int, int);
|
const struct option *,
|
||||||
|
int, int);
|
||||||
|
|
||||||
int parse_options_step(struct parse_opt_ctx_t *ctx,
|
enum parse_opt_result parse_options_step(struct parse_opt_ctx_t *ctx,
|
||||||
const struct option *options,
|
const struct option *options,
|
||||||
const char * const usagestr[])
|
const char * const usagestr[])
|
||||||
{
|
{
|
||||||
@ -839,7 +840,8 @@ int parse_options_end(struct parse_opt_ctx_t *ctx)
|
|||||||
return ctx->cpidx + ctx->argc;
|
return ctx->cpidx + ctx->argc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int parse_options(int argc, const char **argv, const char *prefix,
|
enum parse_opt_result parse_options(int argc, const char **argv,
|
||||||
|
const char *prefix,
|
||||||
const struct option *options,
|
const struct option *options,
|
||||||
const char * const usagestr[],
|
const char * const usagestr[],
|
||||||
enum parse_opt_flags flags)
|
enum parse_opt_flags flags)
|
||||||
@ -900,9 +902,10 @@ static int usage_argh(const struct option *opts, FILE *outfile)
|
|||||||
#define USAGE_OPTS_WIDTH 24
|
#define USAGE_OPTS_WIDTH 24
|
||||||
#define USAGE_GAP 2
|
#define USAGE_GAP 2
|
||||||
|
|
||||||
static int usage_with_options_internal(struct parse_opt_ctx_t *ctx,
|
static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t *ctx,
|
||||||
const char * const *usagestr,
|
const char * const *usagestr,
|
||||||
const struct option *opts, int full, int err)
|
const struct option *opts,
|
||||||
|
int full, int err)
|
||||||
{
|
{
|
||||||
FILE *outfile = err ? stderr : stdout;
|
FILE *outfile = err ? stderr : stdout;
|
||||||
int need_newline;
|
int need_newline;
|
||||||
|
@ -211,7 +211,8 @@ struct option {
|
|||||||
* untouched and parse_options() returns the number of options
|
* untouched and parse_options() returns the number of options
|
||||||
* processed.
|
* processed.
|
||||||
*/
|
*/
|
||||||
int parse_options(int argc, const char **argv, const char *prefix,
|
enum parse_opt_result parse_options(int argc, const char **argv,
|
||||||
|
const char *prefix,
|
||||||
const struct option *options,
|
const struct option *options,
|
||||||
const char * const usagestr[],
|
const char * const usagestr[],
|
||||||
enum parse_opt_flags flags);
|
enum parse_opt_flags flags);
|
||||||
@ -274,7 +275,7 @@ void parse_options_start(struct parse_opt_ctx_t *ctx,
|
|||||||
const struct option *options,
|
const struct option *options,
|
||||||
enum parse_opt_flags flags);
|
enum parse_opt_flags flags);
|
||||||
|
|
||||||
int parse_options_step(struct parse_opt_ctx_t *ctx,
|
enum parse_opt_result parse_options_step(struct parse_opt_ctx_t *ctx,
|
||||||
const struct option *options,
|
const struct option *options,
|
||||||
const char * const usagestr[]);
|
const char * const usagestr[]);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user