Skip to contentSkip to conversation

bisect: remove unnecessary redirection

PATCH In review David Aguilar 2 participants 5 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 bisect: remove unnecessary redirection

git rev-parse is being called with --quiet so there's no need to redirect to /dev/null.

---
 git-bisect.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
git-bisect.sh +1 -1
index 1e0d602..c1c2321 100755
@@ -365,7 +365,7 @@ bisect_reset() {
 	}
 	case "$#" in
 	0) branch=$(cat "$GIT_DIR/BISECT_START") ;;
-	1) git rev-parse --quiet --verify "$1^{commit}" >/dev/null || {
+	1) git rev-parse --quiet --verify "$1^{commit}" || {
 			invalid="$1"
 			die "$(eval_gettext "'\$invalid' is not a valid commit")"
 		}
Signature · 1 line
2.1.0.29.g9b751c4
#1 lore raw

PATCH 2/2 stash: prefer --quiet over shell redirection

Use git rev-parse --quiet instead of redirecting to /dev/null.

---
 git-stash.sh | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
git-stash.sh +7 -7
index bcc757b..5a5185b 100755
@@ -50,7 +50,7 @@ clear_stash () {
 	then
 		die "$(gettext "git stash clear with parameters is unimplemented")"
 	fi
-	if current=$(git rev-parse --verify $ref_stash 2>/dev/null)
+	if current=$(git rev-parse --quiet --verify $ref_stash)
 	then
 		git update-ref -d $ref_stash $current
 	fi
@@ -67,7 +67,7 @@ create_stash () {
 	fi
 
 	# state of the base commit
-	if b_commit=$(git rev-parse --verify HEAD)
+	if b_commit=$(git rev-parse --quiet --verify HEAD)
 	then
 		head=$(git rev-list --oneline -n 1 HEAD --)
 	else
@@ -292,7 +292,7 @@ save_stash () {
 }
 
 have_stash () {
-	git rev-parse --verify $ref_stash >/dev/null 2>&1
+	git rev-parse --quiet --verify $ref_stash
 }
 
 list_stash () {
@@ -392,12 +392,12 @@ parse_flags_and_rev()
 		;;
 	esac
 
-	REV=$(git rev-parse --quiet --symbolic --verify "$1" 2>/dev/null) || {
+	REV=$(git rev-parse --quiet --symbolic --verify "$1") || {
 		reference="$1"
 		die "$(eval_gettext "\$reference is not valid reference")"
 	}
 
-	i_commit=$(git rev-parse --quiet --verify "$REV^2" 2>/dev/null) &&
+	i_commit=$(git rev-parse --quiet --verify "$REV^2") &&
 	set -- $(git rev-parse "$REV" "$REV^1" "$REV:" "$REV^1:" "$REV^2:" 2>/dev/null) &&
 	s=$1 &&
 	w_commit=$1 &&
@@ -409,7 +409,7 @@ parse_flags_and_rev()
 	test "$ref_stash" = "$(git rev-parse --symbolic-full-name "${REV%@*}")" &&
 	IS_STASH_REF=t
 
-	u_commit=$(git rev-parse --quiet --verify "$REV^3" 2>/dev/null) &&
+	u_commit=$(git rev-parse --quiet --verify "$REV^3") &&
 	u_tree=$(git rev-parse "$REV^3:" 2>/dev/null)
 }
 
@@ -531,7 +531,7 @@ drop_stash () {
 		die "$(eval_gettext "\${REV}: Could not drop stash entry")"
 
 	# clear_stash if we just dropped the last stash entry
-	git rev-parse --verify "$ref_stash@{0}" >/dev/null 2>&1 || clear_stash
+	git rev-parse --quiet --verify "$ref_stash@{0}" || clear_stash
 }
 
 apply_to_branch () {
Signature · 1 line
2.1.0.29.g9b751c4
#2 lore raw

Re: [PATCH 2/2] stash: prefer --quiet over shell redirection

Am 30.08.2014 21:30, schrieb David Aguilar:

Quoted 21 lines

Use git rev-parse --quiet instead of redirecting to /dev/null.

---
 git-stash.sh | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
git-stash.sh +1 -1
index bcc757b..5a5185b 100755
@@ -50,7 +50,7 @@ clear_stash () {
 	then
 		die "$(gettext "git stash clear with parameters is unimplemented")"
 	fi
-	if current=$(git rev-parse --verify $ref_stash 2>/dev/null)
+	if current=$(git rev-parse --quiet --verify $ref_stash)
 	then
 		git update-ref -d $ref_stash $current
 	fi

git-stash.sh create_stash () { · line 73

Quoted 8 lines
git-stash.sh +1 -1
@@ -67,7 +67,7 @@ create_stash () {
 	fi
 
 	# state of the base commit
-	if b_commit=$(git rev-parse --verify HEAD)
+	if b_commit=$(git rev-parse --quiet --verify HEAD)
 	then
 		head=$(git rev-list --oneline -n 1 HEAD --)
 	else

The else branch calls die; wouldn't it be useful to keep the error message of rev-parse?

git-stash.sh save_stash () { · line 295

Quoted 6 lines
git-stash.sh +1 -1
@@ -292,7 +292,7 @@ save_stash () {
 }
 
 have_stash () {
-	git rev-parse --verify $ref_stash >/dev/null 2>&1
+	git rev-parse --quiet --verify $ref_stash

This change is not correct: --quiet removes only output on stderr, but not that on stdout.

Quoted 6 lines
git-stash.sh +0 -0
 }
 
 list_stash () {
@@ -392,12 +392,12 @@ parse_flags_and_rev()
 		;;
 	esac

git-stash.sh parse_flags_and_rev() · line 401

Quoted 10 lines
git-stash.sh +2 -2
 
-	REV=$(git rev-parse --quiet --symbolic --verify "$1" 2>/dev/null) || {
+	REV=$(git rev-parse --quiet --symbolic --verify "$1") || {
 		reference="$1"
 		die "$(eval_gettext "\$reference is not valid reference")"
 	}
 
-	i_commit=$(git rev-parse --quiet --verify "$REV^2" 2>/dev/null) &&
+	i_commit=$(git rev-parse --quiet --verify "$REV^2") &&
 	set -- $(git rev-parse "$REV" "$REV^1" "$REV:" "$REV^1:" "$REV^2:" 2>/dev/null) &&

I see another rev-parse that you did not modify. An omission?

git-stash.sh parse_flags_and_rev() · line 413

Quoted 9 lines
git-stash.sh +1 -1
 	s=$1 &&
 	w_commit=$1 &&
@@ -409,7 +409,7 @@ parse_flags_and_rev()
 	test "$ref_stash" = "$(git rev-parse --symbolic-full-name "${REV%@*}")" &&
 	IS_STASH_REF=t
 
-	u_commit=$(git rev-parse --quiet --verify "$REV^3" 2>/dev/null) &&
+	u_commit=$(git rev-parse --quiet --verify "$REV^3") &&
 	u_tree=$(git rev-parse "$REV^3:" 2>/dev/null)

I see yet another rev-parse that you did not modify.

git-stash.sh drop_stash () { · line 534

Quoted 8 lines
git-stash.sh +1 -1
 }
 
@@ -531,7 +531,7 @@ drop_stash () {
 		die "$(eval_gettext "\${REV}: Could not drop stash entry")"
 
 	# clear_stash if we just dropped the last stash entry
-	git rev-parse --verify "$ref_stash@{0}" >/dev/null 2>&1 || clear_stash
+	git rev-parse --quiet --verify "$ref_stash@{0}" || clear_stash

Again not correct.

git-stash.sh drop_stash () { · line 537

Quoted 4 lines
git-stash.sh +0 -0
 }
 
 apply_to_branch () {

-- Hannes

#3 lore raw

Re: [PATCH 2/2] stash: prefer --quiet over shell redirection

Quoted 11 lines · Johannes Sixt

Am 30.08.2014 21:30, schrieb David Aguilar:

Quoted 10 lines
git-stash.sh +1 -1
@@ -392,12 +392,12 @@ parse_flags_and_rev()
 		;;
 	esac
 
-	REV=$(git rev-parse --quiet --symbolic --verify "$1" 2>/dev/null) || {
+	REV=$(git rev-parse --quiet --symbolic --verify "$1") || {
 		reference="$1"
 		die "$(eval_gettext "\$reference is not valid reference")"
 	}
 
Quoted 5 lines

git-stash.sh parse_flags_and_rev() · line 401

Quoted 3 lines
git-stash.sh +1 -1
-	i_commit=$(git rev-parse --quiet --verify "$REV^2" 2>/dev/null) &&
+	i_commit=$(git rev-parse --quiet --verify "$REV^2") &&
 	set -- $(git rev-parse "$REV" "$REV^1" "$REV:" "$REV^1:" "$REV^2:" 2>/dev/null) &&

I see another rev-parse that you did not modify. An omission?

The docs for --quiet say, "Only meaningful in --verify mode", so I didn't touch the non-verify call-sites.

Thanks for the review. I'll address your notes and send a v2 shortly.

Signature · 1 line
David
#4 lore raw
In reply to David Aguilar

Am 30.08.2014 21:30, schrieb David Aguilar:

Quoted 13 lines

git rev-parse is being called with --quiet so there's no need to redirect to /dev/null.

---
 git-bisect.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
git-bisect.sh +0 -0
index 1e0d602..c1c2321 100755

git-bisect.sh bisect_reset() { · line 368

Quoted 5 lines
git-bisect.sh +1 -1
@@ -365,7 +365,7 @@ bisect_reset() {
 	}
 	case "$#" in
 	0) branch=$(cat "$GIT_DIR/BISECT_START") ;;
-	1) git rev-parse --quiet --verify "$1^{commit}" >/dev/null || {
+	1) git rev-parse --quiet --verify "$1^{commit}" || {

This is wrong. The redirection quells stdout, but --quiet is about stderr.

git-bisect.sh bisect_reset() { · line 371

Quoted 4 lines
git-bisect.sh +0 -0
 			invalid="$1"
 			die "$(eval_gettext "'\$invalid' is not a valid commit")"
 		}

-- Hannes