Skip to content

Commit e57d2c5

Browse files
phillipwoodgitster
authored andcommitted
rebase: cleanup "--exec" option handling
When handling "--exec" rebase collects the commands into a struct string_list, then prepends "exec " to each command creating a multi line string and finally splits that string back into a list of commands. This is an artifact of the scripted rebase and the need to support "rebase --preserve-merges". Now that "--preserve-merges" no-longer exists we can cleanup the way the argument is handled. There is no need to add the "exec " prefix to the commands as that is added by todo_list_to_strbuf(). Signed-off-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a38d39a commit e57d2c5

File tree

2 files changed

+13
-36
lines changed

2 files changed

+13
-36
lines changed

builtin/rebase.c

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ struct rebase_options {
113113
int autostash;
114114
int committer_date_is_author_date;
115115
int ignore_date;
116-
char *cmd;
116+
struct string_list exec;
117117
int allow_empty_message;
118118
int rebase_merges, rebase_cousins;
119119
char *strategy, *strategy_opts;
@@ -131,6 +131,7 @@ struct rebase_options {
131131
.default_backend = "merge", \
132132
.flags = REBASE_NO_QUIET, \
133133
.git_am_opts = STRVEC_INIT, \
134+
.exec = STRING_LIST_INIT_NODUP, \
134135
.git_format_patch_opt = STRBUF_INIT, \
135136
.fork_point = -1, \
136137
}
@@ -243,25 +244,13 @@ static int init_basic_state(struct replay_opts *opts, const char *head_name,
243244
return write_basic_state(opts, head_name, onto, orig_head);
244245
}
245246

246-
static void split_exec_commands(const char *cmd, struct string_list *commands)
247-
{
248-
if (cmd && *cmd) {
249-
string_list_split(commands, cmd, '\n', -1);
250-
251-
/* rebase.c adds a new line to cmd after every command,
252-
* so here the last command is always empty */
253-
string_list_remove_empty_items(commands, 0);
254-
}
255-
}
256-
257247
static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
258248
{
259249
int ret;
260250
char *revisions = NULL, *shortrevisions = NULL;
261251
struct strvec make_script_args = STRVEC_INIT;
262252
struct todo_list todo_list = TODO_LIST_INIT;
263253
struct replay_opts replay = get_replay_opts(opts);
264-
struct string_list commands = STRING_LIST_INIT_DUP;
265254

266255
if (get_revision_ranges(opts->upstream, opts->onto, &opts->orig_head->object.oid,
267256
&revisions, &shortrevisions))
@@ -297,14 +286,12 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
297286
&todo_list))
298287
BUG("unusable todo list");
299288

300-
split_exec_commands(opts->cmd, &commands);
301289
ret = complete_action(the_repository, &replay, flags,
302290
shortrevisions, opts->onto_name, opts->onto,
303-
&opts->orig_head->object.oid, &commands,
291+
&opts->orig_head->object.oid, &opts->exec,
304292
opts->autosquash, opts->update_refs, &todo_list);
305293
}
306294

307-
string_list_clear(&commands, 0);
308295
free(revisions);
309296
free(shortrevisions);
310297
todo_list_release(&todo_list);
@@ -1032,7 +1019,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
10321019
struct object_id branch_base;
10331020
int ignore_whitespace = 0;
10341021
const char *gpg_sign = NULL;
1035-
struct string_list exec = STRING_LIST_INIT_NODUP;
10361022
const char *rebase_merges = NULL;
10371023
struct string_list strategy_options = STRING_LIST_INIT_NODUP;
10381024
struct object_id squash_onto;
@@ -1127,7 +1113,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
11271113
N_("GPG-sign commits"),
11281114
PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
11291115
OPT_AUTOSTASH(&options.autostash),
1130-
OPT_STRING_LIST('x', "exec", &exec, N_("exec"),
1116+
OPT_STRING_LIST('x', "exec", &options.exec, N_("exec"),
11311117
N_("add exec lines after each commit of the "
11321118
"editable list")),
11331119
OPT_BOOL_F(0, "allow-empty-message",
@@ -1250,7 +1236,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
12501236
if (trace2_is_enabled()) {
12511237
if (is_merge(&options))
12521238
trace2_cmd_mode("interactive");
1253-
else if (exec.nr)
1239+
else if (options.exec.nr)
12541240
trace2_cmd_mode("interactive-exec");
12551241
else
12561242
trace2_cmd_mode(action_names[options.action]);
@@ -1378,7 +1364,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
13781364

13791365
if ((options.flags & REBASE_INTERACTIVE_EXPLICIT) ||
13801366
(options.action != ACTION_NONE) ||
1381-
(exec.nr > 0) ||
1367+
(options.exec.nr > 0) ||
13821368
options.autosquash) {
13831369
allow_preemptive_ff = 0;
13841370
}
@@ -1402,8 +1388,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
14021388
}
14031389
}
14041390

1405-
for (i = 0; i < exec.nr; i++)
1406-
if (check_exec_cmd(exec.items[i].string))
1391+
for (i = 0; i < options.exec.nr; i++)
1392+
if (check_exec_cmd(options.exec.items[i].string))
14071393
exit(1);
14081394

14091395
if (!(options.flags & REBASE_NO_QUIET))
@@ -1422,17 +1408,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
14221408
if (gpg_sign)
14231409
options.gpg_sign_opt = xstrfmt("-S%s", gpg_sign);
14241410

1425-
if (exec.nr) {
1426-
int i;
1427-
1411+
if (options.exec.nr)
14281412
imply_merge(&options, "--exec");
14291413

1430-
strbuf_reset(&buf);
1431-
for (i = 0; i < exec.nr; i++)
1432-
strbuf_addf(&buf, "exec %s\n", exec.items[i].string);
1433-
options.cmd = xstrdup(buf.buf);
1434-
}
1435-
14361414
if (rebase_merges) {
14371415
if (!*rebase_merges)
14381416
; /* default mode; do nothing */
@@ -1543,7 +1521,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
15431521
if (options.empty == EMPTY_UNSPECIFIED) {
15441522
if (options.flags & REBASE_INTERACTIVE_EXPLICIT)
15451523
options.empty = EMPTY_ASK;
1546-
else if (exec.nr > 0)
1524+
else if (options.exec.nr > 0)
15471525
options.empty = EMPTY_KEEP;
15481526
else
15491527
options.empty = EMPTY_DROP;
@@ -1831,11 +1809,10 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
18311809
free(options.head_name);
18321810
strvec_clear(&options.git_am_opts);
18331811
free(options.gpg_sign_opt);
1834-
free(options.cmd);
1812+
string_list_clear(&options.exec, 0);
18351813
free(options.strategy);
18361814
strbuf_release(&options.git_format_patch_opt);
18371815
free(squash_onto_name);
1838-
string_list_clear(&exec, 0);
18391816
string_list_clear(&strategy_options, 0);
18401817
return !!ret;
18411818
}

sequencer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5745,8 +5745,8 @@ static void todo_list_add_exec_commands(struct todo_list *todo_list,
57455745

57465746
base_items[i].command = TODO_EXEC;
57475747
base_items[i].offset_in_buf = base_offset;
5748-
base_items[i].arg_offset = base_offset + strlen("exec ");
5749-
base_items[i].arg_len = command_len - strlen("exec ");
5748+
base_items[i].arg_offset = base_offset;
5749+
base_items[i].arg_len = command_len;
57505750

57515751
base_offset += command_len + 1;
57525752
}

0 commit comments

Comments
 (0)