Skip to content

Commit d9f1419

Browse files
committed
non-builtin rebase: use non-builtin interactive backend
We recently converted both the `git rebase` and the `git rebase -i` command from Unix shell scripts to builtins. The former has a safety valve allowing to fall back to the scripted `rebase`, just in case that there is a bug in the builtin `rebase`: setting the config variable `rebase.useBuiltin` to `false` will fall back to using the scripted version. The latter did not have such a safety hatch. Let's reinstate the scripted interactive rebase backend so that `rebase.useBuiltin=false` will not use the builtin interactive rebase, just in case that an end user runs into a bug with the builtin version and needs to get out of the fix really quickly. This is necessary because Git for Windows wants to ship the builtin rebase/interactive rebase earlier than core Git: Git for Windows v2.19.0 will come with the option of a drastically faster (if a lot less battle-tested) `git rebase`/`git rebase -i`. As the file name `git-rebase--interactive` is already in use, let's rename the scripted backend to `git-legacy-rebase--interactive`. A couple of additional touch-ups are needed (such as teaching the builtin `rebase--interactive`, which assumed the role of the `rebase--helper`, to perform the two tricks to skip the unnecessary picks and to generate a new todo list) to make things work again. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 436bdc3 commit d9f1419

File tree

7 files changed

+42
-46
lines changed

7 files changed

+42
-46
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
/git-interpret-trailers
8484
/git-instaweb
8585
/git-legacy-rebase
86+
/git-legacy-rebase--interactive
8687
/git-legacy-stash
8788
/git-log
8889
/git-ls-files

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ SCRIPT_SH += git-request-pull.sh
639639
SCRIPT_SH += git-submodule.sh
640640
SCRIPT_SH += git-web--browse.sh
641641

642+
SCRIPT_LIB += git-legacy-rebase--interactive
642643
SCRIPT_LIB += git-mergetool--lib
643644
SCRIPT_LIB += git-parse-remote
644645
SCRIPT_LIB += git-rebase--am

builtin/rebase--interactive.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
143143
char *raw_strategies = NULL;
144144
enum {
145145
NONE = 0, CONTINUE, SKIP, EDIT_TODO, SHOW_CURRENT_PATCH,
146-
SHORTEN_OIDS, EXPAND_OIDS, CHECK_TODO_LIST, REARRANGE_SQUASH, ADD_EXEC
146+
SHORTEN_OIDS, EXPAND_OIDS, CHECK_TODO_LIST, REARRANGE_SQUASH, ADD_EXEC,
147+
MAKE_SCRIPT, SKIP_UNNECESSARY_PICKS,
147148
} command = 0;
148149
struct option options[] = {
149150
OPT_BOOL(0, "ff", &opts.allow_ff, N_("allow fast-forward")),
@@ -196,6 +197,10 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
196197
OPT_RERERE_AUTOUPDATE(&opts.allow_rerere_auto),
197198
OPT_BOOL(0, "reschedule-failed-exec", &opts.reschedule_failed_exec,
198199
N_("automatically re-schedule any `exec` that fails")),
200+
OPT_CMDMODE(0, "make-script", &command,
201+
N_("make rebase script"), MAKE_SCRIPT),
202+
OPT_CMDMODE(0, "skip-unnecessary-picks", &command,
203+
N_("skip unnecessary picks"), SKIP_UNNECESSARY_PICKS),
199204
OPT_END()
200205
};
201206

@@ -267,6 +272,18 @@ int cmd_rebase__interactive(int argc, const char **argv, const char *prefix)
267272
case ADD_EXEC:
268273
ret = sequencer_add_exec_commands(the_repository, cmd);
269274
break;
275+
case MAKE_SCRIPT:
276+
ret = sequencer_make_script(the_repository,
277+
stdout, argc, argv, flags);
278+
break;
279+
case SKIP_UNNECESSARY_PICKS: {
280+
struct object_id oid;
281+
282+
ret = skip_unnecessary_picks(the_repository, &oid);
283+
if (!ret)
284+
printf("%s\n", oid_to_hex(&oid));
285+
break;
286+
}
270287
default:
271288
BUG("invalid command '%d'", command);
272289
}

git-rebase--interactive.sh renamed to git-legacy-rebase--interactive.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ git_sequence_editor () {
9595
}
9696

9797
expand_todo_ids() {
98-
git rebase--helper --expand-ids
98+
git rebase--interactive --expand-ids
9999
}
100100

101101
collapse_todo_ids() {
102-
git rebase--helper --shorten-ids
102+
git rebase--interactive --shorten-ids
103103
}
104104

