rebase: reindent function git_rebase__interactive
Signed-off-by: Wink Saville <wink@saville.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Wink Saville committed
Mar 23, 2018 at 14:25 UTC
d48f97aa854bfa7da62d053f4fed4df58e164f95
1 file changed
+215
-217
git-rebase--interactive.sh
+215
-217
@@ -741,27 +741,26 @@ get_missing_commit_check_level () {
741
}
742
743
git_rebase__interactive () {
744
-
745
-case "$action" in
746
-continue)
747
- if test ! -d "$rewritten"
748
- then
749
- exec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \
750
- --continue
751
- fi
752
- # do we have anything to commit?
753
- if git diff-index --cached --quiet HEAD --
754
- then
755
- # Nothing to commit -- skip this commit
756
-
757
- test ! -f "$GIT_DIR"/CHERRY_PICK_HEAD ||
758
- rm "$GIT_DIR"/CHERRY_PICK_HEAD ||
759
- die "$(gettext "Could not remove CHERRY_PICK_HEAD")"
760
- else
761
- if ! test -f "$author_script"
744
+ case "$action" in
745
+ continue)
746
+ if test ! -d "$rewritten"
747
then
763
- gpg_sign_opt_quoted=${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")}
764
- die "$(eval_gettext "\
748
+ exec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \
749
+ --continue
750
+ fi
751
+ # do we have anything to commit?
752
+ if git diff-index --cached --quiet HEAD --
753
+ then
754
+ # Nothing to commit -- skip this commit
755
+
756
+ test ! -f "$GIT_DIR"/CHERRY_PICK_HEAD ||
757
+ rm "$GIT_DIR"/CHERRY_PICK_HEAD ||
758
+ die "$(gettext "Could not remove CHERRY_PICK_HEAD")"
759
+ else
760
+ if ! test -f "$author_script"
761
+ then
762
+ gpg_sign_opt_quoted=${gpg_sign_opt:+$(git rev-parse --sq-quote "$gpg_sign_opt")}
763
+ die "$(eval_gettext "\
764
You have staged changes in your working tree.
765
If these changes are meant to be
766
squashed into the previous commit, run:
@@ -776,197 +775,197 @@ In both cases, once you're done, continue with:
775
776
git rebase --continue
777
")"
779
- fi
780
- . "$author_script" ||
781
- die "$(gettext "Error trying to find the author identity to amend commit")"
782
- if test -f "$amend"
783
- then
784
- current_head=$(git rev-parse --verify HEAD)
785
- test "$current_head" = $(cat "$amend") ||
786
- die "$(gettext "\
778
+ fi
779
+ . "$author_script" ||
780
+ die "$(gettext "Error trying to find the author identity to amend commit")"
781
+ if test -f "$amend"
782
+ then
783
+ current_head=$(git rev-parse --verify HEAD)
784
+ test "$current_head" = $(cat "$amend") ||
785
+ die "$(gettext "\
786
You have uncommitted changes in your working tree. Please commit them
787
first and then run 'git rebase --continue' again.")"
789
- do_with_author git commit --amend --no-verify -F "$msg" -e \
790
- ${gpg_sign_opt:+"$gpg_sign_opt"} $allow_empty_message ||
791
- die "$(gettext "Could not commit staged changes.")"
792
- else
793
- do_with_author git commit --no-verify -F "$msg" -e \
794
- ${gpg_sign_opt:+"$gpg_sign_opt"} $allow_empty_message ||
795
- die "$(gettext "Could not commit staged changes.")"
788
+ do_with_author git commit --amend --no-verify -F "$msg" -e \
789
+ ${gpg_sign_opt:+"$gpg_sign_opt"} $allow_empty_message ||
790
+ die "$(gettext "Could not commit staged changes.")"
791
+ else
792
+ do_with_author git commit --no-verify -F "$msg" -e \
793
+ ${gpg_sign_opt:+"$gpg_sign_opt"} $allow_empty_message ||
794
+ die "$(gettext "Could not commit staged changes.")"
795
+ fi
796
fi
797
- fi
797
799
- if test -r "$state_dir"/stopped-sha
800
- then
801
- record_in_rewritten "$(cat "$state_dir"/stopped-sha)"
802
- fi
798
+ if test -r "$state_dir"/stopped-sha
799
+ then
800
+ record_in_rewritten "$(cat "$state_dir"/stopped-sha)"
801
+ fi
802
804
- require_clean_work_tree "rebase"
805
- do_rest
806
- return 0
807
- ;;
808
-skip)
809
- git rerere clear
803
+ require_clean_work_tree "rebase"
804
+ do_rest
805
+ return 0
806
+ ;;
807
+ skip)
808
+ git rerere clear
809
811
- if test ! -d "$rewritten"
812
- then
813
- exec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \
814
- --continue
815
- fi
816
- do_rest
817
- return 0
818
- ;;
819
-edit-todo)
820
- git stripspace --strip-comments <"$todo" >"$todo".new
821
- mv -f "$todo".new "$todo"
822
- collapse_todo_ids
823
- append_todo_help
824
- gettext "
810
+ if test ! -d "$rewritten"
811
+ then
812
+ exec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \
813
+ --continue
814
+ fi
815
+ do_rest
816
+ return 0
817
+ ;;
818
+ edit-todo)
819
+ git stripspace --strip-comments <"$todo" >"$todo".new
820
+ mv -f "$todo".new "$todo"
821
+ collapse_todo_ids
822
+ append_todo_help
823
+ gettext "
824
You are editing the todo file of an ongoing interactive rebase.
825
To continue rebase after editing, run:
826
git rebase --continue
827
828
" | git stripspace --comment-lines >>"$todo"
829
831
- git_sequence_editor "$todo" ||
832
- die "$(gettext "Could not execute editor")"
833
- expand_todo_ids
834
-
835
- exit
836
- ;;
837
-show-current-patch)
838
- exec git show REBASE_HEAD --
839
- ;;
840
-esac
841
-
842
-comment_for_reflog start
830
+ git_sequence_editor "$todo" ||
831
+ die "$(gettext "Could not execute editor")"
832
+ expand_todo_ids
833
844
-if test ! -z "$switch_to"
845
-then
846
- GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $switch_to"
847
- output git checkout "$switch_to" -- ||
848
- die "$(eval_gettext "Could not checkout \$switch_to")"
834
+ exit
835
+ ;;
836
+ show-current-patch)
837
+ exec git show REBASE_HEAD --
838
+ ;;
839
+ esac
840
841
comment_for_reflog start
851
-fi
852
-
853
-orig_head=$(git rev-parse --verify HEAD) || die "$(gettext "No HEAD?")"
854
-mkdir -p "$state_dir" || die "$(eval_gettext "Could not create temporary \$state_dir")"
855
-rm -f "$(git rev-parse --git-path REBASE_HEAD)"
842
857
-: > "$state_dir"/interactive || die "$(gettext "Could not mark as interactive")"
858
-write_basic_state
859
-if test t = "$preserve_merges"
860
-then
861
- if test -z "$rebase_root"
843
+ if test ! -z "$switch_to"
844
then
863
- mkdir "$rewritten" &&
864
- for c in $(git merge-base --all $orig_head $upstream)
865
- do
866
- echo $onto > "$rewritten"/$c ||
867
- die "$(gettext "Could not init rewritten commits")"
868
- done
869
- else
870
- mkdir "$rewritten" &&
871
- echo $onto > "$rewritten"/root ||
872
- die "$(gettext "Could not init rewritten commits")"
845
+ GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $switch_to"
846
+ output git checkout "$switch_to" -- ||
847
+ die "$(eval_gettext "Could not checkout \$switch_to")"
848
+
849
+ comment_for_reflog start
850
fi
874
- # No cherry-pick because our first pass is to determine
875
- # parents to rewrite and skipping dropped commits would
876
- # prematurely end our probe
877
- merges_option=
878
-else
879
- merges_option="--no-merges --cherry-pick"
880
-fi
881
-
882
-shorthead=$(git rev-parse --short $orig_head)
883
-shortonto=$(git rev-parse --short $onto)
884
-if test -z "$rebase_root"
885
- # this is now equivalent to ! -z "$upstream"
886
-then
887
- shortupstream=$(git rev-parse --short $upstream)
888
- revisions=$upstream...$orig_head
889
- shortrevisions=$shortupstream..$shorthead
890
-else
891
- revisions=$onto...$orig_head
892
- shortrevisions=$shorthead
893
-fi
894
-if test t != "$preserve_merges"
895
-then
896
- git rebase--helper --make-script ${keep_empty:+--keep-empty} \
897
- $revisions ${restrict_revision+^$restrict_revision} >"$todo" ||
898
- die "$(gettext "Could not generate todo list")"
899
-else
900
- format=$(git config --get rebase.instructionFormat)
901
- # the 'rev-list .. | sed' requires %m to parse; the instruction requires %H to parse
902
- git rev-list $merges_option --format="%m%H ${format:-%s}" \
903
- --reverse --left-right --topo-order \
904
- $revisions ${restrict_revision+^$restrict_revision} | \
905
- sed -n "s/^>//p" |
906
- while read -r sha1 rest
907
- do
851
909
- if test -z "$keep_empty" && is_empty_commit $sha1 && ! is_merge_commit $sha1
910
- then
911
- comment_out="$comment_char "
912
- else
913
- comment_out=
914
- fi
852
+ orig_head=$(git rev-parse --verify HEAD) || die "$(gettext "No HEAD?")"
853
+ mkdir -p "$state_dir" || die "$(eval_gettext "Could not create temporary \$state_dir")"
854
+ rm -f "$(git rev-parse --git-path REBASE_HEAD)"
855
856
+ : > "$state_dir"/interactive || die "$(gettext "Could not mark as interactive")"
857
+ write_basic_state
858
+ if test t = "$preserve_merges"
859
+ then
860
if test -z "$rebase_root"
861
then
918
- preserve=t
919
- for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)
862
+ mkdir "$rewritten" &&
863
+ for c in $(git merge-base --all $orig_head $upstream)
864
do
921
- if test -f "$rewritten"/$p
922
- then
923
- preserve=f
924
- fi
865
+ echo $onto > "$rewritten"/$c ||
866
+ die "$(gettext "Could not init rewritten commits")"
867
done
868
else
927
- preserve=f
928
- fi
929
- if test f = "$preserve"
930
- then
931
- touch "$rewritten"/$sha1
932
- printf '%s\n' "${comment_out}pick $sha1 $rest" >>"$todo"
933
- fi
934
- done
935
-fi
936
-
937
-# Watch for commits that been dropped by --cherry-pick
938
-if test t = "$preserve_merges"
939
-then
940
- mkdir "$dropped"
941
- # Save all non-cherry-picked changes
942
- git rev-list $revisions --left-right --cherry-pick | \
943
- sed -n "s/^>//p" > "$state_dir"/not-cherry-picks
944
- # Now all commits and note which ones are missing in
945
- # not-cherry-picks and hence being dropped
946
- git rev-list $revisions |
947
- while read rev
948
- do
949
- if test -f "$rewritten"/$rev &&
950
- ! sane_grep "$rev" "$state_dir"/not-cherry-picks >/dev/null
951
- then
952
- # Use -f2 because if rev-list is telling us this commit is
953
- # not worthwhile, we don't want to track its multiple heads,
954
- # just the history of its first-parent for others that will
955
- # be rebasing on top of it
956
- git rev-list --parents -1 $rev | cut -d' ' -s -f2 > "$dropped"/$rev
957
- sha1=$(git rev-list -1 $rev)
958
- sane_grep -v "^[a-z][a-z]* $sha1" <"$todo" > "${todo}2" ; mv "${todo}2" "$todo"
959
- rm "$rewritten"/$rev
869
+ mkdir "$rewritten" &&
870
+ echo $onto > "$rewritten"/root ||
871
+ die "$(gettext "Could not init rewritten commits")"
872
fi
961
- done
962
-fi
873
+ # No cherry-pick because our first pass is to determine
874
+ # parents to rewrite and skipping dropped commits would
875
+ # prematurely end our probe
876
+ merges_option=
877
+ else
878
+ merges_option="--no-merges --cherry-pick"
879
+ fi
880
+
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
893
+ if test t != "$preserve_merges"
894
+ then
895
+ git rebase--helper --make-script ${keep_empty:+--keep-empty} \
896
+ $revisions ${restrict_revision+^$restrict_revision} >"$todo" ||
897
+ die "$(gettext "Could not generate todo list")"
898
+ else
899
+ format=$(git config --get rebase.instructionFormat)
900
+ # the 'rev-list .. | sed' requires %m to parse; the instruction requires %H to parse
901
+ git rev-list $merges_option --format="%m%H ${format:-%s}" \
902
+ --reverse --left-right --topo-order \
903
+ $revisions ${restrict_revision+^$restrict_revision} | \
904
+ sed -n "s/^>//p" |
905
+ while read -r sha1 rest
906
+ do
907
+
908
+ if test -z "$keep_empty" && is_empty_commit $sha1 && ! is_merge_commit $sha1
909
+ then
910
+ comment_out="$comment_char "
911
+ else
912
+ comment_out=
913
+ fi
914
+
915
+ if test -z "$rebase_root"
916
+ then
917
+ preserve=t
918
+ for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)
919
+ do
920
+ if test -f "$rewritten"/$p
921
+ then
922
+ preserve=f
923
+ fi
924
+ done
925
+ else
926
+ preserve=f
927
+ fi
928
+ if test f = "$preserve"
929
+ then
930
+ touch "$rewritten"/$sha1
931
+ printf '%s\n' "${comment_out}pick $sha1 $rest" >>"$todo"
932
+ fi
933
+ done
934
+ fi
935
+
936
+ # Watch for commits that been dropped by --cherry-pick
937
+ if test t = "$preserve_merges"
938
+ then
939
+ mkdir "$dropped"
940
+ # Save all non-cherry-picked changes
941
+ git rev-list $revisions --left-right --cherry-pick | \
942
+ sed -n "s/^>//p" > "$state_dir"/not-cherry-picks
943
+ # Now all commits and note which ones are missing in
944
+ # not-cherry-picks and hence being dropped
945
+ git rev-list $revisions |
946
+ while read rev
947
+ do
948
+ if test -f "$rewritten"/$rev &&
949
+ ! sane_grep "$rev" "$state_dir"/not-cherry-picks >/dev/null
950
+ then
951
+ # Use -f2 because if rev-list is telling us this commit is
952
+ # not worthwhile, we don't want to track its multiple heads,
953
+ # just the history of its first-parent for others that will
954
+ # be rebasing on top of it
955
+ git rev-list --parents -1 $rev | cut -d' ' -s -f2 > "$dropped"/$rev
956
+ sha1=$(git rev-list -1 $rev)
957
+ sane_grep -v "^[a-z][a-z]* $sha1" <"$todo" > "${todo}2" ; mv "${todo}2" "$todo"
958
+ rm "$rewritten"/$rev
959
+ fi
960
+ done
961
+ fi
962
964
-test -s "$todo" || echo noop >> "$todo"
965
-test -z "$autosquash" || git rebase--helper --rearrange-squash || exit
966
-test -n "$cmd" && git rebase--helper --add-exec-commands "$cmd"
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
968
-todocount=$(git stripspace --strip-comments <"$todo" | wc -l)
969
-todocount=${todocount##* }
967
+ todocount=$(git stripspace --strip-comments <"$todo" | wc -l)
968
+ todocount=${todocount##* }
969
970
cat >>"$todo" <<EOF
971
@@ -975,48 +974,47 @@ $comment_char $(eval_ngettext \
974
"Rebase \$shortrevisions onto \$shortonto (\$todocount commands)" \
975
"$todocount")
976
EOF
978
-append_todo_help
979
-gettext "
980
-However, if you remove everything, the rebase will be aborted.
981
-
982
-" | git stripspace --comment-lines >>"$todo"
977
+ append_todo_help
978
+ gettext "
979
+ However, if you remove everything, the rebase will be aborted.
980
984
-if test -z "$keep_empty"
985
-then
986
- printf '%s\n' "$comment_char $(gettext "Note that empty commits are commented out")" >>"$todo"
987
-fi
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
990
-has_action "$todo" ||
991
- return 2
988
993
-cp "$todo" "$todo".backup
994
-collapse_todo_ids
995
-git_sequence_editor "$todo" ||
996
- die_abort "$(gettext "Could not execute editor")"
989
+ has_action "$todo" ||
990
+ return 2
991
998
-has_action "$todo" ||
999
- return 2
992
+ cp "$todo" "$todo".backup
993
+ collapse_todo_ids
994
+ git_sequence_editor "$todo" ||
995
+ die_abort "$(gettext "Could not execute editor")"
996
1001
-git rebase--helper --check-todo-list || {
1002
- ret=$?
1003
- checkout_onto
1004
- exit $ret
1005
-}
997
+ has_action "$todo" ||
998
+ return 2
999
1007
-expand_todo_ids
1000
+ git rebase--helper --check-todo-list || {
1001
+ ret=$?
1002
+ checkout_onto
1003
+ exit $ret
1004
+ }
1005
1009
-test -d "$rewritten" || test -n "$force_rebase" ||
1010
-onto="$(git rebase--helper --skip-unnecessary-picks)" ||
1011
-die "Could not skip unnecessary pick commands"
1006
+ expand_todo_ids
1007
1013
-checkout_onto
1014
-if test -z "$rebase_root" && test ! -d "$rewritten"
1015
-then
1016
- require_clean_work_tree "rebase"
1017
- exec git rebase--helper ${force_rebase:+--no-ff} $allow_empty_message \
1018
- --continue
1019
-fi
1020
-do_rest
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
1020
}