From: Pierre Habouzit <madcoder@debian.org>
To: gitster@pobox.com
Cc: git@vger.kernel.org, Pierre Habouzit <madcoder@debian.org>
Subject: [PATCH 4/7] parse-options: let OPT__ABBREV ignore arguments.
Date: Mon, 17 Dec 2007 19:23:14 +0100 [thread overview]
Message-ID: <1197915797-30679-5-git-send-email-madcoder@debian.org> (raw)
In-Reply-To: <1197915797-30679-4-git-send-email-madcoder@debian.org>
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
parse-options.c | 16 +++++++++-------
1 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/parse-options.c b/parse-options.c
index f3f0f2a..679a963 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -359,19 +359,21 @@ void usage_with_options(const char * const *usagestr,
int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int flags)
{
- int v;
-
- if (!arg) {
- v = flags & PARSE_OPT_UNSET ? 0 : DEFAULT_ABBREV;
- } else {
+ int v = flags & PARSE_OPT_UNSET ? 0 : DEFAULT_ABBREV;
+ if (arg) {
v = strtol(arg, (char **)&arg, 10);
- if (*arg)
+ if (*arg) {
+ if (flags & PARSE_OPT_MAY_IGN) {
+ *(int *)opt->value = DEFAULT_ABBREV;
+ return PARSE_OPT_IGNORE;
+ }
return opterror(opt, "expects a numerical value", 0);
+ }
if (v && v < MINIMUM_ABBREV)
v = MINIMUM_ABBREV;
else if (v > 40)
v = 40;
}
- *(int *)(opt->value) = v;
+ *(int *)opt->value = v;
return 0;
}
--
1.5.4.rc0.1148.ga3ab1-dirty
next prev parent reply other threads:[~2007-12-17 18:24 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-12-17 18:23 [proposal] make parse-options nicer wrt optional arguments (supersedes all my recent posts on the matter) Pierre Habouzit
2007-12-17 18:23 ` [PATCH 1/7] parse-options: Make callbacks take flags instead of boolean `unset` Pierre Habouzit
2007-12-17 18:23 ` [PATCH 2/7] parse-options: allow callbacks to ignore arguments they don't need to use Pierre Habouzit
2007-12-17 18:23 ` [PATCH 3/7] parse-options: Let the integer/string cases be callbacks as well Pierre Habouzit
2007-12-17 18:23 ` Pierre Habouzit [this message]
2007-12-17 18:23 ` [PATCH 5/7] parse-options: Add a gitcli(5) man page Pierre Habouzit
2007-12-17 18:23 ` [PATCH 6/7] parse-options: have a `use default value` wildcard Pierre Habouzit
2007-12-17 18:23 ` [PATCH 7/7] git-tag: fix -l switch handling regression Pierre Habouzit
2007-12-17 18:56 ` Pierre Habouzit
2007-12-17 19:03 ` Pierre Habouzit
2007-12-17 20:13 ` Junio C Hamano
2007-12-18 2:00 ` [PATCH 5/7] parse-options: Add a gitcli(5) man page Wayne Davison
2007-12-17 18:54 ` [PATCH 1/7] parse-options: Make callbacks take flags instead of boolean `unset` Pierre Habouzit
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=1197915797-30679-5-git-send-email-madcoder@debian.org \
--to=madcoder@debian.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.