Skip to content

Commit e6b722d

Browse files
committed
tag: use OPT_CMDMODE
This is just a demonstration of how the code would look like; I do not think it is particularly easier to read than before myself. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1158826 commit e6b722d

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

builtin/tag.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -436,18 +436,18 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
436436
struct ref_lock *lock;
437437
struct create_tag_options opt;
438438
char *cleanup_arg = NULL;
439-
int annotate = 0, force = 0, lines = -1, list = 0,
440-
delete = 0, verify = 0;
439+
int annotate = 0, force = 0, lines = -1;
440+
int cmdmode = 0;
441441
const char *msgfile = NULL, *keyid = NULL;
442442
struct msg_arg msg = { 0, STRBUF_INIT };
443443
struct commit_list *with_commit = NULL;
444444
struct option options[] = {
445-
OPT_BOOLEAN('l', "list", &list, N_("list tag names")),
445+
OPT_CMDMODE('l', "list", &cmdmode, N_("list tag names"), 'l'),
446446
{ OPTION_INTEGER, 'n', NULL, &lines, N_("n"),
447447
N_("print <n> lines of each tag message"),
448448
PARSE_OPT_OPTARG, NULL, 1 },
449-
OPT_BOOLEAN('d', "delete", &delete, N_("delete tags")),
450-
OPT_BOOLEAN('v', "verify", &verify, N_("verify tags")),
449+
OPT_CMDMODE('d', "delete", &cmdmode, N_("delete tags"), 'd'),
450+
OPT_CMDMODE('v', "verify", &cmdmode, N_("verify tags"), 'v'),
451451

452452
OPT_GROUP(N_("Tag creation options")),
453453
OPT_BOOLEAN('a', "annotate", &annotate,
@@ -489,22 +489,19 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
489489
}
490490
if (opt.sign)
491491
annotate = 1;
492-
if (argc == 0 && !(delete || verify))
493-
list = 1;
492+
if (argc == 0 && !cmdmode)
493+
cmdmode = 'l';
494494

495-
if ((annotate || msg.given || msgfile || force) &&
496-
(list || delete || verify))
495+
if ((annotate || msg.given || msgfile || force) && (cmdmode != 0))
497496
usage_with_options(git_tag_usage, options);
498497

499-
if (list + delete + verify > 1)
500-
usage_with_options(git_tag_usage, options);
501498
finalize_colopts(&colopts, -1);
502-
if (list && lines != -1) {
499+
if (cmdmode == 'l' && lines != -1) {
503500
if (explicitly_enable_column(colopts))
504501
die(_("--column and -n are incompatible"));
505502
colopts = 0;
506503
}
507-
if (list) {
504+
if (cmdmode == 'l') {
508505
int ret;
509506
if (column_active(colopts)) {
510507
struct column_options copts;
@@ -523,9 +520,9 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
523520
die(_("--contains option is only allowed with -l."));
524521
if (points_at.nr)
525522
die(_("--points-at option is only allowed with -l."));
526-
if (delete)
523+
if (cmdmode == 'd')
527524
return for_each_tag_name(argv, delete_tag);
528-
if (verify)
525+
if (cmdmode == 'v')
529526
return for_each_tag_name(argv, verify_tag);
530527

531528
if (msg.given || msgfile) {

0 commit comments

Comments
 (0)