Skip to content

Commit 27c499b

Browse files
winksavillegitster
authored andcommitted
rebase: extract functions out of git_rebase__interactive
The extracted functions are: - initiate_action - setup_reflog_action - init_basic_state - init_revisions_and_shortrevisions - complete_action Used by git_rebase__interactive Signed-off-by: Wink Saville <[email protected]> Helped-by: Junio C Hamano <[email protected]> Helped-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d48f97a commit 27c499b

File tree

1 file changed

+111
-71
lines changed

1 file changed

+111
-71
lines changed

git-rebase--interactive.sh

Lines changed: 111 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -740,8 +740,20 @@ get_missing_commit_check_level () {
740740
printf '%s' "$check_level" | tr 'A-Z' 'a-z'
741741
}
742742

743-
git_rebase__interactive () {
744-
case "$action" in
743+
# Initiate an action. If the cannot be any
744+
# further action it may exec a command
745+
# or exit and not return.
746+
#
747+
# TODO: Consider a cleaner return model so it
748+
# never exits and always return 0 if process
749+
# is complete.
750+
#
751+
# Parameter 1 is the action to initiate.
752+
#
753+
# Returns 0 if the action was able to complete
754+
# and if 1 if further processing is required.
755+
initiate_action () {
756+
case "$1" in
745757
continue)
746758
if test ! -d "$rewritten"
747759
then
@@ -836,8 +848,13 @@ To continue rebase after editing, run:
836848
show-current-patch)
837849
exec git show REBASE_HEAD --
838850
;;
851+
*)
852+
return 1 # continue
853+
;;
839854
esac
855+
}
840856

857+
setup_reflog_action () {
841858
comment_for_reflog start
842859

843860
if test ! -z "$switch_to"
@@ -848,13 +865,102 @@ To continue rebase after editing, run:
848865

849866
comment_for_reflog start
850867
fi
868+
}
851869

