[PATCH 1/4] OPT__QUIET(): switch from count-up to true bool
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Aug 6, 2013, 23:31 UTC
- Message-ID
- <1375831889-9610-2-git-send-email-gitster@pobox.com>
- In-Reply-To
- <1375831889-9610-1-git-send-email-gitster@pobox.com>
The parseopt parsing for OPT__QUIET() is implemented in terms of OPT_BOOLEAN aka OPT_COUNTUP, so a user _could_ theoretically have used it to make "git cmd -q -q" and "git cmd -q" behave differently.
However, no existing user does so (a summary of the audit at the end). Use OPT_BOOL to make sure our choices are either 0 or 1.
builtin/branch.c:
quiet is passed to create_branch() in branch.c and delete_branches(). The former passes it to setup_tracking() which is used as a bool to decide use of BRANCH_CONFIG_VERBOSE. The latter uses it as a bool to give a single printf() for reporting the names of deleted branches.
builtin/check-ignore.c:
all users of quiet use it as a bool.
builtin/checkout-index.c:
quiet is assigned to state.quite and only the latter is used throughout the program. It is a single-bit bitfield.
builtin/checkout.c:
quiet is stored in checkout_opts.quiet which is of type int. It is used in many places:
- reset_tree() uses it as a bool;
- merge_working_tree() uses it twice, as a bool at both places;
- update_refs_for_switch() uses it three times, all as a bool. It also passes it to create_branch() which we already verified above.
- switch_branches() and switch_unborn_to_new_branch() use it once each, as a bool at both places.
Signed-off-by: Junio C Hamano <gitster@pobox.com> --- parse-options.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/parse-options.h b/parse-options.h index c378b75..f2b01ee 100644 --- a/parse-options.h +++ b/parse-options.h @@ -231,7 +231,7 @@ extern int parse_opt_string_list(const struct option *, const char *, int); extern int parse_opt_noop_cb(const struct option *, const char *, int); #define OPT__VERBOSE(var, h) OPT_BOOLEAN('v', "verbose", (var), (h)) -#define OPT__QUIET(var, h) OPT_BOOLEAN('q', "quiet", (var), (h)) +#define OPT__QUIET(var, h) OPT_BOOL('q', "quiet", (var), (h)) #define OPT__VERBOSITY(var) \ { OPTION_CALLBACK, 'v', "verbose", (var), NULL, N_("be more verbose"), \ PARSE_OPT_NOARG, &parse_opt_verbosity_cb, 0 }, \
-- 1.8.4-rc1-210-gf6d87e2