Skip to content

Commit 4741edd

Browse files
stefanbellergitster
authored andcommitted
Remove deprecated OPTION_BOOLEAN for parsing arguments
As of b04ba2b OPTION_BOOLEAN was deprecated. This commit removes all occurrences of OPTION_BOOLEAN. In b04ba2b Junio suggested to replace it with either OPTION_SET_INT or OPTION_COUNTUP instead. However a pattern, which occurred often with the OPTION_BOOLEAN was a hidden boolean parameter. So I defined OPT_HIDDEN_BOOL as an additional possible parse option in parse-options.h to make life easy. The OPT_HIDDEN_BOOL was used in checkout, clone, commit, show-ref. The only exception, where there was need to fiddle with OPTION_SET_INT was log and notes. However in these two files there is also a pattern, so we could think of introducing OPT_NONEG_BOOL. Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e6b722d commit 4741edd

File tree

7 files changed

+19
-25
lines changed

7 files changed

+19
-25
lines changed

builtin/checkout.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,9 +1073,8 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
10731073
OPT_BOOLEAN('p', "patch", &opts.patch_mode, N_("select hunks interactively")),
10741074
OPT_BOOL(0, "ignore-skip-worktree-bits", &opts.ignore_skipworktree,
10751075
N_("do not limit pathspecs to sparse entries only")),
1076-
{ OPTION_BOOLEAN, 0, "guess", &dwim_new_local_branch, NULL,
1077-
N_("second guess 'git checkout no-such-branch'"),
1078-
PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
1076+
OPT_HIDDEN_BOOL(0, "guess", &dwim_new_local_branch,
1077+
N_("second guess 'git checkout no-such-branch'")),
10791078
OPT_END(),
10801079
};
10811080

builtin/clone.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,9 @@ static struct option builtin_clone_options[] = {
6464
N_("force progress reporting")),
6565
OPT_BOOLEAN('n', "no-checkout", &option_no_checkout,
6666
N_("don't create a checkout")),
67-
OPT_BOOLEAN(0, "bare", &option_bare, N_("create a bare repository")),
68-
{ OPTION_BOOLEAN, 0, "naked", &option_bare, NULL,
69-
N_("create a bare repository"),
70-
PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
67+
OPT_BOOL(0, "bare", &option_bare, N_("create a bare repository")),
68+
OPT_HIDDEN_BOOL(0, "naked", &option_bare,
69+
N_("create a bare repository")),
7170
OPT_BOOLEAN(0, "mirror", &option_mirror,
7271
N_("create a mirror repository (implies bare)")),
7372
OPT_BOOL('l', "local", &option_local,

builtin/commit.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,12 +1448,10 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
14481448
{ OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, N_("mode"), N_("show untracked files, optional modes: all, normal, no. (Default: all)"), PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
14491449
/* end commit contents options */
14501450

1451-
{ OPTION_BOOLEAN, 0, "allow-empty", &allow_empty, NULL,
1452-
N_("ok to record an empty change"),
1453-
PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
1454-
{ OPTION_BOOLEAN, 0, "allow-empty-message", &allow_empty_message, NULL,
1455-
N_("ok to record a change with an empty message"),
1456-
PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
1451+
OPT_HIDDEN_BOOL(0, "allow-empty", &allow_empty,
1452+
N_("ok to record an empty change")),
1453+
OPT_HIDDEN_BOOL(0, "allow-empty-message", &allow_empty_message,
1454+
N_("ok to record a change with an empty message")),
14571455

14581456
OPT_END()
14591457
};

builtin/log.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,9 +1183,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
11831183
N_("don't output binary diffs")),
11841184
OPT_BOOLEAN(0, "ignore-if-in-upstream", &ignore_if_in_upstream,
11851185
N_("don't include a patch matching a commit upstream")),
1186-
{ OPTION_BOOLEAN, 'p', "no-stat", &use_patch_format, NULL,
1186+
{ OPTION_SET_INT, 'p', "no-stat", &use_patch_format, NULL,
11871187
N_("show patch format instead of default (patch + stat)"),
1188-
PARSE_OPT_NONEG | PARSE_OPT_NOARG },
1188+
PARSE_OPT_NONEG | PARSE_OPT_NOARG, NULL, 1},
11891189
OPT_GROUP(N_("Messaging")),
11901190
{ OPTION_CALLBACK, 0, "add-header", NULL, N_("header"),
11911191
N_("add email header"), 0, header_callback },

builtin/notes.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -739,13 +739,13 @@ static int merge(int argc, const char **argv, const char *prefix)
739739
N_("resolve notes conflicts using the given strategy "
740740
"(manual/ours/theirs/union/cat_sort_uniq)")),
741741
OPT_GROUP(N_("Committing unmerged notes")),
742-
{ OPTION_BOOLEAN, 0, "commit", &do_commit, NULL,
742+
{ OPTION_SET_INT, 0, "commit", &do_commit, NULL,
743743
N_("finalize notes merge by committing unmerged notes"),
744-
PARSE_OPT_NOARG | PARSE_OPT_NONEG },
744+
PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 1},
745745
OPT_GROUP(N_("Aborting notes merge resolution")),
746-
{ OPTION_BOOLEAN, 0, "abort", &do_abort, NULL,
746+
{ OPTION_SET_INT, 0, "abort", &do_abort, NULL,
747747
N_("abort notes merge"),
748-
PARSE_OPT_NOARG | PARSE_OPT_NONEG },
748+
PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, 1},
749749
OPT_END()
750750
};
751751

builtin/show-ref.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,8 @@ static const struct option show_ref_options[] = {
169169
OPT_BOOLEAN(0, "heads", &heads_only, N_("only show heads (can be combined with tags)")),
170170
OPT_BOOLEAN(0, "verify", &verify, N_("stricter reference checking, "
171171
"requires exact ref path")),
172-
{ OPTION_BOOLEAN, 'h', NULL, &show_head, NULL,
173-
N_("show the HEAD reference, even if it would be filtered out"),
174-
PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
172+
OPT_HIDDEN_BOOL('h', NULL, &show_head,
173+
N_("show the HEAD reference, even if it would be filtered out")),
175174
OPT_BOOLEAN(0, "head", &show_head,
176175
N_("show the HEAD reference, even if it would be filtered out")),
177176
OPT_BOOLEAN('d', "dereference", &deref_tags,

parse-options.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ enum parse_opt_type {
2222
OPTION_FILENAME
2323
};
2424

25-
/* Deprecated synonym */
26-
#define OPTION_BOOLEAN OPTION_COUNTUP
27-
2825
enum parse_opt_flags {
2926
PARSE_OPT_KEEP_DASHDASH = 1,
3027
PARSE_OPT_STOP_AT_NON_OPTION = 2,
@@ -129,6 +126,8 @@ struct option {
129126
#define OPT_SET_INT(s, l, v, h, i) { OPTION_SET_INT, (s), (l), (v), NULL, \
130127
(h), PARSE_OPT_NOARG, NULL, (i) }
131128
#define OPT_BOOL(s, l, v, h) OPT_SET_INT(s, l, v, h, 1)
129+
#define OPT_HIDDEN_BOOL(s, l, v, h) { OPTION_SET_INT, (s), (l), (v), NULL, \
130+
(h), PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, 1}
132131
#define OPT_SET_PTR(s, l, v, h, p) { OPTION_SET_PTR, (s), (l), (v), NULL, \
133132
(h), PARSE_OPT_NOARG, NULL, (p) }
134133
#define OPT_CMDMODE(s, l, v, h, i) { OPTION_CMDMODE, (s), (l), (v), NULL, \

0 commit comments

Comments
 (0)