870+
init_basic_state () {
852871
orig_head=$(git rev-parse --verify HEAD) || die "$(gettext "No HEAD?")"
853872
mkdir -p "$state_dir" || die "$(eval_gettext "Could not create temporary \$state_dir")"
854873
rm -f "$(git rev-parse --git-path REBASE_HEAD)"
855874

856875
: > "$state_dir"/interactive || die "$(gettext "Could not mark as interactive")"
857876
write_basic_state
877+
}
878+
879+
init_revisions_and_shortrevisions () {
880+
shorthead=$(git rev-parse --short $orig_head)
881+
shortonto=$(git rev-parse --short $onto)
882+
if test -z "$rebase_root"
883+
# this is now equivalent to ! -z "$upstream"
884+
then
885+
shortupstream=$(git rev-parse --short $upstream)
886+
revisions=$upstream...$orig_head
887+
shortrevisions=$shortupstream..$shorthead
888+
else
889+
revisions=$onto...$orig_head
890+
shortrevisions=$shorthead
891+
fi
892+
}
893+
894+
complete_action() {
895+
test -s "$todo" || echo noop >> "$todo"
896+
test -z "$autosquash" || git rebase--helper --rearrange-squash || exit
897+
test -n "$cmd" && git rebase--helper --add-exec-commands "$cmd"
898+
899+
todocount=$(git stripspace --strip-comments <"$todo" | wc -l)
900+
todocount=${todocount##* }
901+
902+
cat >>"$todo" <<EOF
903+
904+
$comment_char $(eval_ngettext \
905+
"Rebase \$shortrevisions onto \$shortonto (\$todocount command)" \
906+
"Rebase \$shortrevisions onto \$shortonto (\$todocount commands)" \
907+
"$todocount")
908+
EOF
909+
append_todo_help
910+
gettext "
911+
However, if you remove everything, the rebase will be aborted.
912+
913+
" | git stripspace --comment-lines >>"$todo"
914+
915+
if test -z "$keep_empty"
916+
then
917+
printf '%s\n' "$comment_char $(gettext "Note that empty commits are commented out")" >>"$todo"
918+
fi
919+
920+
921+
has_action "$todo" ||
922+
return 2
923+
924+
cp "$todo" "$todo".backup
925+
collapse_todo_ids
926+
git_sequence_editor "$todo" ||
927+
die_abort "$(gettext "Could not execute editor")"
928+
929+
has_action "$todo" ||
930+
return 2
931+
932+
git rebase--helper --check-todo-list || {
933+
ret=$?
934+
checkout_onto
935+
exit $ret
936+
}
937+
938+
expand_todo_ids
939+
940+
test -d "$rewritten" || test -n "$force_rebase" ||
941+
onto="$(git rebase--helper --skip-unnecessary-picks)" ||
942+
die "Could not skip unnecessary pick commands"
943+
944+
checkout_onto
945+
if test -z "$rebase_root" && test ! -d "$rewritten"
946+
then
947+
require_clean_work_tree "rebase"
948+
exec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \
949+
--continue
950+
fi
951+
do_rest
952+
}
953+
954+
git_rebase__interactive () {
955+
initiate_action "$action"
956+
ret=$?
957+
if test $ret = 0; then
958+
return 0
959+
fi
960+
961+
setup_reflog_action
962+
init_basic_state
963+
858964
if test t = "$preserve_merges"
859965
then
860966
if test -z "$rebase_root"
@@ -878,18 +984,8 @@ To continue rebase after editing, run:
878984
merges_option="--no-merges --cherry-pick"
879985
fi
880986

881-
shorthead=$(git rev-parse --short $orig_head)
882-
shortonto=$(git rev-parse --short $onto)
883-
if test -z "$rebase_root"
884-
# this is now equivalent to ! -z "$upstream"
885-
then
886-
shortupstream=$(git rev-parse --short $upstream)
887-
revisions=$upstream...$orig_head
888-
shortrevisions=$shortupstream..$shorthead
889-
else
890-
revisions=$onto...$orig_head
891-
shortrevisions=$shorthead
892-
fi
987+
init_revisions_and_shortrevisions
988+
893989
if test t != "$preserve_merges"
894990
then
895991
git rebase--helper --make-script ${keep_empty:+--keep-empty} \
@@ -960,61 +1056,5 @@ To continue rebase after editing, run:
9601056
done
9611057
fi
9621058

963-
test -s "$todo" || echo noop >> "$todo"
964-
test -z "$autosquash" || git rebase--helper --rearrange-squash || exit
965-
test -n "$cmd" && git rebase--helper --add-exec-commands "$cmd"
966-
967-
todocount=$(git stripspace --strip-comments <"$todo" | wc -l)
968-
todocount=${todocount##* }
969-
970-
cat >>"$todo" <<EOF
971-
972-
$comment_char $(eval_ngettext \
973-
"Rebase \$shortrevisions onto \$shortonto (\$todocount command)" \
974-
"Rebase \$shortrevisions onto \$shortonto (\$todocount commands)" \
975-
"$todocount")
976-
EOF
977-
append_todo_help
978-
gettext "
979-
However, if you remove everything, the rebase will be aborted.
980-
981-
" | git stripspace --comment-lines >>"$todo"
982-
983-
if test -z "$keep_empty"
984-
then
985-
printf '%s\n' "$comment_char $(gettext "Note that empty commits are commented out")" >>"$todo"
986-
fi
987-
988-
989-
has_action "$todo" ||
990-
return 2
991-
992-
cp "$todo" "$todo".backup
993-
collapse_todo_ids
994-
git_sequence_editor "$todo" ||
995-
die_abort "$(gettext "Could not execute editor")"
996-
997-
has_action "$todo" ||
998-
return 2
999-
1000-
git rebase--helper --check-todo-list || {
1001-
ret=$?
1002-
checkout_onto
1003-
exit $ret
1004-
}
1005-
1006-
expand_todo_ids
1007-
1008-
test -d "$rewritten" || test -n "$force_rebase" ||
1009-
onto="$(git rebase--helper --skip-unnecessary-picks)" ||
1010-
die "Could not skip unnecessary pick commands"
1011-
1012-
checkout_onto
1013-
if test -z "$rebase_root" && test ! -d "$rewritten"
1014-
then
1015-
require_clean_work_tree "rebase"
1016-
exec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \
1017-
--continue
1018-
fi
1019-
do_rest
1059+
complete_action
10201060
}

0 commit comments

Comments
 (0)