+strategy=recursive
+do_merge=
+dotest=$GIT_DIR/.dotest-merge
+prec=4
+
+continue_merge () {
+ test -n "$prev_head" || die "prev_head must be defined"
+ test -d "$dotest" || die "$dotest directory does not exist"
+
+ unmerged=$(git-ls-files -u)
+ if test -n "$unmerged"
+ then
+ echo "You still have unmerged paths in your index"
+ echo "did you forget update-index?"
+ die "$MRESOLVEMSG"
+ fi
+
+ if test -n "`git-diff-index HEAD`"
+ then
+ git-commit -C "`cat $dotest/current`"
+ else
+ echo "Previous merge succeeded automatically"
+ fi
+
+ prev_head=`git-rev-parse HEAD^0`
+
+ # save the resulting commit so we can read-tree on it later
+ echo "$prev_head" > "$dotest/`printf %0${prec}d $msgnum`.result"
+ echo "$prev_head" > "$dotest/prev_head"
+
+ # onto the next patch:
+ msgnum=$(($msgnum + 1))
+ printf "%0${prec}d" "$msgnum" > "$dotest/msgnum"
+}
+
+call_merge () {
+ cmt="$(cat $dotest/`printf %0${prec}d $1`)"
+ echo "$cmt" > "$dotest/current"
+ git-merge-$strategy "$cmt^" -- HEAD "$cmt"
+ rv=$?
+ case "$rv" in
+ 0)
+ git-commit -C "$cmt" || die "commit failed: $MRESOLVEMSG"
+ ;;
+ 1)
+ test -d "$GIT_DIR/rr-cache" && git-rerere
+ die "$MRESOLVEMSG"
+ ;;
+ 2)
+ echo "Strategy: $rv $strategy failed, try another" 1>&2
+ die "$MRESOLVEMSG"
+ ;;
+ *)
+ die "Unknown exit code ($rv) from command:" \
+ "git-merge-$strategy $cmt^ -- HEAD $cmt"
+ ;;
+ esac
+}
+
+finish_rb_merge () {
+ set -e
+
+ msgnum=1
+ echo "Finalizing rebased commits..."
+ git-reset --hard "`cat $dotest/onto`"
+ end="`cat $dotest/end`"
+ while test "$msgnum" -le "$end"
+ do
+ msgnum=`printf "%0${prec}d" "$msgnum"`
+ printf "%0${prec}d" "$msgnum" > "$dotest/msgnum"
+
+ git-read-tree `cat "$dotest/$msgnum.result"`
+ git-checkout-index -q -f -u -a
+ git-commit -C "`cat $dotest/$msgnum`"
+
+ echo "Committed $msgnum"
+ echo ' '`git-rev-list --pretty=oneline -1 HEAD | \
+ sed 's/^[a-f0-9]\+ //'`
+ msgnum=$(($msgnum + 1))
+ done
+ rm -r "$dotest"
+ echo "All done."
+}
+