git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bisect: use "$GIT_DIR/BISECT_START" to check if we are bisecting
@ 2008-05-28 16:57 Christian Couder
  2008-05-28 17:04 ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Christian Couder @ 2008-05-28 16:57 UTC (permalink / raw)
  To: Junio Hamano; +Cc: git

It seems simpler and safer to use the BISECT_START file everywhere
to decide if we are bisecting or not, instead of using it in some
places and BISECT_NAMES in other places.

In commit 6459c7c6786aa9bda0c7a095c9db66c36da0e5f0 (Nov 18 2007,
Bisect: use "$GIT_DIR/BISECT_NAMES" to check if we are bisecting.),
we decided to use BISECT_NAMES but code changed a lot and we now
have to check BISECT_START first in the "bisect_start" function
anyway.

This patch also makes things a little bit safer by creating
the BISECT_START file first and deleting it last, and also by
adding checks in "bisect_clean_state".

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 git-bisect.sh |   29 +++++++++++++----------------
 1 files changed, 13 insertions(+), 16 deletions(-)

	This is a cleanup to add on top of the detached HEAD series.
	Thanks.

diff --git a/git-bisect.sh b/git-bisect.sh
index 4bcbace..991b2ef 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,8 +146,8 @@ 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
 	#
@@ -226,7 +226,7 @@ bisect_next_check() {
 		;;
 	*)
 		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 '
 		}
@@ -392,16 +392,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,14 +412,15 @@ 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_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 () {
-- 
1.5.5.1.580.g40a12.dirty

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] bisect: use "$GIT_DIR/BISECT_START" to check if we are bisecting
  2008-05-28 16:57 [PATCH] bisect: use "$GIT_DIR/BISECT_START" to check if we are bisecting Christian Couder
@ 2008-05-28 17:04 ` Junio C Hamano
  2008-05-29  4:01   ` Christian Couder
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2008-05-28 17:04 UTC (permalink / raw)
  To: Christian Couder; +Cc: git

Christian Couder <chriscool@tuxfamily.org> writes:

> It seems simpler and safer to use the BISECT_START file everywhere
> to decide if we are bisecting or not, instead of using it in some
> places and BISECT_NAMES in other places.
>
> In commit 6459c7c6786aa9bda0c7a095c9db66c36da0e5f0 (Nov 18 2007,
> Bisect: use "$GIT_DIR/BISECT_NAMES" to check if we are bisecting.),
> we decided to use BISECT_NAMES but code changed a lot and we now
> have to check BISECT_START first in the "bisect_start" function
> anyway.
>
> This patch also makes things a little bit safer by creating
> the BISECT_START file first and deleting it last, and also by
> adding checks in "bisect_clean_state".
>
> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>

What's the breakage scenario that this patch fixes?

> diff --git a/git-bisect.sh b/git-bisect.sh
> index 4bcbace..991b2ef 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" || {

The reason you ignore an existing but empty BISECT_START file is...?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] bisect: use "$GIT_DIR/BISECT_START" to check if we are bisecting
  2008-05-28 17:04 ` Junio C Hamano
@ 2008-05-29  4:01   ` Christian Couder
  2008-05-29  4:28     ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Christian Couder @ 2008-05-29  4:01 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Le mercredi 28 mai 2008, Junio C Hamano a écrit :
> Christian Couder <chriscool@tuxfamily.org> writes:
> > It seems simpler and safer to use the BISECT_START file everywhere
> > to decide if we are bisecting or not, instead of using it in some
> > places and BISECT_NAMES in other places.
> >
> > In commit 6459c7c6786aa9bda0c7a095c9db66c36da0e5f0 (Nov 18 2007,
> > Bisect: use "$GIT_DIR/BISECT_NAMES" to check if we are bisecting.),
> > we decided to use BISECT_NAMES but code changed a lot and we now
> > have to check BISECT_START first in the "bisect_start" function
> > anyway.
> >
> > This patch also makes things a little bit safer by creating
> > the BISECT_START file first and deleting it last, and also by
> > adding checks in "bisect_clean_state".
> >
> > Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
>
> What's the breakage scenario that this patch fixes?

Before this patch, in "bisect_clean_state" we removed the BISECT_START file 
before the other files, so for example if the process is killed after 
having removed this file but not the others, then we are in an inconsistent 
state.

In this inconsistent state, if "git bisect reset" is called (perhaps again), 
then it would checkout the "master" branch (because the BISECT_START file 
does not exists, but the BISECT_NAMES file still exists).

> > diff --git a/git-bisect.sh b/git-bisect.sh
> > index 4bcbace..991b2ef 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" || {
>
> The reason you ignore an existing but empty BISECT_START file is...?

... that it should not happen, because this file is only written 
in "bisect_start" and there its content comes either from the current HEAD 
or from a previous not empty BISECT_START file.

We might add a check for an empty BISECT_START file and warn in this case 
that the file may have been corrupted, but that may be for another patch.

Thanks,
Christian.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] bisect: use "$GIT_DIR/BISECT_START" to check if we are bisecting
  2008-05-29  4:01   ` Christian Couder
@ 2008-05-29  4:28     ` Junio C Hamano
  0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2008-05-29  4:28 UTC (permalink / raw)
  To: Christian Couder; +Cc: git

Christian Couder <chriscool@tuxfamily.org> writes:

>> The reason you ignore an existing but empty BISECT_START file is...?
>
> ... that it should not happen, because this file is only written 
> in "bisect_start" and there its content comes either from the current HEAD 
> or from a previous not empty BISECT_START file.
>
> We might add a check for an empty BISECT_START file and warn in this case 
> that the file may have been corrupted, but that may be for another patch.

My question was more about "why are you acting as if distinction between
empty and nonempty BISECT_START matters?"

Because you "echo $start_head >$GIT_DIR/BISECT_START", this file will
always at least have a terminating LF even when the head is detached.
IOW, if it exists, it will never be empty, I think.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-05-29  4:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-28 16:57 [PATCH] bisect: use "$GIT_DIR/BISECT_START" to check if we are bisecting Christian Couder
2008-05-28 17:04 ` Junio C Hamano
2008-05-29  4:01   ` Christian Couder
2008-05-29  4:28     ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).