rebase--interactive2: rewrite the submodes of interactive rebase in C

This rewrites the submodes of interactive rebase (`--continue`,
`--skip`, `--edit-todo`, and `--show-current-patch`) in C.

git-rebase.sh is then modified to call directly git-rebase--interactive2
instead of git-rebase--interactive.sh.

Signed-off-by: Alban Gruin <alban.gruin@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Alban Gruin 2018-09-27 23:56:08 +02:00 committed by Junio C Hamano
parent 53bbcfbde7
commit 0af129b2ed
2 changed files with 86 additions and 10 deletions

View File

@ -134,11 +134,14 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
{
struct replay_opts opts = REPLAY_OPTS_INIT;
unsigned flags = 0, keep_empty = 0, rebase_merges = 0, autosquash = 0;
int abbreviate_commands = 0, rebase_cousins = -1;
int abbreviate_commands = 0, rebase_cousins = -1, ret = 0;
const char *onto = NULL, *onto_name = NULL, *restrict_revision = NULL,
*squash_onto = NULL, *upstream = NULL, *head_name = NULL,
*switch_to = NULL, *cmd = NULL;
char *raw_strategies = NULL;
enum {
NONE = 0, CONTINUE, SKIP, EDIT_TODO, SHOW_CURRENT_PATCH
} command = 0;
struct option options[] = {
OPT_BOOL(0, "ff", &opts.allow_ff, N_("allow fast-forward")),
OPT_BOOL(0, "keep-empty", &keep_empty, N_("keep empty commits")),
@ -151,6 +154,13 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
N_("move commits that begin with squash!/fixup!")),
OPT_BOOL(0, "signoff", &opts.signoff, N_("sign commits")),
OPT__VERBOSE(&opts.verbose, N_("be verbose")),
OPT_CMDMODE(0, "continue", &command, N_("continue rebase"),
CONTINUE),
OPT_CMDMODE(0, "skip", &command, N_("skip commit"), SKIP),
OPT_CMDMODE(0, "edit-todo", &command, N_("edit the todo list"),
EDIT_TODO),
OPT_CMDMODE(0, "show-current-patch", &command, N_("show the current patch"),
SHOW_CURRENT_PATCH),
OPT_STRING(0, "onto", &onto, N_("onto"), N_("onto")),
OPT_STRING(0, "restrict-revision", &restrict_revision,
N_("restrict-revision"), N_("restrict revision")),
@ -198,10 +208,39 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
warning(_("--[no-]rebase-cousins has no effect without "
"--rebase-merges"));
if (!onto && !upstream)
die(_("a base commit must be provided with --upstream or --onto"));
switch (command) {
case NONE:
if (!onto && !upstream)
die(_("a base commit must be provided with --upstream or --onto"));
return !!do_interactive_rebase(&opts, flags, switch_to, upstream, onto,
onto_name, squash_onto, head_name, restrict_revision,
raw_strategies, cmd, autosquash);
ret = do_interactive_rebase(&opts, flags, switch_to, upstream, onto,
onto_name, squash_onto, head_name, restrict_revision,
raw_strategies, cmd, autosquash);
break;
case SKIP: {
struct string_list merge_rr = STRING_LIST_INIT_DUP;
rerere_clear(&merge_rr);
/* fallthrough */
case CONTINUE:
ret = sequencer_continue(&opts);
break;
}
case EDIT_TODO:
ret = edit_todo_list(flags);
break;
case SHOW_CURRENT_PATCH: {
struct child_process cmd = CHILD_PROCESS_INIT;
cmd.git_cmd = 1;
argv_array_pushl(&cmd.args, "show", "REBASE_HEAD", "--", NULL);
ret = run_command(&cmd);
break;
}
default:
BUG("invalid command '%d'", command);
}
return !!ret;
}

View File

@ -200,19 +200,56 @@ finish_rebase () {
rm -rf "$state_dir"
}
run_interactive () {
GIT_CHERRY_PICK_HELP="$resolvemsg"
export GIT_CHERRY_PICK_HELP
test -n "$keep_empty" && keep_empty="--keep-empty"
test -n "$rebase_merges" && rebase_merges="--rebase-merges"
test -n "$rebase_cousins" && rebase_cousins="--rebase-cousins"
test -n "$autosquash" && autosquash="--autosquash"
test -n "$verbose" && verbose="--verbose"
test -n "$force_rebase" && force_rebase="--no-ff"
test -n "$restrict_revision" && \
restrict_revision="--restrict-revision=^$restrict_revision"
test -n "$upstream" && upstream="--upstream=$upstream"
test -n "$onto" && onto="--onto=$onto"
test -n "$squash_onto" && squash_onto="--squash-onto=$squash_onto"
test -n "$onto_name" && onto_name="--onto-name=$onto_name"
test -n "$head_name" && head_name="--head-name=$head_name"
test -n "$strategy" && strategy="--strategy=$strategy"
test -n "$strategy_opts" && strategy_opts="--strategy-opts=$strategy_opts"
test -n "$switch_to" && switch_to="--switch-to=$switch_to"
test -n "$cmd" && cmd="--cmd=$cmd"
test -n "$action" && action="--$action"
exec git rebase--interactive2 "$action" "$keep_empty" "$rebase_merges" "$rebase_cousins" \
"$upstream" "$onto" "$squash_onto" "$restrict_revision" \
"$allow_empty_message" "$autosquash" "$verbose" \
"$force_rebase" "$onto_name" "$head_name" "$strategy" \
"$strategy_opts" "$cmd" "$switch_to" \
"$allow_rerere_autoupdate" "$gpg_sign_opt" "$signoff"
}
run_specific_rebase () {
if [ "$interactive_rebase" = implied ]; then
GIT_EDITOR=:
export GIT_EDITOR
autosquash=
fi
. git-rebase--$type
if test -z "$preserve_merges"
if test -n "$interactive_rebase" -a -z "$preserve_merges"
then
git_rebase__$type
run_interactive
else
git_rebase__preserve_merges
. git-rebase--$type
if test -z "$preserve_merges"
then
git_rebase__$type
else
git_rebase__preserve_merges
fi
fi
ret=$?