threads / patch / 7453

patchbisect: use update-ref to update refs

Subject: [PATCH] bisect: use update-ref to update refs

## tl;dr

3 messages between Mar 28, 2007 and Mar 28, 2007. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

Uwe Kleine-König· Mar 28, 2007, 12:35 UTC · lore

update-ref is safer than manualy echoing values to various files in $GIT_DIR/refs/heads/.

bisect predates update-ref and was never updated to use the latter.
Signed-off-by: Uwe Kleine-König <ukleinek@informatik.uni-freiburg.de>
---

There are some style nits in git-bisect.sh that I found while producing that patch. E.g. the 3rd hunk shows

	GIT_DIR="$GIT_DIR" git-$command ...

where the assignment to GIT_DIR should be superfluous? In some places git-command is used, and in other git command.

 git-bisect.sh |   13 +++++++------
 1 files changed, 7 insertions(+), 6 deletions(-)
Show changes to git-bisect.sh +7 −6
diff --git a/git-bisect.sh b/git-bisect.sh
index a12ea31..1589870 100755
--- a/git-bisect.sh
+++ b/git-bisect.sh
@@ -90,7 +90,7 @@ bisect_bad() {
 	*)
 		usage ;;
 	esac || exit
-	echo "$rev" >"$GIT_DIR/refs/bisect/bad"
+	git update-ref "refs/bisect/bad" "$rev"
 	echo "# bad: "$(git-show-branch $rev) >>"$GIT_DIR/BISECT_LOG"
 	echo "git-bisect bad $rev" >>"$GIT_DIR/BISECT_LOG"
 	bisect_auto_next
@@ -106,7 +106,7 @@ bisect_good() {
 	for rev in $revs
 	do
 		rev=$(git-rev-parse --verify "$rev^{commit}") || exit
-		echo "$rev" >"$GIT_DIR/refs/bisect/good-$rev"
+		git update-ref "refs/bisect/good-$rev" "$rev"
 		echo "# good: "$(git-show-branch $rev) >>"$GIT_DIR/BISECT_LOG"
 		echo "git-bisect good $rev" >>"$GIT_DIR/BISECT_LOG"
 	done
@@ -159,9 +159,10 @@ bisect_next() {
 		nr="$nr_good";
 	fi;
 	echo "Bisecting: maximal $nr revisions left to test"
-	echo "$rev" > "$GIT_DIR/refs/heads/new-bisect"
+	git update-ref refs/heads/new-bisect "$rev"
 	git checkout -q new-bisect || exit
-	mv "$GIT_DIR/refs/heads/new-bisect" "$GIT_DIR/refs/heads/bisect" &&
+	git update-ref refs/heads/bisect "$rev" &&
+	git update-ref -d refs/heads/new-bisect "$rev" &&
 	GIT_DIR="$GIT_DIR" git-symbolic-ref HEAD refs/heads/bisect
 	git-show-branch "$rev"
 }
@@ -211,12 +212,12 @@ bisect_replay () {
 			eval "$cmd"
 			;;
 		good)
-			echo "$rev" >"$GIT_DIR/refs/bisect/good-$rev"
+			git update-ref "refs/bisect/good-$rev" "$rev"
 			echo "# good: "$(git-show-branch $rev) >>"$GIT_DIR/BISECT_LOG"
 			echo "git-bisect good $rev" >>"$GIT_DIR/BISECT_LOG"
 			;;
 		bad)
-			echo "$rev" >"$GIT_DIR/refs/bisect/bad"
+			git update-ref "refs/bisect/bad" "$rev"
 			echo "# bad: "$(git-show-branch $rev) >>"$GIT_DIR/BISECT_LOG"
 			echo "git-bisect bad $rev" >>"$GIT_DIR/BISECT_LOG"
 			;;
-- 
1.5.0.2.260.g2eb065


-- 
Uwe Kleine-König

http://www.google.com/search?q=1+newton+in+kg*m+%2F+s%5E2
Johannes Sixt· Mar 28, 2007, 13:46 UTC · re: Uwe Kleine-König · lore

Re: [PATCH] bisect: use update-ref to update refs

Uwe Kleine-König wrote:
>         GIT_DIR="$GIT_DIR" git-$command ...
> 
> where the assignment to GIT_DIR should be superfluous?

git-sh-setup sets GIT_DIR, but does not export it. Therefore, this assignment is *not* superfluous (its effect is to export GIT_DIR for this command only).

-- Hannes
Uwe Kleine-König· Mar 28, 2007, 14:10 UTC · re: Johannes Sixt · lore

Re: [PATCH] bisect: use update-ref to update refs

Johannes Sixt wrote:
Show 8 quoted lines
> Uwe Kleine-König wrote:
> >         GIT_DIR="$GIT_DIR" git-$command ...
> > 
> > where the assignment to GIT_DIR should be superfluous?
> 
> git-sh-setup sets GIT_DIR, but does not export it. Therefore, this
> assignment is *not* superfluous (its effect is to export GIT_DIR for
> this command only).

..., but why do only two invocations of git get GIT_DIR="$GIT_DIR" and the other 20+ don't?

Best regards Uwe

-- 
Uwe Kleine-König

http://www.google.com/search?q=sine+of+%2830+degree%29

← back to recent threads