From 670f5fe34f0f6a363297d5dcd73051089b78fe82 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Tue, 30 Aug 2005 11:04:39 -0700 Subject: [PATCH] Fix bisection terminating condition When testing bisection and using gitk to visualize the result, it was obvious that the termination condition was broken. We know what the bad entry is only when the bisection ends up telling us to test the known-bad entry again. Also, add a safety net: if somebody marks as good something that includes the known-bad point, we now notice and complain, instead of writing an empty revision to the new bisection branch. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- git-bisect-script | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'git-bisect-script') diff --git a/git-bisect-script b/git-bisect-script index 0c5c10750e..649b7026eb 100755 --- a/git-bisect-script +++ b/git-bisect-script @@ -105,12 +105,16 @@ bisect_next() { good=$(git-rev-parse --sq --revs-only --not \ $(cd "$GIT_DIR" && ls refs/bisect/good-*)) && rev=$(eval "git-rev-list --bisect $good $bad") || exit - nr=$(eval "git-rev-list $rev $good" | wc -l) || exit - if [ "$nr" -le "1" ]; then + if [ -z "$rev" ]; then + echo "$bad was both good and bad" + exit 1 + fi + if [ "$rev" = "$bad" ]; then echo "$rev is first bad commit" git-diff-tree --pretty $rev exit 0 fi + nr=$(eval "git-rev-list $rev $good" | wc -l) || exit echo "Bisecting: $nr revisions left to test after this" echo "$rev" > "$GIT_DIR/refs/heads/new-bisect" git checkout new-bisect || exit -- cgit v1.3 From cc9f24d024e7e4bf0b2fbd4e1beb7eb1a425805f Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 30 Aug 2005 12:45:41 -0700 Subject: 'git bisect visualize' Linus says: I'm testing bisection to find a bug that causes my G5 to no longer boot, and during the process have found this command line very nice: gitk bisect/bad --not $(cd .git/refs ; ls bisect/good-*) it basically shows the state of bisection with the known bad commit as the top, and cutting off all the good commits - so what you see are the potential buggy commits. Signed-off-by: Junio C Hamano --- git-bisect-script | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'git-bisect-script') diff --git a/git-bisect-script b/git-bisect-script index 649b7026eb..e5a4670158 100755 --- a/git-bisect-script +++ b/git-bisect-script @@ -2,12 +2,13 @@ . git-sh-setup-script || dir "Not a git archive" usage() { - echo >&2 'usage: git bisect [start | bad | good | next | reset] + echo >&2 'usage: git bisect [start|bad|good|next|reset|visualize] git bisect start reset bisect state and start bisection. git bisect bad [] mark a known-bad revision. git bisect good [...] mark ... known-good revisions. git bisect next find next bisection to test and check it out. -git bisect reset [] finish bisection search and go back to branch.' +git bisect reset [] finish bisection search and go back to branch. +git bisect visualize show bisect status in gitk.' exit 1 } @@ -57,8 +58,14 @@ bisect_start() { bisect_bad() { bisect_autostart - case "$#" in 0 | 1) ;; *) usage ;; esac - rev=$(git-rev-parse --verify --default HEAD "$@") || exit + case "$#" in + 0) + rev=$(git-rev-parse --verify HEAD) ;; + 1) + rev=$(git-rev-parse --verify "$1") ;; + *) + usage ;; + esac || exit echo "$rev" > "$GIT_DIR/refs/bisect/bad" bisect_auto_next } @@ -67,11 +74,13 @@ bisect_good() { bisect_autostart case "$#" in 0) revs=$(git-rev-parse --verify HEAD) || exit ;; - *) revs=$(git-rev-parse --revs-only --no-flags "$@") || exit ;; + *) revs=$(git-rev-parse --revs-only --no-flags "$@") && + test '' != "$revs" || die "Bad rev input: $@" ;; esac for rev in $revs do - echo "$rev" >"$GIT_DIR/refs/bisect/good-$rev" + rev=$(git-rev-parse --verify "$rev") || exit + echo "$rev" >"$GIT_DIR/refs/bisect/good-$rev" done bisect_auto_next } @@ -122,6 +131,11 @@ bisect_next() { ln -sf refs/heads/bisect "$GIT_DIR/HEAD" } +bisect_visualize() { + bisect_next_check fail + gitk bisect/bad --not `cd "$GIT_DIR/refs" && echo bisect/good-*` +} + bisect_reset() { case "$#" in 0) branch=master ;; @@ -154,6 +168,8 @@ case "$#" in next) # Not sure we want "next" at the UI level anymore. bisect_next "$@" ;; + visualize) + bisect_visualize "$@" ;; reset) bisect_reset "$@" ;; *) -- cgit v1.3