Merge branch 'sb/blame-config-doc'
[gitweb.git] / git-bisect.sh
index ae3cb013e7d5679bc4c63fe4cea35d40167178c5..0138a8860e3779cf62210d8d54d2eada020be12f 100755 (executable)
@@ -186,7 +186,7 @@ bisect_start() {
        #
        # Get rid of any old bisect state.
        #
-       bisect_clean_state || exit
+       git bisect--helper --bisect-clean-state || exit
 
        #
        # Change state.
@@ -195,7 +195,7 @@ bisect_start() {
        # We have to trap this to be able to clean up using
        # "bisect_clean_state".
        #
-       trap 'bisect_clean_state' 0
+       trap 'git bisect--helper --bisect-clean-state' 0
        trap 'exit 255' 1 2 3 15
 
        #
@@ -209,7 +209,7 @@ bisect_start() {
        eval "$eval true" &&
        if test $must_write_terms -eq 1
        then
-               write_terms "$TERM_BAD" "$TERM_GOOD"
+               git bisect--helper --write-terms "$TERM_BAD" "$TERM_GOOD" || exit
        fi &&
        echo "git bisect start$orig_args" >>"$GIT_DIR/BISECT_LOG" || exit
        #
@@ -237,22 +237,6 @@ bisect_write() {
        test -n "$nolog" || echo "git bisect $state $rev" >>"$GIT_DIR/BISECT_LOG"
 }
 
-is_expected_rev() {
-       test -f "$GIT_DIR/BISECT_EXPECTED_REV" &&
-       test "$1" = $(cat "$GIT_DIR/BISECT_EXPECTED_REV")
-}
-
-check_expected_revs() {
-       for _rev in "$@"; do
-               if ! is_expected_rev "$_rev"
-               then
-                       rm -f "$GIT_DIR/BISECT_ANCESTORS_OK"
-                       rm -f "$GIT_DIR/BISECT_EXPECTED_REV"
-                       return
-               fi
-       done
-}
-
 bisect_skip() {
        all=''
        for arg in "$@"
@@ -280,7 +264,7 @@ bisect_state() {
                rev=$(git rev-parse --verify "$bisected_head") ||
                        die "$(eval_gettext "Bad rev input: \$bisected_head")"
                bisect_write "$state" "$rev"
-               check_expected_revs "$rev" ;;
+               git bisect--helper --check-expected-revs "$rev" ;;
        2,"$TERM_BAD"|*,"$TERM_GOOD"|*,skip)
                shift
                hash_list=''
@@ -294,7 +278,7 @@ bisect_state() {
                do
                        bisect_write "$state" "$rev"
                done
-               check_expected_revs $hash_list ;;
+               git bisect--helper --check-expected-revs $hash_list ;;
        *,"$TERM_BAD")
                die "$(eval_gettext "'git bisect \$TERM_BAD' can take only one argument.")" ;;
        *)
@@ -430,27 +414,7 @@ bisect_reset() {
                die "$(eval_gettext "Could not check out original HEAD '\$branch'.
 Try 'git bisect reset <commit>'.")"
        fi
-       bisect_clean_state
-}
-
-bisect_clean_state() {
-       # There may be some refs packed during bisection.
-       git for-each-ref --format='%(refname) %(objectname)' refs/bisect/\* |
-       while read ref hash
-       do
-               git update-ref -d $ref $hash || exit
-       done
-       rm -f "$GIT_DIR/BISECT_EXPECTED_REV" &&
-       rm -f "$GIT_DIR/BISECT_ANCESTORS_OK" &&
-       rm -f "$GIT_DIR/BISECT_LOG" &&
-       rm -f "$GIT_DIR/BISECT_NAMES" &&
-       rm -f "$GIT_DIR/BISECT_RUN" &&
-       rm -f "$GIT_DIR/BISECT_TERMS" &&
-       # Cleanup head-name if it got left by an old version of git-bisect
-       rm -f "$GIT_DIR/head-name" &&
-       git update-ref -d --no-deref BISECT_HEAD &&
-       # clean up BISECT_START last
-       rm -f "$GIT_DIR/BISECT_START"
+       git bisect--helper --bisect-clean-state || exit
 }
 
 bisect_replay () {
@@ -557,45 +521,6 @@ get_terms () {
        fi
 }
 
-write_terms () {
-       TERM_BAD=$1
-       TERM_GOOD=$2
-       if test "$TERM_BAD" = "$TERM_GOOD"
-       then
-               die "$(gettext "please use two different terms")"
-       fi
-       check_term_format "$TERM_BAD" bad
-       check_term_format "$TERM_GOOD" good
-       printf '%s\n%s\n' "$TERM_BAD" "$TERM_GOOD" >"$GIT_DIR/BISECT_TERMS"
-}
-
-check_term_format () {
-       term=$1
-       git check-ref-format refs/bisect/"$term" ||
-       die "$(eval_gettext "'\$term' is not a valid term")"
-       case "$term" in
-       help|start|terms|skip|next|reset|visualize|replay|log|run)
-               die "$(eval_gettext "can't use the builtin command '\$term' as a term")"
-               ;;
-       bad|new)
-               if test "$2" != bad
-               then
-                       # In theory, nothing prevents swapping
-                       # completely good and bad, but this situation
-                       # could be confusing and hasn't been tested
-                       # enough. Forbid it for now.
-                       die "$(eval_gettext "can't change the meaning of term '\$term'")"
-               fi
-               ;;
-       good|old)
-               if test "$2" != good
-               then
-                       die "$(eval_gettext "can't change the meaning of term '\$term'")"
-               fi
-               ;;
-       esac
-}
-
 check_and_set_terms () {
        cmd="$1"
        case "$cmd" in
@@ -609,13 +534,17 @@ check_and_set_terms () {
                bad|good)
                        if ! test -s "$GIT_DIR/BISECT_TERMS"
                        then
-                               write_terms bad good
+                               TERM_BAD=bad
+                               TERM_GOOD=good
+                               git bisect--helper --write-terms "$TERM_BAD" "$TERM_GOOD" || exit
                        fi
                        ;;
                new|old)
                        if ! test -s "$GIT_DIR/BISECT_TERMS"
                        then
-                               write_terms new old
+                               TERM_BAD=new
+                               TERM_GOOD=old
+                               git bisect--helper --write-terms "$TERM_BAD" "$TERM_GOOD" || exit
                        fi
                        ;;
                esac ;;