Skip to content

Commit 4a8bc98

Browse files
phillipwoodgitster
authored andcommitted
rebase -m: cleanup --strategy-option handling
When handling "--strategy-option" rebase collects the commands into a struct string_list, then concatenates them into a string, prepending "--" to each one before splitting the string and removing the "--" prefix. 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. The tests for a bad strategy option are adjusted now that parse_strategy_opts() is no-longer called when starting a rebase. The fact that it only errors out when running "git rebase --continue" is a mixed blessing but the next commit will fix the root cause of the parsing problem so lets not worry about that here. Reviewed-by: Elijah Newren <[email protected]> Signed-off-by: Phillip Wood <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fb60b9f commit 4a8bc98

File tree

4 files changed

+19
-24
lines changed

4 files changed

+19
-24
lines changed

builtin/rebase.c

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ struct rebase_options {
117117
struct string_list exec;
118118
int allow_empty_message;
119119
int rebase_merges, rebase_cousins;
120-
char *strategy, *strategy_opts;
120+
char *strategy;
121+
struct string_list strategy_opts;
121122
struct strbuf git_format_patch_opt;
122123
int reschedule_failed_exec;
123124
int reapply_cherry_picks;
@@ -143,6 +144,7 @@ struct rebase_options {
143144
.config_autosquash = -1, \
144145
.update_refs = -1, \
145146
.config_update_refs = -1, \
147+
.strategy_opts = STRING_LIST_INIT_NODUP,\
146148
}
147149

148150
static struct replay_opts get_replay_opts(const struct rebase_options *opts)
@@ -176,8 +178,8 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts)
176178
replay.default_strategy = NULL;
177179
}
178180

179-
if (opts->strategy_opts)
180-
parse_strategy_opts(&replay, opts->strategy_opts);
181+
for (size_t i = 0; i < opts->strategy_opts.nr; i++)
182+
strvec_push(&replay.xopts, opts->strategy_opts.items[i].string);
181183

182184
if (opts->squash_onto) {
183185
oidcpy(&replay.squash_onto, opts->squash_onto);
@@ -1013,7 +1015,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
10131015
int ignore_whitespace = 0;
10141016
const char *gpg_sign = NULL;
10151017
const char *rebase_merges = NULL;
1016-
struct string_list strategy_options = STRING_LIST_INIT_NODUP;
10171018
struct object_id squash_onto;
10181019
char *squash_onto_name = NULL;
10191020
char *keep_base_onto_name = NULL;
@@ -1122,7 +1123,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
11221123
N_("use 'merge-base --fork-point' to refine upstream")),
11231124
OPT_STRING('s', "strategy", &options.strategy,
11241125
N_("strategy"), N_("use the given merge strategy")),
1125-
OPT_STRING_LIST('X', "strategy-option", &strategy_options,
1126+
OPT_STRING_LIST('X', "strategy-option", &options.strategy_opts,
11261127
N_("option"),
11271128
N_("pass the argument through to the merge "
11281129
"strategy")),
@@ -1436,23 +1437,13 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
14361437
} else {
14371438
/* REBASE_MERGE */
14381439
if (ignore_whitespace) {
1439-
string_list_append(&strategy_options,
1440+
string_list_append(&options.strategy_opts,
14401441
"ignore-space-change");
14411442
}
14421443
}
14431444

1444-
if (strategy_options.nr) {
1445-
int i;
1446-
1447-
if (!options.strategy)
1448-
options.strategy = "ort";
1449-
1450-
strbuf_reset(&buf);
1451-
for (i = 0; i < strategy_options.nr; i++)
1452-
strbuf_addf(&buf, " --%s",
1453-
strategy_options.items[i].string);
1454-
options.strategy_opts = xstrdup(buf.buf);
1455-
}
1445+
if (options.strategy_opts.nr && !options.strategy)
1446+
options.strategy = "ort";
14561447

14571448
if (options.strategy) {
14581449
options.strategy = xstrdup(options.strategy);
@@ -1827,10 +1818,9 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
18271818
free(options.gpg_sign_opt);
18281819
string_list_clear(&options.exec, 0);
18291820
free(options.strategy);
1830-
free(options.strategy_opts);
1821+
string_list_clear(&options.strategy_opts, 0);
18311822
strbuf_release(&options.git_format_patch_opt);
18321823
free(squash_onto_name);
18331824
free(keep_base_onto_name);
1834-
string_list_clear(&strategy_options, 0);
18351825
return !!ret;
18361826
}

sequencer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2913,7 +2913,7 @@ static int populate_opts_cb(const char *key, const char *value, void *data)
29132913
return 0;
29142914
}
29152915

2916-
void parse_strategy_opts(struct replay_opts *opts, char *raw_opts)
2916+
static void parse_strategy_opts(struct replay_opts *opts, char *raw_opts)
29172917
{
29182918
int i;
29192919
int count;

sequencer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,6 @@ int read_oneliner(struct strbuf *buf,
252252
const char *path, unsigned flags);
253253
int read_author_script(const char *path, char **name, char **email, char **date,
254254
int allow_missing);
255-
void parse_strategy_opts(struct replay_opts *opts, char *raw_opts);
256255
int write_basic_state(struct replay_opts *opts, const char *head_name,
257256
struct commit *onto, const struct object_id *orig_head);
258257
void sequencer_post_commit_cleanup(struct repository *r, int verbose);

t/t3436-rebase-more-options.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,25 @@ test_expect_success 'setup' '
4141
'
4242

4343
test_expect_success 'bad -X <strategy-option> arguments: unclosed quote' '
44+
test_when_finished "test_might_fail git rebase --abort" &&
4445
cat >expect <<-\EOF &&
4546
fatal: could not split '\''--bad'\'': unclosed quote
4647
EOF
47-
test_expect_code 128 git rebase -X"bad argument\"" side main >out 2>actual &&
48+
GIT_SEQUENCE_EDITOR="echo break >" \
49+
git rebase -i -X"bad argument\"" side main &&
50+
test_expect_code 128 git rebase --continue >out 2>actual &&
4851
test_must_be_empty out &&
4952
test_cmp expect actual
5053
'
5154

5255
test_expect_success 'bad -X <strategy-option> arguments: bad escape' '
56+
test_when_finished "test_might_fail git rebase --abort" &&
5357
cat >expect <<-\EOF &&
5458
fatal: could not split '\''--bad'\'': cmdline ends with \
5559
EOF
56-
test_expect_code 128 git rebase -X"bad escape \\" side main >out 2>actual &&
60+
GIT_SEQUENCE_EDITOR="echo break >" \
61+
git rebase -i -X"bad escape \\" side main &&
62+
test_expect_code 128 git rebase --continue >out 2>actual &&
5763
test_must_be_empty out &&
5864
test_cmp expect actual
5965
'

0 commit comments

Comments
 (0)