@@ -71,7 +71,7 @@ static void verify_opt_compatible(const char *me, const char *base_opt, ...)
71
71
die (_ ("%s: %s cannot be used with %s" ), me , this_opt , base_opt );
72
72
}
73
73
74
- static void parse_args (int argc , const char * * argv , struct replay_opts * opts )
74
+ static int run_sequencer (int argc , const char * * argv , struct replay_opts * opts )
75
75
{
76
76
const char * const * usage_str = revert_or_cherry_pick_usage (opts );
77
77
const char * me = action_name (opts );
@@ -115,25 +115,15 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
115
115
if (opts -> keep_redundant_commits )
116
116
opts -> allow_empty = 1 ;
117
117
118
- /* Set the subcommand */
119
- if (cmd == 'q' )
120
- opts -> subcommand = REPLAY_REMOVE_STATE ;
121
- else if (cmd == 'c' )
122
- opts -> subcommand = REPLAY_CONTINUE ;
123
- else if (cmd == 'a' )
124
- opts -> subcommand = REPLAY_ROLLBACK ;
125
- else
126
- opts -> subcommand = REPLAY_NONE ;
127
-
128
118
/* Check for incompatible command line arguments */
129
- if (opts -> subcommand != REPLAY_NONE ) {
119
+ if (cmd ) {
130
120
char * this_operation ;
131
- if (opts -> subcommand == REPLAY_REMOVE_STATE )
121
+ if (cmd == 'q' )
132
122
this_operation = "--quit" ;
133
- else if (opts -> subcommand == REPLAY_CONTINUE )
123
+ else if (cmd == 'c' )
134
124
this_operation = "--continue" ;
135
125
else {
136
- assert (opts -> subcommand == REPLAY_ROLLBACK );
126
+ assert (cmd == 'a' );
137
127
this_operation = "--abort" ;
138
128
}
139
129
@@ -156,7 +146,7 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
156
146
"--edit" , opts -> edit ,
157
147
NULL );
158
148
159
- if (opts -> subcommand != REPLAY_NONE ) {
149
+ if (cmd ) {
160
150
opts -> revs = NULL ;
161
151
} else {
162
152
struct setup_revision_opt s_r_opt ;
@@ -174,35 +164,39 @@ static void parse_args(int argc, const char **argv, struct replay_opts *opts)
174
164
175
165
if (argc > 1 )
176
166
usage_with_options (usage_str , options );
167
+
168
+ if (cmd == 'q' )
169
+ return sequencer_remove_state (opts );
170
+ if (cmd == 'c' )
171
+ return sequencer_continue (opts );
172
+ if (cmd == 'a' )
173
+ return sequencer_rollback (opts );
174
+ return sequencer_pick_revisions (opts );
177
175
}
178
176
179
177
int cmd_revert (int argc , const char * * argv , const char * prefix )
180
178
{
181
- struct replay_opts opts ;
179
+ struct replay_opts opts = REPLAY_OPTS_INIT ;
182
180
int res ;
183
181
184
- memset (& opts , 0 , sizeof (opts ));
185
182
if (isatty (0 ))
186
183
opts .edit = 1 ;
187
184
opts .action = REPLAY_REVERT ;
188
185
git_config (git_default_config , NULL );
189
- parse_args (argc , argv , & opts );
190
- res = sequencer_pick_revisions (& opts );
186
+ res = run_sequencer (argc , argv , & opts );
191
187
if (res < 0 )
192
188
die (_ ("revert failed" ));
193
189
return res ;
194
190
}
195
191
196
192
int cmd_cherry_pick (int argc , const char * * argv , const char * prefix )
197
193
{
198
- struct replay_opts opts ;
194
+ struct replay_opts opts = REPLAY_OPTS_INIT ;
199
195
int res ;
200
196
201
- memset (& opts , 0 , sizeof (opts ));
202
197
opts .action = REPLAY_PICK ;
203
198
git_config (git_default_config , NULL );
204
- parse_args (argc , argv , & opts );
205
- res = sequencer_pick_revisions (& opts );
199
+ res = run_sequencer (argc , argv , & opts );
206
200
if (res < 0 )
207
201
die (_ ("cherry-pick failed" ));
208
202
return res ;
0 commit comments