Skip to content

Commit fe786a3

Browse files
agrngitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 49165b6 commit fe786a3

File tree

2 files changed

+84
-8
lines changed

2 files changed

+84
-8
lines changed

builtin/rebase--interactive2.c

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,14 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
134134
{
135135
struct replay_opts opts = REPLAY_OPTS_INIT;
136136
unsigned flags = 0, keep_empty = 0, rebase_merges = 0, autosquash = 0;
137-
int abbreviate_commands = 0, rebase_cousins = -1;
137+
int abbreviate_commands = 0, rebase_cousins = -1, ret = 0;
138138
const char *onto = NULL, *onto_name = NULL, *restrict_revision = NULL,
139139
*squash_onto = NULL, *upstream = NULL, *head_name = NULL,
140140
*switch_to = NULL, *cmd = NULL;
141141
char *raw_strategies = NULL;
142+
enum {
143+
NONE = 0, CONTINUE, SKIP, EDIT_TODO, SHOW_CURRENT_PATCH
144+
} command = 0;
142145
struct option options[] = {
143146
OPT_BOOL(0, "ff", &opts.allow_ff, N_("allow fast-forward")),
144147
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)
151154
N_("move commits that begin with squash!/fixup!")),
152155
OPT_BOOL(0, "signoff", &opts.signoff, N_("sign commits")),
153156
OPT__VERBOSE(&opts.verbose, N_("be verbose")),
157+
OPT_CMDMODE(0, "continue", &command, N_("continue rebase"),
158+
CONTINUE),
159+
OPT_CMDMODE(0, "skip", &command, N_("skip commit"), SKIP),
160+
OPT_CMDMODE(0, "edit-todo", &command, N_("edit the todo list"),
161+
EDIT_TODO),
162+
OPT_CMDMODE(0, "show-current-patch", &command, N_("show the current patch"),
163+
SHOW_CURRENT_PATCH),
154164
OPT_STRING(0, "onto", &onto, N_("onto"), N_("onto")),
155165
OPT_STRING(0, "restrict-revision", &restrict_revision,
156166
N_("restrict-revision"), N_("restrict revision")),
@@ -194,7 +204,36 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
194204
warning(_("--[no-]rebase-cousins has no effect without "
195205
"--rebase-merges"));
196206

197-
return !!do_interactive_rebase(&opts, flags, switch_to, upstream, onto,
198-
onto_name, squash_onto, head_name, restrict_revision,
199-
raw_strategies, cmd, autosquash);
207+
switch (command) {
208+
case NONE:
209+
ret = do_interactive_rebase(&opts, flags, switch_to, upstream, onto,
210+
onto_name, squash_onto, head_name, restrict_revision,
211+
raw_strategies, cmd, autosquash);
212+
break;
213+
case SKIP: {
214+
struct string_list merge_rr = STRING_LIST_INIT_DUP;
215+
216+
rerere_clear(&merge_rr);
217+
/* fallthrough */
218+
case CONTINUE:
219+
ret = sequencer_continue(&opts);
220+
break;
221+
}
222+
case EDIT_TODO:
223+
ret = edit_todo_list(flags);
224+
break;
225+
case SHOW_CURRENT_PATCH: {
226+
struct child_process cmd = CHILD_PROCESS_INIT;
227+
228+
cmd.git_cmd = 1;
229+
argv_array_pushl(&cmd.args, "show", "REBASE_HEAD", "--", NULL);
230+
ret = run_command(&cmd);
231+
232+
break;
233+
}
234+
default:
235+
BUG("invalid command '%d'", command);
236+
}
237+
238+
return !!ret;
200239
}

git-rebase.sh

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,19 +200,56 @@ finish_rebase () {
200200
rm -rf "$state_dir"
201201
}
202202

203+
run_interactive () {
204+
GIT_CHERRY_PICK_HELP="$resolvemsg"
205+
export GIT_CHERRY_PICK_HELP
206+
207+
test -n "$keep_empty" && keep_empty="--keep-empty"
208+
test -n "$rebase_merges" && rebase_merges="--rebase-merges"
209+
test -n "$rebase_cousins" && rebase_cousins="--rebase-cousins"
210+
test -n "$autosquash" && autosquash="--autosquash"
211+
test -n "$verbose" && verbose="--verbose"
212+
test -n "$force_rebase" && force_rebase="--no-ff"
213+
test -n "$restrict_revisions" && \
214+
restrict_revisions="--restrict-revisions=^$restrict_revisions"
215+
test -n "$upstream" && upstream="--upstream=$upstream"
216+
test -n "$onto" && onto="--onto=$onto"
217+
test -n "$squash_onto" && squash_onto="--squash-onto=$squash_onto"
218+
test -n "$onto_name" && onto_name="--onto-name=$onto_name"
219+
test -n "$head_name" && head_name="--head-name=$head_name"
220+
test -n "$strategy" && strategy="--strategy=$strategy"
221+
test -n "$strategy_opts" && strategy_opts="--strategy-opts=$strategy_opts"
222+
test -n "$switch_to" && switch_to="--switch-to=$switch_to"
223+
test -n "$cmd" && cmd="--cmd=$cmd"
224+
test -n "$action" && action="--$action"
225+
226+
exec git rebase--interactive2 "$action" "$keep_empty" "$rebase_merges" "$rebase_cousins" \
227+
"$upstream" "$onto" "$squash_onto" "$restrict_revision" \
228+
"$allow_empty_message" "$autosquash" "$verbose" \
229+
"$force_rebase" "$onto_name" "$head_name" "$strategy" \
230+
"$strategy_opts" "$cmd" "$switch_to" \
231+
"$allow_rerere_autoupdate" "$gpg_sign_opt" "$signoff"
232+
}
233+
203234
run_specific_rebase () {
204235
if [ "$interactive_rebase" = implied ]; then
205236
GIT_EDITOR=:
206237
export GIT_EDITOR
207238
autosquash=
208239
fi
209-
. git-rebase--$type
210240

211-
if test -z "$preserve_merges"
241+
if test -n "$interactive_rebase" -a -z "$preserve_merges"
212242
then
213-
git_rebase__$type
243+
run_interactive
214244
else
215-
git_rebase__preserve_merges
245+
. git-rebase--$type
246+
247+
if test -z "$preserve_merges"
248+
then
249+
git_rebase__$type
250+
else
251+
git_rebase__preserve_merges
252+
fi
216253
fi
217254

218255
ret=$?

0 commit comments

Comments
 (0)