105105
# Switch to the branch in $into and notify it in the reflog
@@ -131,12 +131,12 @@ get_missing_commit_check_level () {
131131
initiate_action () {
132132
case "$1" in
133133
continue)
134-
exec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \
134+
exec git rebase--interactive ${force_rebase:+--no-ff} $allow_empty_message \
135135
--continue
136136
;;
137137
skip)
138138
git rerere clear
139-
exec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \
139+
exec git rebase--interactive ${force_rebase:+--no-ff} $allow_empty_message \
140140
--continue
141141
;;
142142
edit-todo)
@@ -207,8 +207,8 @@ init_revisions_and_shortrevisions () {
207207

208208
complete_action() {
209209
test -s "$todo" || echo noop >> "$todo"
210-
test -z "$autosquash" || git rebase--helper --rearrange-squash || exit
211-
test -n "$cmd" && git rebase--helper --add-exec-commands "$cmd"
210+
test -z "$autosquash" || git rebase--interactive --rearrange-squash || exit
211+
test -n "$cmd" && git rebase--interactive --add-exec-commands --cmd "$cmd"
212212

213213
todocount=$(git stripspace --strip-comments <"$todo" | wc -l)
214214
todocount=${todocount##* }
@@ -243,7 +243,7 @@ EOF
243243
has_action "$todo" ||
244244
return 2
245245

246-
git rebase--helper --check-todo-list || {
246+
git rebase--interactive --check-todo-list || {
247247
ret=$?
248248
checkout_onto
249249
exit $ret
@@ -252,12 +252,12 @@ EOF
252252
expand_todo_ids
253253

254254
test -n "$force_rebase" ||
255-
onto="$(git rebase--helper --skip-unnecessary-picks)" ||
255+
onto="$(git rebase--interactive --skip-unnecessary-picks)" ||
256256
die "Could not skip unnecessary pick commands"
257257

258258
checkout_onto
259259
require_clean_work_tree "rebase"
260-
exec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \
260+
exec git rebase--interactive ${force_rebase:+--no-ff} $allow_empty_message \
261261
--continue
262262
}
263263

@@ -273,7 +273,7 @@ git_rebase__interactive () {
273273

274274
init_revisions_and_shortrevisions
275275

276-
git rebase--helper --make-script ${keep_empty:+--keep-empty} \
276+
git rebase--interactive --make-script ${keep_empty:+--keep-empty} \
277277
${rebase_merges:+--rebase-merges} \
278278
${rebase_cousins:+--rebase-cousins} \
279279
$revisions ${restrict_revision+^$restrict_revision} >"$todo" ||

git-legacy-rebase.sh

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -141,38 +141,6 @@ finish_rebase () {
141141
rm -rf "$state_dir"
142142
}
143143

144-
run_interactive () {
145-
GIT_CHERRY_PICK_HELP="$resolvemsg"
146-
export GIT_CHERRY_PICK_HELP
147-
148-
test -n "$keep_empty" && keep_empty="--keep-empty"
149-
test -n "$rebase_merges" && rebase_merges="--rebase-merges"
150-
test -n "$rebase_cousins" && rebase_cousins="--rebase-cousins"
151-
test -n "$autosquash" && autosquash="--autosquash"
152-
test -n "$verbose" && verbose="--verbose"
153-
test -n "$force_rebase" && force_rebase="--no-ff"
154-
test -n "$restrict_revision" && \
155-
restrict_revision="--restrict-revision=^$restrict_revision"
156-
test -n "$upstream" && upstream="--upstream=$upstream"
157-
test -n "$onto" && onto="--onto=$onto"
158-
test -n "$squash_onto" && squash_onto="--squash-onto=$squash_onto"
159-
test -n "$onto_name" && onto_name="--onto-name=$onto_name"
160-
test -n "$head_name" && head_name="--head-name=$head_name"
161-
test -n "$strategy" && strategy="--strategy=$strategy"
162-
test -n "$strategy_opts" && strategy_opts="--strategy-opts=$strategy_opts"
163-
test -n "$switch_to" && switch_to="--switch-to=$switch_to"
164-
test -n "$cmd" && cmd="--cmd=$cmd"
165-
test -n "$action" && action="--$action"
166-
167-
exec git rebase--interactive "$action" "$keep_empty" "$rebase_merges" "$rebase_cousins" \
168-
"$upstream" "$onto" "$squash_onto" "$restrict_revision" \
169-
"$allow_empty_message" "$autosquash" "$verbose" \
170-
"$force_rebase" "$onto_name" "$head_name" "$strategy" \
171-
"$strategy_opts" "$cmd" "$switch_to" \
172-
"$allow_rerere_autoupdate" "$gpg_sign_opt" "$signoff" \
173-
"$reschedule_failed_exec"
174-
}
175-
176144
run_specific_rebase () {
177145
if [ "$interactive_rebase" = implied ]; then
178146
GIT_SEQUENCE_EDITOR=:
@@ -182,7 +150,9 @@ run_specific_rebase () {
182150

183151
if test -n "$interactive_rebase" -a -z "$preserve_merges"
184152
then
185-
run_interactive
153+
. git-legacy-rebase--$type
154+
155+
git_rebase__$type
186156
else
187157
. git-rebase--$type
188158

@@ -202,7 +172,12 @@ run_specific_rebase () {
202172
then
203173
apply_autostash &&
204174
rm -rf "$state_dir" &&
205-
die "Nothing to do"
175+
if test -n "$interactive_rebase" -a -z "$preserve_merges"
176+
then
177+
die "error: nothing to do"
178+
else
179+
die "Nothing to do"
180+
fi
206181
fi
207182
exit $ret
208183
}

sequencer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4793,7 +4793,7 @@ static int rewrite_file(const char *path, const char *buf, size_t len)
47934793
}
47944794

47954795
/* skip picking commits whose parents are unchanged */
4796-
static int skip_unnecessary_picks(struct repository *r, struct object_id *output_oid)
4796+
int skip_unnecessary_picks(struct repository *r, struct object_id *output_oid)
47974797
{
47984798
const char *todo_file = rebase_path_todo();
47994799
struct strbuf buf = STRBUF_INIT;

sequencer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,5 @@ int read_author_script(const char *path, char **name, char **email, char **date,
144144
void parse_strategy_opts(struct replay_opts *opts, char *raw_opts);
145145
int write_basic_state(struct replay_opts *opts, const char *head_name,
146146
const char *onto, const char *orig_head);
147+
148+
int skip_unnecessary_picks(struct repository *r, struct object_id *output_oid);

0 commit comments

Comments
 (0)