rebase -i: use struct rebase_options in do_interactive_rebase()
All the parameters that are passed to do_interactive_rebase() apart from `flags` are already in `struct rebase_options` so there is no need to pass them separately. Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Phillip Wood committed
Apr 17, 2019 at 15:30 UTC
0ea0847ef0f6d548fe3a3c6720f99323408b2a50
1 file changed
+36
-33
builtin/rebase.c
+36
-33
@@ -113,6 +113,8 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts)
113
replay.reschedule_failed_exec = opts->reschedule_failed_exec;
114
replay.gpg_sign = xstrdup_or_null(opts->gpg_sign_opt);
115
replay.strategy = opts->strategy;
116
+ if (opts->strategy_opts)
117
+ parse_strategy_opts(&replay, opts->strategy_opts);
118
119
return replay;
120
}
@@ -262,44 +264,50 @@ static int init_basic_state(struct replay_opts *opts, const char *head_name,
264
return write_basic_state(opts, head_name, onto, orig_head);
265
}
266
265
-static int do_interactive_rebase(struct replay_opts *opts, unsigned flags,
266
- const char *switch_to, struct commit *upstream,
267
- struct commit *onto, const char *onto_name,
268
- struct object_id *squash_onto, const char *head_name,
269
- struct commit *restrict_revision, char *raw_strategies,
270
- struct string_list *commands, unsigned autosquash)
267
+static void split_exec_commands(const char *cmd, struct string_list *commands)
268
+{
269
+ if (cmd && *cmd) {
270
+ string_list_split(commands, cmd, '\n', -1);
271
+
272
+ /* rebase.c adds a new line to cmd after every command,
273
+ * so here the last command is always empty */
274
+ string_list_remove_empty_items(commands, 0);
275
+ }
276
+}
277
+
278
+static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
279
{
280
int ret;
281
const char *head_hash = NULL;
282
char *revisions = NULL, *shortrevisions = NULL;
283
struct argv_array make_script_args = ARGV_ARRAY_INIT;
284
struct todo_list todo_list = TODO_LIST_INIT;
285
+ struct replay_opts replay = get_replay_opts(opts);
286
+ struct string_list commands = STRING_LIST_INIT_DUP;
287
278
- if (prepare_branch_to_be_rebased(the_repository, opts, switch_to))
288
+ if (prepare_branch_to_be_rebased(the_repository, &replay,
289
+ opts->switch_to))
290
return -1;
291
281
- if (get_revision_ranges(upstream, onto, &head_hash,
292
+ if (get_revision_ranges(opts->upstream, opts->onto, &head_hash,
293
&revisions, &shortrevisions))
294
return -1;
295
285
- if (raw_strategies)
286
- parse_strategy_opts(opts, raw_strategies);
287
-
288
- if (init_basic_state(opts, head_name, onto, head_hash)) {
296
+ if (init_basic_state(&replay, opts->head_name, opts->onto, head_hash)) {
297
free(revisions);
298
free(shortrevisions);
299
300
return -1;
301
}
302
295
- if (!upstream && squash_onto)
303
+ if (!opts->upstream && opts->squash_onto)
304
write_file(path_squash_onto(), "%s\n",
297
- oid_to_hex(squash_onto));
305
+ oid_to_hex(opts->squash_onto));
306
307
argv_array_pushl(&make_script_args, "", revisions, NULL);
300
- if (restrict_revision)
308
+ if (opts->restrict_revision)
309
argv_array_push(&make_script_args,
302
- oid_to_hex(&restrict_revision->object.oid));
310
+ oid_to_hex(&opts->restrict_revision->object.oid));
311
312
ret = sequencer_make_script(the_repository, &todo_list.buf,
313
make_script_args.argc, make_script_args.argv,
@@ -313,10 +321,13 @@ static int do_interactive_rebase(struct replay_opts *opts, unsigned flags,
321
&todo_list))
322
BUG("unusable todo list");
323
316
- ret = complete_action(the_repository, opts, flags, shortrevisions, onto_name,
317
- onto, head_hash, commands, autosquash, &todo_list);
324
+ split_exec_commands(opts->cmd, &commands);
325
+ ret = complete_action(the_repository, &replay, flags,
326
+ shortrevisions, opts->onto_name, opts->onto, head_hash,
327
+ &commands, opts->autosquash, &todo_list);
328
}
329
330
+ string_list_clear(&commands, 0);
331
free(revisions);
332
free(shortrevisions);
333
todo_list_release(&todo_list);
@@ -336,7 +347,6 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
347
unsigned flags = 0;
348
int abbreviate_commands = 0, ret = 0;
349
struct object_id squash_onto = null_oid;
339
- struct string_list commands = STRING_LIST_INIT_DUP;
350
enum {
351
NONE = 0, CONTINUE, SKIP, EDIT_TODO, SHOW_CURRENT_PATCH,
352
SHORTEN_OIDS, EXPAND_OIDS, CHECK_TODO_LIST, REARRANGE_SQUASH, ADD_EXEC
@@ -424,23 +434,12 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
434
warning(_("--[no-]rebase-cousins has no effect without "
435
"--rebase-merges"));
436
427
- if (opts.cmd && *opts.cmd) {
428
- string_list_split(&commands, opts.cmd, '\n', -1);
429
-
430
- /* rebase.c adds a new line to cmd after every command,
431
- * so here the last command is always empty */
432
- string_list_remove_empty_items(&commands, 0);
433
- }
434
-
437
switch (command) {
438
case NONE: {
437
- struct replay_opts replay_opts = get_replay_opts(&opts);
439
if (!opts.onto && !opts.upstream)
440
die(_("a base commit must be provided with --upstream or --onto"));
441
441
- ret = do_interactive_rebase(&replay_opts, flags, opts.switch_to, opts.upstream, opts.onto,
442
- opts.onto_name, opts.squash_onto, opts.head_name, opts.restrict_revision,
443
- opts.strategy_opts, &commands, opts.autosquash);
442
+ ret = do_interactive_rebase(&opts, flags);
443
break;
444
}
445
case SKIP: {
@@ -477,14 +476,18 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
476
case REARRANGE_SQUASH:
477
ret = rearrange_squash_in_todo_file();
478
break;
480
- case ADD_EXEC:
479
+ case ADD_EXEC: {
480
+ struct string_list commands = STRING_LIST_INIT_DUP;
481
+
482
+ split_exec_commands(opts.cmd, &commands);
483
ret = add_exec_commands(&commands);
484
+ string_list_clear(&commands, 0);
485
break;
486
+ }
487
default:
488
BUG("invalid command '%d'", command);
489
}
490
487
- string_list_clear(&commands, 0);
491
return !!ret;
492
}
493