Skip to contentSkip to conversation

Use git-update-ref for updating the HEAD

PATCH New Jonas Fonseca 1 participant 2 messages Jun 15, 2016 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Use git-update-ref for updating the HEAD

Conditionally make git-update-ref check the old head. For this to succeed for the initial commit, cg-init should not touch .git/refs/heads/master, and the touching seems to be redundant anyway, so remove it.

---
commit b41f8cafc556233613412ff3545e3507202b666a
tree 9e2c5d8d467acc27d7c866c908990d7de44478f9
parent b06f2a707963c8712f7a6bbd4b89bae758bcf92a
author Jonas Fonseca <[email protected]> Thu, 29 Sep 2005 15:09:06 +0200 committer Jonas Fonseca <[email protected]> Thu, 29 Sep 2005 15:09:06 +0200

 cg-Xlib   |    2 +-
 cg-commit |    2 +-
 cg-init   |    1 -
 3 files changed, 2 insertions(+), 3 deletions(-)
cg-Xlib +1 -1
@@ -246,7 +246,7 @@ tree_timewarp()
 	fi
 
 	git-read-tree -m "$branch" || die "$branch: bad commit"
-	[ "$no_head_update" ] || echo "$branch" > $_git/HEAD
+	[ "$no_head_update" ] || git-update-ref HEAD "$branch"
 
 	# Kill gone files
 	git-diff-tree -z -r $base $branch | xargs -0 bash -c '
cg-commit +1 -1
@@ -420,7 +420,7 @@ fi
 
 if [ "$newhead" ]; then
 	echo "Committed as $newhead."
-	echo $newhead >$_git/HEAD
+	git-update-ref HEAD $newhead $oldhead
 	[ "$merging" ] && rm $_git/merging $_git/merging-sym $_git/merge-base
 	rm -f "$_git/commit-ignore"
 
cg-init +0 -1
@@ -48,7 +48,6 @@ done
 cleanup_trap "rm -rf $_git"
 
 git-init-db
-touch $_git/refs/heads/master
 
 git-read-tree # Seed the dircache
 if ! [ "$no_initial_commit" ]; then
Signature · 1 line
Jonas Fonseca
#1 lore raw

PATCH 1/1 Use git-{update,symbolic}-ref for updating HEAD

Conditionally make git-update-ref check the old head. For this to succeed for the initial commit, cg-init should not touch .git/refs/heads/master, and the touching seems to be redundant anyway, so remove it.

This should make Cogito mostly work on cygwin.

---

This is an incremental update to make Cogito handle symbolic refs.

I am not sure whether the change from using '[ -L .git/HEAD ]' to using
'[ -e .git/HEAD ]' is the thing to do. And I haven't used it so much yet; did a few commit and so on. And the tests fails do to local cloning not working yet (git-local-fetch needs to be fixed).

 Makefile                        |    2 +-
 cg-Xlib                         |    4 ++--
 cg-commit                       |    4 ++--
 cg-init                         |    1 -
 cg-object-id                    |    2 +-

---

Makefile +1 -1
index f0a0590..9eacade 100644
@@ -35,7 +35,7 @@ all: cogito
 cogito: $(GEN_SCRIPT)
 
 ifneq (,$(wildcard .git))
-GIT_HEAD=.git/HEAD
+GIT_HEAD=.git/$(shell git-symbolic-ref HEAD)
 GIT_HEAD_ID=" \($(shell cat $(GIT_HEAD))\)"
 endif
 cg-version: $(VERSION) $(GIT_HEAD) Makefile
cg-Xlib +2 -2
index b27e8b9..dcf9aa3 100755
@@ -246,7 +246,7 @@ tree_timewarp()
 	fi
 
 	git-read-tree -m "$branch" || die "$branch: bad commit"
-	[ "$no_head_update" ] || echo "$branch" > $_git/HEAD
+	[ "$no_head_update" ] || git-update-ref HEAD "$branch"
 
 	# Kill gone files
 	git-diff-tree -z -r $base $branch | xargs -0 bash -c '
@@ -471,7 +471,7 @@ if [ ! "$_git_repo_unneeded" ]; then
 	       exit 1
 	fi
 	_git_head=master
-	[ -L "$_git/HEAD" ] && _git_head="$(basename "$(readlink "$_git/HEAD")")"
+	[ -e "$_git/HEAD" ] && _git_head="$(basename "$(git-symbolic-ref HEAD)")"
 	[ -s "$_git/head-name" ] && _git_head="$(cat "$_git/head-name")"
 fi
 
cg-commit +2 -2
index 4345bd5..6024f17 100755
@@ -396,7 +396,7 @@ fi
 
 oldhead=
 if [ -s "$_git/HEAD" ]; then
-	oldhead=$(cat $_git/HEAD)
+	oldhead=$(git-symbolic-ref HEAD)
 	oldheadstr="-p $oldhead"
 fi
 
@@ -420,7 +420,7 @@ fi
 
 if [ "$newhead" ]; then
 	echo "Committed as $newhead."
-	echo $newhead >$_git/HEAD
+	git-update-ref HEAD $newhead $oldhead 
 	[ "$merging" ] && rm $_git/merging $_git/merging-sym $_git/merge-base
 	rm -f "$_git/commit-ignore"
 
cg-init +0 -1
index 570c83e..65faf84 100755
@@ -48,7 +48,6 @@ done
 cleanup_trap "rm -rf $_git"
 
 git-init-db
-touch $_git/refs/heads/master
 
 git-read-tree # Seed the dircache
 if ! [ "$no_initial_commit" ]; then
cg-object-id +1 -1
index 2ae9420..5c03626 100755
@@ -53,7 +53,7 @@ normalize_id()
 	fi
 
 	if [ ! "$id" ] || [ "$id" = "this" ] || [ "$id" = "HEAD" ]; then
-		read id < "$_git/HEAD"
+		read id < "$_git/$(git-symbolic-ref HEAD)"
 
 	elif [ -r "$_git/refs/tags/$id" ]; then
 		read id < "$_git/refs/tags/$id"
Signature · 1 line
Jonas Fonseca