X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=git-bisect.sh;h=0d0e278c92c39f17b368eb6ead781a877bc8caed;hb=6e13921b4f7adcc7316a76c0c4955b85b1589a65;hp=4bcbaceb8bd6a5dc9021b2525f43ae5317a7d46a;hpb=29313449f726f13ecc562cea9856645eade8e3e9;p=git.git diff --git a/git-bisect.sh b/git-bisect.sh index 4bcbaceb8..0d0e278c9 100755 --- a/git-bisect.sh +++ b/git-bisect.sh @@ -44,7 +44,7 @@ sq() { } bisect_autostart() { - test -f "$GIT_DIR/BISECT_NAMES" || { + test -s "$GIT_DIR/BISECT_START" || { echo >&2 'You need to start by "git bisect start"' if test -t 0 then @@ -98,7 +98,7 @@ bisect_start() { # # Get rid of any old bisect state. # - bisect_clean_state + bisect_clean_state || exit # # Check for one bad and then some good revisions. @@ -146,10 +146,10 @@ bisect_start() { # # Write new start state. # - sq "$@" >"$GIT_DIR/BISECT_NAMES" && echo "$start_head" >"$GIT_DIR/BISECT_START" && + sq "$@" >"$GIT_DIR/BISECT_NAMES" && eval "$eval" && - echo "git-bisect start$orig_args" >>"$GIT_DIR/BISECT_LOG" || exit + echo "git bisect start$orig_args" >>"$GIT_DIR/BISECT_LOG" || exit # # Check if we can proceed to the next bisect state. # @@ -169,7 +169,26 @@ bisect_write() { esac git update-ref "refs/bisect/$tag" "$rev" || exit echo "# $state: $(git show-branch $rev)" >>"$GIT_DIR/BISECT_LOG" - test -n "$nolog" || echo "git-bisect $state $rev" >>"$GIT_DIR/BISECT_LOG" + 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") +} + +mark_expected_rev() { + echo "$1" > "$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_state() { @@ -181,7 +200,8 @@ bisect_state() { 1,bad|1,good|1,skip) rev=$(git rev-parse --verify HEAD) || die "Bad rev input: HEAD" - bisect_write "$state" "$rev" ;; + bisect_write "$state" "$rev" + check_expected_revs "$rev" ;; 2,bad|*,good|*,skip) shift eval='' @@ -191,7 +211,8 @@ bisect_state() { die "Bad rev input: $rev" eval="$eval bisect_write '$state' '$sha'; " done - eval "$eval" ;; + eval "$eval" + check_expected_revs "$@" ;; *,bad) die "'git bisect bad' can take only one argument." ;; *) @@ -220,13 +241,14 @@ bisect_next_check() { if test -t 0 then printf >&2 'Are you sure [Y/n]? ' - case "$(read yesno)" in [Nn]*) exit 1 ;; esac + read yesno + case "$yesno" in [Nn]*) exit 1 ;; esac fi : bisect without good... ;; *) THEN='' - test -f "$GIT_DIR/BISECT_NAMES" || { + test -s "$GIT_DIR/BISECT_START" || { echo >&2 'You need to start by "git bisect start".' THEN='then ' } @@ -242,33 +264,18 @@ bisect_auto_next() { bisect_next_check && bisect_next || : } -eval_rev_list() { - _eval="$1" - - eval $_eval - res=$? - - if [ $res -ne 0 ]; then - echo >&2 "'git rev-list --bisect-vars' failed:" - echo >&2 "maybe you mistake good and bad revs?" - exit $res - fi - - return $res -} - filter_skipped() { _eval="$1" _skip="$2" if [ -z "$_skip" ]; then - eval_rev_list "$_eval" + eval "$_eval" return fi # Let's parse the output of: # "git rev-list --bisect-vars --bisect-all ..." - eval_rev_list "$_eval" | while read hash line + eval "$_eval" | while read hash line do case "$VARS,$FOUND,$TRIED,$hash" in # We display some vars. @@ -331,20 +338,133 @@ exit_if_skipped_commits () { fi } +bisect_checkout() { + _rev="$1" + _msg="$2" + echo "Bisecting: $_msg" + mark_expected_rev "$_rev" + git checkout -q "$_rev" || exit + git show-branch "$_rev" +} + +is_among() { + _rev="$1" + _list="$2" + case "$_list" in *$_rev*) return 0 ;; esac + return 1 +} + +handle_bad_merge_base() { + _badmb="$1" + _good="$2" + if is_expected_rev "$_badmb"; then + cat >&2 <&2 <&2 < "$GIT_DIR/BISECT_ANCESTORS_OK" + + return 0 +} + bisect_next() { case "$#" in 0) ;; *) usage ;; esac bisect_autostart bisect_next_check good + # Get bad, good and skipped revs + bad=$(git rev-parse --verify refs/bisect/bad) && + good=$(git for-each-ref --format='^%(objectname)' \ + "refs/bisect/good-*" | tr '\012' ' ') && skip=$(git for-each-ref --format='%(objectname)' \ "refs/bisect/skip-*" | tr '\012' ' ') || exit + # Maybe some merge bases must be tested first + check_good_are_ancestors_of_bad "$bad" "$good" "$skip" + # Return now if a checkout has already been done + test "$?" -eq "1" && return + + # Get bisection information BISECT_OPT='' test -n "$skip" && BISECT_OPT='--bisect-all' - - bad=$(git rev-parse --verify refs/bisect/bad) && - good=$(git for-each-ref --format='^%(objectname)' \ - "refs/bisect/good-*" | tr '\012' ' ') && eval="git rev-list --bisect-vars $BISECT_OPT $good $bad --" && eval="$eval $(cat "$GIT_DIR/BISECT_NAMES")" && eval=$(filter_skipped "$eval" "$skip") && @@ -365,9 +485,7 @@ bisect_next() { # commit is also a "skip" commit (see above). exit_if_skipped_commits "$bisect_rev" - echo "Bisecting: $bisect_nr revisions left to test after this" - git checkout -q "$bisect_rev" || exit - git show-branch "$bisect_rev" + bisect_checkout "$bisect_rev" "$bisect_nr revisions left to test after this" } bisect_visualize() { @@ -392,16 +510,12 @@ bisect_visualize() { } bisect_reset() { - test -f "$GIT_DIR/BISECT_NAMES" || { + test -s "$GIT_DIR/BISECT_START" || { echo "We are not bisecting." return } case "$#" in - 0) if [ -s "$GIT_DIR/BISECT_START" ]; then - branch=`cat "$GIT_DIR/BISECT_START"` - else - branch=master - fi ;; + 0) branch=$(cat "$GIT_DIR/BISECT_START") ;; 1) git show-ref --verify --quiet -- "refs/heads/$1" || die "$1 does not seem to be a valid branch" branch="$1" ;; @@ -416,22 +530,29 @@ bisect_clean_state() { git for-each-ref --format='%(refname) %(objectname)' refs/bisect/\* | while read ref hash do - git update-ref -d $ref $hash + git update-ref -d $ref $hash || exit done - rm -f "$GIT_DIR/BISECT_START" - rm -f "$GIT_DIR/BISECT_LOG" - rm -f "$GIT_DIR/BISECT_NAMES" - rm -f "$GIT_DIR/BISECT_RUN" + 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" && # Cleanup head-name if it got left by an old version of git-bisect - rm -f "$GIT_DIR/head-name" + rm -f "$GIT_DIR/head-name" && + + rm -f "$GIT_DIR/BISECT_START" } bisect_replay () { test -r "$1" || die "cannot read $1 for replaying" bisect_reset - while read bisect command rev + while read git bisect command rev do - test "$bisect" = "git-bisect" || continue + test "$git $bisect" = "git bisect" -o "$git" = "git-bisect" || continue + if test "$git" = "git-bisect"; then + rev="$command" + command="$bisect" + fi case "$command" in start) cmd="bisect_start $rev"