summaryrefslogtreecommitdiff
path: root/builtin/rebase.c
diff options
context:
space:
mode:
Diffstat (limited to 'builtin/rebase.c')
-rw-r--r--builtin/rebase.c41
1 files changed, 24 insertions, 17 deletions
diff --git a/builtin/rebase.c b/builtin/rebase.c
index 0466d9414a..4506bae768 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -83,7 +83,7 @@ static const char *action_names[] = {
struct rebase_options {
enum rebase_type type;
enum empty_type empty;
- const char *default_backend;
+ char *default_backend;
const char *state_dir;
struct commit *upstream;
const char *upstream_name;
@@ -135,7 +135,7 @@ struct rebase_options {
.type = REBASE_UNSPECIFIED, \
.empty = EMPTY_UNSPECIFIED, \
.keep_empty = 1, \
- .default_backend = "merge", \
+ .default_backend = xstrdup("merge"), \
.flags = REBASE_NO_QUIET, \
.git_am_opts = STRVEC_INIT, \
.exec = STRING_LIST_INIT_NODUP, \
@@ -151,6 +151,19 @@ struct rebase_options {
.strategy_opts = STRING_LIST_INIT_NODUP,\
}
+static void rebase_options_release(struct rebase_options *opts)
+{
+ free(opts->default_backend);
+ free(opts->reflog_action);
+ free(opts->head_name);
+ strvec_clear(&opts->git_am_opts);
+ free(opts->gpg_sign_opt);
+ string_list_clear(&opts->exec, 0);
+ free(opts->strategy);
+ string_list_clear(&opts->strategy_opts, 0);
+ strbuf_release(&opts->git_format_patch_opt);
+}
+
static struct replay_opts get_replay_opts(const struct rebase_options *opts)
{
struct replay_opts replay = REPLAY_OPTS_INIT;
@@ -796,6 +809,7 @@ static int rebase_config(const char *var, const char *value,
}
if (!strcmp(var, "rebase.backend")) {
+ FREE_AND_NULL(opts->default_backend);
return git_config_string(&opts->default_backend, var, value);
}
@@ -1047,6 +1061,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
{
struct rebase_options options = REBASE_OPTIONS_INIT;
const char *branch_name;
+ const char *strategy_opt = NULL;
int ret, flags, total_argc, in_progress = 0;
int keep_base = 0;
int ok_to_skip_pre_rebase = 0;
@@ -1161,7 +1176,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
PARSE_OPT_OPTARG, parse_opt_rebase_merges),
OPT_BOOL(0, "fork-point", &options.fork_point,
N_("use 'merge-base --fork-point' to refine upstream")),
- OPT_STRING('s', "strategy", &options.strategy,
+ OPT_STRING('s', "strategy", &strategy_opt,
N_("strategy"), N_("use the given merge strategy")),
OPT_STRING_LIST('X', "strategy-option", &options.strategy_opts,
N_("option"),
@@ -1470,13 +1485,12 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
}
}
- if (options.strategy_opts.nr && !options.strategy)
- options.strategy = "ort";
-
- if (options.strategy) {
- options.strategy = xstrdup(options.strategy);
+ if (strategy_opt)
+ options.strategy = xstrdup(strategy_opt);
+ else if (options.strategy_opts.nr && !options.strategy)
+ options.strategy = xstrdup("ort");
+ if (options.strategy)
imply_merge(&options, "--strategy");
- }
if (options.root && !options.onto_name)
imply_merge(&options, "--root without --onto");
@@ -1833,14 +1847,7 @@ run_rebase:
cleanup:
strbuf_release(&buf);
strbuf_release(&revisions);
- free(options.reflog_action);
- free(options.head_name);
- strvec_clear(&options.git_am_opts);
- free(options.gpg_sign_opt);
- string_list_clear(&options.exec, 0);
- free(options.strategy);
- string_list_clear(&options.strategy_opts, 0);
- strbuf_release(&options.git_format_patch_opt);
+ rebase_options_release(&options);
free(squash_onto_name);
free(keep_base_onto_name);
return !!ret;