From 947a604b01a8e81b3d0341d38fbf891289f3c0bb Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Thu, 15 Nov 2007 08:18:07 +0100 Subject: Bisect reset: remove bisect refs that may have been packed. If refs were ever packed in the middle of bisection, the bisect refs were not removed from the "packed-refs" file. This patch fixes this problem by using "git update-ref -d $ref $hash" in "bisect_clean_state". Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- git-bisect.sh | 8 +++++++- t/t6030-bisect-porcelain.sh | 12 ++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/git-bisect.sh b/git-bisect.sh index 1ed44e56ad..46a7b8d54a 100755 --- a/git-bisect.sh +++ b/git-bisect.sh @@ -351,7 +351,13 @@ bisect_reset() { bisect_clean_state() { rm -fr "$GIT_DIR/refs/bisect" - rm -f "$GIT_DIR/refs/heads/bisect" + + # There may be some refs packed during bisection. + git for-each-ref --format='%(refname) %(objectname)' refs/bisect/\* refs/heads/bisect | + while read ref hash + do + git update-ref -d $ref $hash + done rm -f "$GIT_DIR/BISECT_LOG" rm -f "$GIT_DIR/BISECT_NAMES" rm -f "$GIT_DIR/BISECT_RUN" diff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh index 53956c08e2..f09db6244e 100755 --- a/t/t6030-bisect-porcelain.sh +++ b/t/t6030-bisect-porcelain.sh @@ -71,6 +71,18 @@ test_expect_success 'bisect start with one bad and good' ' git bisect next ' +test_expect_success 'bisect reset removes packed refs' ' + git bisect reset && + git bisect start && + git bisect good $HASH1 && + git bisect bad $HASH3 && + git pack-refs --all --prune && + git bisect next && + git bisect reset && + test -z "$(git for-each-ref "refs/bisect/*")" && + test -z "$(git for-each-ref "refs/heads/bisect")" +' + # $HASH1 is good, $HASH4 is bad, we skip $HASH3 # but $HASH2 is bad, # so we should find $HASH2 as the first bad commit -- cgit v1.2.1 From e23cb8c0cc0fb9f18e7e7106e2eec692a7b10044 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 15 Nov 2007 00:39:57 -0800 Subject: git-bisect: war on "sed" We do not need to pipe "echo" to "sed" only to strip refs/heads/ from the beginning. We are assuming not-so-ancient shells these days. Also there is no need to avoid assuming \012 is the LF; we do not run on EBCDIC, sorry. Other parts of the script already uses tr to convert separator to LF that way. Signed-off-by: Junio C Hamano --- git-bisect.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/git-bisect.sh b/git-bisect.sh index 46a7b8d54a..3a210335e7 100755 --- a/git-bisect.sh +++ b/git-bisect.sh @@ -71,7 +71,7 @@ bisect_start() { ;; refs/heads/*) [ -s "$GIT_DIR/head-name" ] && die "won't bisect on seeked tree" - echo "$head" | sed 's#^refs/heads/##' >"$GIT_DIR/head-name" + echo "${head#refs/heads/}" >"$GIT_DIR/head-name" ;; *) die "Bad HEAD - strange symbolic ref" @@ -275,8 +275,7 @@ exit_if_skipped_commits () { if expr "$_tried" : ".*[|].*" > /dev/null ; then echo "There are only 'skip'ped commit left to test." echo "The first bad commit could be any of:" - echo "$_tried" | sed -e 's/[|]/\ -/g' + echo "$_tried" | tr '[|]' '[\012]' echo "We cannot bisect more!" exit 2 fi -- cgit v1.2.1 From 3d7cd64cb493e3e30e4398c7b6cd66ee38cb4418 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 15 Nov 2007 00:42:04 -0800 Subject: git-bisect: use update-ref to mark good/bad commits This removes the last instance of making a ref by hand with "echo SHA1 >.git/refs/$refname" from the script and replaces it with update-ref. Signed-off-by: Junio C Hamano --- git-bisect.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-bisect.sh b/git-bisect.sh index 3a210335e7..4b74a7bb42 100755 --- a/git-bisect.sh +++ b/git-bisect.sh @@ -130,7 +130,7 @@ bisect_write() { good|skip) tag="$state"-"$rev" ;; *) die "Bad bisect_write argument: $state" ;; esac - echo "$rev" >"$GIT_DIR/refs/bisect/$tag" + git update-ref "refs/bisect/$tag" "$rev" echo "# $state: "$(git show-branch $rev) >>"$GIT_DIR/BISECT_LOG" test -z "$nolog" && echo "git-bisect $state $rev" >>"$GIT_DIR/BISECT_LOG" } -- cgit v1.2.1 From 0bee49c6abf18082a01f5d1a2106608456fb7d5a Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 15 Nov 2007 00:47:53 -0800 Subject: git-bisect: modernize branch shuffling hack When switching to a new rev, we first made "new-bisect" branch to point at the chosen commit, attempt to switch to it, and then finally renamed the new-bisect branch to bisect by hand when successful. This is so that we can catch checkout failure (your local modification may interfere with switching to the chosen version) without losing information on which commit the next attempt should be made. Rewrite it using a more modern form but without breaking the safety. Signed-off-by: Junio C Hamano --- git-bisect.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/git-bisect.sh b/git-bisect.sh index 4b74a7bb42..dae8a8e980 100755 --- a/git-bisect.sh +++ b/git-bisect.sh @@ -316,10 +316,9 @@ bisect_next() { exit_if_skipped_commits "$bisect_rev" echo "Bisecting: $bisect_nr revisions left to test after this" - echo "$bisect_rev" >"$GIT_DIR/refs/heads/new-bisect" + git branch -f new-bisect "$bisect_rev" git checkout -q new-bisect || exit - mv "$GIT_DIR/refs/heads/new-bisect" "$GIT_DIR/refs/heads/bisect" && - GIT_DIR="$GIT_DIR" git symbolic-ref HEAD refs/heads/bisect + git branch -M new-bisect bisect git show-branch "$bisect_rev" } -- cgit v1.2.1 From e3f062bfd412adafb7ed6a8f24a3ec89d39211fc Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sat, 17 Nov 2007 14:35:25 +0100 Subject: Bisect visualize: use "for-each-ref" to list all good refs. In bisect_visualize, "cd $GIT_DIR/refs && echo bisect/good-*" was still used instead of "git for-each-ref". This patch fix it. We now pass "refs/bisect/bad" and "--not refs/bisect/good-" instead of "bisect/bad" and "--not bisect/good-" to gitk, but it seems to work. Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- git-bisect.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git-bisect.sh b/git-bisect.sh index dae8a8e980..2b20037a11 100755 --- a/git-bisect.sh +++ b/git-bisect.sh @@ -324,8 +324,8 @@ bisect_next() { bisect_visualize() { bisect_next_check fail - not=`cd "$GIT_DIR/refs" && echo bisect/good-*` - eval gitk bisect/bad --not $not -- $(cat "$GIT_DIR/BISECT_NAMES") + not=$(git for-each-ref --format='%(refname)' "refs/bisect/good-*") + eval gitk refs/bisect/bad --not $not -- $(cat "$GIT_DIR/BISECT_NAMES") } bisect_reset() { -- cgit v1.2.1 From 6459c7c6786aa9bda0c7a095c9db66c36da0e5f0 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sun, 18 Nov 2007 16:34:03 +0100 Subject: Bisect: use "$GIT_DIR/BISECT_NAMES" to check if we are bisecting. Previously we tested if the "$GIT_DIR/refs/bisect" directory existed, to check if we were bisecting. Now with packed refs, it is simpler to check if the file "$GIT_DIR/BISECT_NAMES" exists, as it is already created when starting bisection and removed when reseting bisection. Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- git-bisect.sh | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/git-bisect.sh b/git-bisect.sh index 2b20037a11..414f813be7 100755 --- a/git-bisect.sh +++ b/git-bisect.sh @@ -36,7 +36,7 @@ sq() { } bisect_autostart() { - test -d "$GIT_DIR/refs/bisect" || { + test -f "$GIT_DIR/BISECT_NAMES" || { echo >&2 'You need to start by "git bisect start"' if test -t 0 then @@ -82,7 +82,6 @@ bisect_start() { # Get rid of any old bisect state # bisect_clean_state - mkdir "$GIT_DIR/refs/bisect" # # Check for one bad and then some good revisions. @@ -191,7 +190,7 @@ bisect_next_check() { ;; *) THEN='' - test -d "$GIT_DIR/refs/bisect" || { + test -f "$GIT_DIR/BISECT_NAMES" || { echo >&2 'You need to start by "git bisect start".' THEN='then ' } @@ -348,8 +347,6 @@ bisect_reset() { } bisect_clean_state() { - rm -fr "$GIT_DIR/refs/bisect" - # There may be some refs packed during bisection. git for-each-ref --format='%(refname) %(objectname)' refs/bisect/\* refs/heads/bisect | while read ref hash -- cgit v1.2.1 From fce0499fad13815d936c1068b7a064030f543b3d Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Tue, 20 Nov 2007 06:39:53 +0100 Subject: Bisect reset: do nothing when not bisecting. Before this patch, using "git bisect reset" when not bisecting did a "git checkout master" for no good reason. This also happened using "git bisect replay" when not bisecting because "bisect_replay" starts by calling "bisect_reset". Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- git-bisect.sh | 4 ++++ t/t6030-bisect-porcelain.sh | 27 ++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/git-bisect.sh b/git-bisect.sh index 414f813be7..6f20a297a5 100755 --- a/git-bisect.sh +++ b/git-bisect.sh @@ -328,6 +328,10 @@ bisect_visualize() { } bisect_reset() { + test -f "$GIT_DIR/BISECT_NAMES" || { + echo "We are not bisecting." + return + } case "$#" in 0) if [ -s "$GIT_DIR/head-name" ]; then branch=`cat "$GIT_DIR/head-name"` diff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh index f09db6244e..2ba4b00e52 100755 --- a/t/t6030-bisect-porcelain.sh +++ b/t/t6030-bisect-porcelain.sh @@ -71,6 +71,31 @@ test_expect_success 'bisect start with one bad and good' ' git bisect next ' +test_expect_success 'bisect reset: back in the master branch' ' + git bisect reset && + echo "* master" > branch.expect && + git branch > branch.output && + cmp branch.expect branch.output +' + +test_expect_success 'bisect reset: back in another branch' ' + git checkout -b other && + git bisect start && + git bisect good $HASH1 && + git bisect bad $HASH3 && + git bisect reset && + echo " master" > branch.expect && + echo "* other" >> branch.expect && + git branch > branch.output && + cmp branch.expect branch.output +' + +test_expect_success 'bisect reset when not bisecting' ' + git bisect reset && + git branch > branch.output && + cmp branch.expect branch.output +' + test_expect_success 'bisect reset removes packed refs' ' git bisect reset && git bisect start && @@ -179,7 +204,7 @@ test_expect_success 'bisect skip: add line and then a new test' ' git bisect skip && git bisect good > my_bisect_log.txt && grep "$HASH5 is first bad commit" my_bisect_log.txt && - git bisect log > log_to_replay.txt + git bisect log > log_to_replay.txt && git bisect reset ' -- cgit v1.2.1