git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Fix bisection terminating condition

From
Linus Torvalds <torvalds@osdl.org>
Date
Aug 30, 2005, 18:04 UTC
Message-ID
<Pine.LNX.4.58.0508301038340.4426@g5.osdl.org>
In-Reply-To
<Pine.LNX.4.58.0508301026450.4293@g5.osdl.org>

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 <torvalds@osdl.org>
---
diff --git a/git-bisect-script b/git-bisect-script
--- 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
Previous: Linus TorvaldsNext: Junio C Hamano
Message 5 of 7 in “Bisection visualization hint..”
  1. Linus TorvaldsAug 30, 2005
  2. Junio C HamanoAug 30, 2005
  3. A Large Angry SCMAug 30, 2005
  4. Linus TorvaldsAug 30, 2005
  5. Fix bisection terminating conditionLinus Torvalds, Aug 30, 2005
  6. Junio C HamanoAug 30, 2005
  7. 'git bisect visualize'Junio C Hamano, Aug 30, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.