revert: use the OPT_CMDMODE for parsing, reducing code

The revert command comes with their own implementation of checking for exclusiveness of parameters. Now that the OPT_CMDMODE is in place, we can also rely on that macro instead of cooking that solution for each command itself. This commit also replaces OPT_BOOLEAN, which was deprecated by b04ba2bb (parse-options: deprecate OPT_BOOLEAN, 2011-09-27). Instead OPT_BOOL is used. Signed-off-by: Stefan Beller <stefanbeller@googlemail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed Aug 3, 2013 at 13:51 UTC 84d83f642a680f72f8e81313d605e61bf9efa38f
1 file changed +15 -47
builtin/revert.c
+15 -47
@@ -71,44 +71,19 @@ static void verify_opt_compatible(const char *me, const char *base_opt, ...)
71 die(_("%s: %s cannot be used with %s"), me, this_opt, base_opt);
72 }
73
74 -LAST_ARG_MUST_BE_NULL
75 -static void verify_opt_mutually_compatible(const char *me, ...)
76 -{
77 - const char *opt1, *opt2 = NULL;
78 - va_list ap;
79 -
80 - va_start(ap, me);
81 - while ((opt1 = va_arg(ap, const char *))) {
82 - if (va_arg(ap, int))
83 - break;
84 - }
85 - if (opt1) {
86 - while ((opt2 = va_arg(ap, const char *))) {
87 - if (va_arg(ap, int))
88 - break;
89 - }
90 - }
91 - va_end(ap);
92 -
93 - if (opt1 && opt2)
94 - die(_("%s: %s cannot be used with %s"), me, opt1, opt2);
95 -}
96 -
74 static void parse_args(int argc, const char **argv, struct replay_opts *opts)
75 {
76 const char * const * usage_str = revert_or_cherry_pick_usage(opts);
77 const char *me = action_name(opts);
101 - int remove_state = 0;
102 - int contin = 0;
103 - int rollback = 0;
78 + int cmd = 0;
79 struct option options[] = {
105 - OPT_BOOLEAN(0, "quit", &remove_state, N_("end revert or cherry-pick sequence")),
106 - OPT_BOOLEAN(0, "continue", &contin, N_("resume revert or cherry-pick sequence")),
107 - OPT_BOOLEAN(0, "abort", &rollback, N_("cancel revert or cherry-pick sequence")),
108 - OPT_BOOLEAN('n', "no-commit", &opts->no_commit, N_("don't automatically commit")),
109 - OPT_BOOLEAN('e', "edit", &opts->edit, N_("edit the commit message")),
80 + OPT_CMDMODE(0, "quit", &cmd, N_("end revert or cherry-pick sequence"), 'q'),
81 + OPT_CMDMODE(0, "continue", &cmd, N_("resume revert or cherry-pick sequence"), 'c'),
82 + OPT_CMDMODE(0, "abort", &cmd, N_("cancel revert or cherry-pick sequence"), 'a'),
83 + OPT_BOOL('n', "no-commit", &opts->no_commit, N_("don't automatically commit")),
84 + OPT_BOOL('e', "edit", &opts->edit, N_("edit the commit message")),
85 OPT_NOOP_NOARG('r', NULL),
111 - OPT_BOOLEAN('s', "signoff", &opts->signoff, N_("add Signed-off-by:")),
86 + OPT_BOOL('s', "signoff", &opts->signoff, N_("add Signed-off-by:")),
87 OPT_INTEGER('m', "mainline", &opts->mainline, N_("parent number")),
88 OPT_RERERE_AUTOUPDATE(&opts->allow_rerere_auto),
89 OPT_STRING(0, "strategy", &opts->strategy, N_("strategy"), N_("merge strategy")),
@@ -124,11 +99,11 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
99
100 if (opts->action == REPLAY_PICK) {
101 struct option cp_extra[] = {
127 - OPT_BOOLEAN('x', NULL, &opts->record_origin, N_("append commit name")),
128 - OPT_BOOLEAN(0, "ff", &opts->allow_ff, N_("allow fast-forward")),
129 - OPT_BOOLEAN(0, "allow-empty", &opts->allow_empty, N_("preserve initially empty commits")),
130 - OPT_BOOLEAN(0, "allow-empty-message", &opts->allow_empty_message, N_("allow commits with empty messages")),
131 - OPT_BOOLEAN(0, "keep-redundant-commits", &opts->keep_redundant_commits, N_("keep redundant, empty commits")),
102 + OPT_BOOL('x', NULL, &opts->record_origin, N_("append commit name")),
103 + OPT_BOOL(0, "ff", &opts->allow_ff, N_("allow fast-forward")),
104 + OPT_BOOL(0, "allow-empty", &opts->allow_empty, N_("preserve initially empty commits")),
105 + OPT_BOOL(0, "allow-empty-message", &opts->allow_empty_message, N_("allow commits with empty messages")),
106 + OPT_BOOL(0, "keep-redundant-commits", &opts->keep_redundant_commits, N_("keep redundant, empty commits")),
107 OPT_END(),
108 };
109 if (parse_options_concat(options, ARRAY_SIZE(options), cp_extra))
@@ -139,23 +114,16 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
114 PARSE_OPT_KEEP_ARGV0 |
115 PARSE_OPT_KEEP_UNKNOWN);
116
142 - /* Check for incompatible subcommands */
143 - verify_opt_mutually_compatible(me,
144 - "--quit", remove_state,
145 - "--continue", contin,
146 - "--abort", rollback,
147 - NULL);
148 -
117 /* implies allow_empty */
118 if (opts->keep_redundant_commits)
119 opts->allow_empty = 1;
120
121 /* Set the subcommand */
154 - if (remove_state)
122 + if (cmd == 'q')
123 opts->subcommand = REPLAY_REMOVE_STATE;
156 - else if (contin)
124 + else if (cmd == 'c')
125 opts->subcommand = REPLAY_CONTINUE;
158 - else if (rollback)
126 + else if (cmd == 'a')
127 opts->subcommand = REPLAY_ROLLBACK;
128 else
129 opts->subcommand = REPLAY_NONE;