rebase: remove unused rebase state 'prev_head'
[gitweb.git] / git-rebase.sh
index 72696bfef69ddac259e69795179645ebcf4cf2aa..8c1c4ed02c1fa11c8c7f58c6fa695f151a2ee236 100755 (executable)
@@ -57,8 +57,23 @@ rebase_root=
 force_rebase=
 allow_rerere_autoupdate=
 
+read_state () {
+       if test -d "$merge_dir"
+       then
+               state_dir="$merge_dir"
+               onto_name=$(cat "$merge_dir"/onto_name) &&
+               end=$(cat "$merge_dir"/end) &&
+               msgnum=$(cat "$merge_dir"/msgnum)
+       else
+               state_dir="$apply_dir"
+       fi &&
+       head_name=$(cat "$state_dir"/head-name) &&
+       onto=$(cat "$state_dir"/onto) &&
+       orig_head=$(cat "$state_dir"/orig-head) &&
+       GIT_QUIET=$(cat "$state_dir"/quiet)
+}
+
 continue_merge () {
-       test -n "$prev_head" || die "prev_head must be defined"
        test -d "$merge_dir" || die "$merge_dir directory does not exist"
 
        unmerged=$(git ls-files -u)
@@ -92,10 +107,6 @@ continue_merge () {
        test -z "$GIT_QUIET" &&
        GIT_PAGER='' git log --format=%s -1 "$cmt"
 
-       prev_head=`git rev-parse HEAD^0`
-       # save the resulting commit so we can read-tree on it later
-       echo "$prev_head" > "$merge_dir/prev_head"
-
        # onto the next patch:
        msgnum=$(($msgnum + 1))
        echo "$msgnum" >"$merge_dir/msgnum"
@@ -107,9 +118,8 @@ call_merge () {
        hd=$(git rev-parse --verify HEAD)
        cmt_name=$(git symbolic-ref HEAD 2> /dev/null || echo HEAD)
        msgnum=$(cat "$merge_dir/msgnum")
-       end=$(cat "$merge_dir/end")
        eval GITHEAD_$cmt='"${cmt_name##refs/heads/}~$(($end - $msgnum))"'
-       eval GITHEAD_$hd='$(cat "$merge_dir/onto_name")'
+       eval GITHEAD_$hd='$onto_name'
        export GITHEAD_$cmt GITHEAD_$hd
        if test -n "$GIT_QUIET"
        then
@@ -138,10 +148,6 @@ call_merge () {
 }
 
 move_to_original_branch () {
-       test -z "$head_name" &&
-               head_name="$(cat "$merge_dir"/head-name)" &&
-               onto="$(cat "$merge_dir"/onto)" &&
-               orig_head="$(cat "$merge_dir"/orig-head)"
        case "$head_name" in
        refs/*)
                message="rebase finished: $head_name onto $onto"
@@ -220,13 +226,9 @@ do
                        echo "mark them as resolved using git add"
                        exit 1
                }
+               read_state
                if test -d "$merge_dir"
                then
-                       prev_head=$(cat "$merge_dir/prev_head")
-                       end=$(cat "$merge_dir/end")
-                       msgnum=$(cat "$merge_dir/msgnum")
-                       onto=$(cat "$merge_dir/onto")
-                       GIT_QUIET=$(cat "$merge_dir/quiet")
                        continue_merge
                        while test "$msgnum" -le "$end"
                        do
@@ -236,10 +238,6 @@ do
                        finish_rb_merge
                        exit
                fi
-               head_name=$(cat "$apply_dir"/head-name) &&
-               onto=$(cat "$apply_dir"/onto) &&
-               orig_head=$(cat "$apply_dir"/orig-head) &&
-               GIT_QUIET=$(cat "$apply_dir"/quiet)
                git am --resolved --3way --resolvemsg="$RESOLVEMSG" &&
                move_to_original_branch
                exit
@@ -249,15 +247,11 @@ do
                        die "No rebase in progress?"
 
                git reset --hard HEAD || exit $?
+               read_state
                if test -d "$merge_dir"
                then
                        git rerere clear
-                       prev_head=$(cat "$merge_dir/prev_head")
-                       end=$(cat "$merge_dir/end")
-                       msgnum=$(cat "$merge_dir/msgnum")
                        msgnum=$(($msgnum + 1))
-                       onto=$(cat "$merge_dir/onto")
-                       GIT_QUIET=$(cat "$merge_dir/quiet")
                        while test "$msgnum" -le "$end"
                        do
                                call_merge "$msgnum"
@@ -266,10 +260,6 @@ do
                        finish_rb_merge
                        exit
                fi
-               head_name=$(cat "$apply_dir"/head-name) &&
-               onto=$(cat "$apply_dir"/onto) &&
-               orig_head=$(cat "$apply_dir"/orig-head) &&
-               GIT_QUIET=$(cat "$apply_dir"/quiet)
                git am -3 --skip --resolvemsg="$RESOLVEMSG" &&
                move_to_original_branch
                exit
@@ -279,18 +269,15 @@ do
                        die "No rebase in progress?"
 
                git rerere clear
-
-               test -d "$merge_dir" || merge_dir="$apply_dir"
-
-               head_name="$(cat "$merge_dir"/head-name)" &&
+               read_state
                case "$head_name" in
                refs/*)
                        git symbolic-ref HEAD $head_name ||
                        die "Could not move back to $head_name"
                        ;;
                esac
-               git reset --hard $(cat "$merge_dir/orig-head")
-               rm -r "$merge_dir"
+               git reset --hard $orig_head
+               rm -r "$state_dir"
                exit
                ;;
        --onto)
@@ -574,12 +561,10 @@ fi
 # this is rename-aware if the recursive (default) strategy is used
 
 mkdir -p "$merge_dir"
-echo "$onto" > "$merge_dir/onto"
 echo "$onto_name" > "$merge_dir/onto_name"
-prev_head=$orig_head
-echo "$prev_head" > "$merge_dir/prev_head"
-echo "$orig_head" > "$merge_dir/orig-head"
 echo "$head_name" > "$merge_dir/head-name"
+echo "$onto" > "$merge_dir/onto"
+echo "$orig_head" > "$merge_dir/orig-head"
 echo "$GIT_QUIET" > "$merge_dir/quiet"
 
 msgnum=0