From: "René Scharfe" <l.s.r@web.de>
To: Git List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>,
Jonathan Nieder <jrnieder@gmail.com>
Subject: [PATCH 1/5] parse-options: deduplicate parse_options_usage() calls
Date: Tue, 17 Nov 2015 11:25:14 +0100 [thread overview]
Message-ID: <564B008A.9000102@web.de> (raw)
In-Reply-To: <564AFF32.1030406@web.de>
Avoid long lines and repeating parse_options_usage() calls with their
duplicate parameters by providing labels with speaking names to jump to.
Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
parse-options.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/parse-options.c b/parse-options.c
index 3eceba4..f0b6d9b 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -435,6 +435,7 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
const char * const usagestr[])
{
int internal_help = !(ctx->flags & PARSE_OPT_NO_INTERNAL_HELP);
+ int err = 0;
/* we must reset ->opt, unknown short option leave it dangling */
ctx->opt = NULL;
@@ -454,10 +455,10 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
if (arg[1] != '-') {
ctx->opt = arg + 1;
if (internal_help && *ctx->opt == 'h')
- return parse_options_usage(ctx, usagestr, options, 0);
+ goto show_usage;
switch (parse_short_opt(ctx, options)) {
case -1:
- return parse_options_usage(ctx, usagestr, options, 1);
+ goto show_usage_error;
case -2:
if (ctx->opt)
check_typos(arg + 1, options);
@@ -467,10 +468,10 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
check_typos(arg + 1, options);
while (ctx->opt) {
if (internal_help && *ctx->opt == 'h')
- return parse_options_usage(ctx, usagestr, options, 0);
+ goto show_usage;
switch (parse_short_opt(ctx, options)) {
case -1:
- return parse_options_usage(ctx, usagestr, options, 1);
+ goto show_usage_error;
case -2:
/* fake a short option thing to hide the fact that we may have
* started to parse aggregated stuff
@@ -496,10 +497,10 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
if (internal_help && !strcmp(arg + 2, "help-all"))
return usage_with_options_internal(ctx, usagestr, options, 1, 0);
if (internal_help && !strcmp(arg + 2, "help"))
- return parse_options_usage(ctx, usagestr, options, 0);
+ goto show_usage;
switch (parse_long_opt(ctx, arg + 2, options)) {
case -1:
- return parse_options_usage(ctx, usagestr, options, 1);
+ goto show_usage_error;
case -2:
goto unknown;
}
@@ -511,6 +512,11 @@ unknown:
ctx->opt = NULL;
}
return PARSE_OPT_DONE;
+
+ show_usage_error:
+ err = 1;
+ show_usage:
+ return parse_options_usage(ctx, usagestr, options, err);
}
int parse_options_end(struct parse_opt_ctx_t *ctx)
--
2.6.3
next prev parent reply other threads:[~2015-11-17 10:25 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-17 10:19 [PATCH 0/5] parse-options: allow -h as a short option René Scharfe
2015-11-17 10:25 ` René Scharfe [this message]
2015-11-17 10:25 ` [PATCH 2/5] parse-options: inline parse_options_usage() at its only remaining caller René Scharfe
2015-11-17 10:25 ` [PATCH 3/5] parse-options: allow -h as a short option René Scharfe
2015-11-17 10:25 ` [PATCH 4/5] grep: stop using PARSE_OPT_NO_INTERNAL_HELP René Scharfe
2015-11-17 10:26 ` [PATCH 5/5] show-ref: " René Scharfe
2015-12-04 18:40 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=564B008A.9000102@web.de \
--to=l.s.r@web.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@gmail.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).