git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Remove branch by putting a null sha1 into the ref file.
@ 2006-09-18  4:54 Christian Couder
  2006-09-18  5:47 ` Junio C Hamano
  2006-09-18 16:31 ` Linus Torvalds
  0 siblings, 2 replies; 19+ messages in thread
From: Christian Couder @ 2006-09-18  4:54 UTC (permalink / raw)
  To: Junio Hamano; +Cc: git

With the new packed ref file format from Linus, this should be
the new way to remove a branch.

"refs.c" is fixed so that a null sha1 for a deleted branch does
not result in "refs/head/deleted does not point to a valid
commit object!" messages.

"t/t3200-branch.sh" is fixed so that it uses git-show-ref
instead of checking that the ref does not exist when a branch
is deleted.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 git-branch.sh     |    6 +++++-
 refs.c            |    2 ++
 t/t3200-branch.sh |    2 +-
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/git-branch.sh b/git-branch.sh
index 2600e9c..cb55880 100755
--- a/git-branch.sh
+++ b/git-branch.sh
@@ -10,6 +10,9 @@ SUBDIRECTORY_OK='Yes'
 
 headref=$(git-symbolic-ref HEAD | sed -e 's|^refs/heads/||')
 
+# Fourty 0s.
+NULL_SHA1="0000000000000000000000000000000000000000" 
+
 delete_branch () {
     option="$1"
     shift
@@ -43,7 +46,8 @@ If you are sure you want to delete it, r
 	    ;;
 	esac
 	rm -f "$GIT_DIR/logs/refs/heads/$branch_name"
-	rm -f "$GIT_DIR/refs/heads/$branch_name"
+	echo $NULL_SHA1 > "$GIT_DIR/refs/heads/$branch_name" || \
+	    die "Failed to delete branch '$branch_name' !"
 	echo "Deleted branch $branch_name."
     done
     exit 0
diff --git a/refs.c b/refs.c
index 5e65314..76d8d0e 100644
--- a/refs.c
+++ b/refs.c
@@ -162,6 +162,8 @@ static int do_for_each_ref(const char *b
 				error("%s points nowhere!", path);
 				continue;
 			}
+			if (is_null_sha1(sha1))
+				continue; /* Ignore deleted refs. */
 			if (!has_sha1_file(sha1)) {
 				error("%s does not point to a valid "
 				      "commit object!", path);
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index 5b04efc..150dfdc 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -47,7 +47,7 @@ test_expect_success \
 test_expect_success \
     'git branch -d d/e/f should delete a branch and a log' \
 	'git-branch -d d/e/f &&
-	 test ! -f .git/refs/heads/d/e/f &&
+	 ! git-show-ref --verify --quiet -- "refs/heads/d/e/f" &&
 	 test ! -f .git/logs/refs/heads/d/e/f'
 
 cat >expect <<EOF
-- 
1.4.2.1.g4251-dirty

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

end of thread, other threads:[~2006-09-27  7:25 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-18  4:54 [PATCH] Remove branch by putting a null sha1 into the ref file Christian Couder
2006-09-18  5:47 ` Junio C Hamano
2006-09-18 16:31 ` Linus Torvalds
2006-09-18 18:43   ` Junio C Hamano
2006-09-20  2:56   ` Christian Couder
2006-09-22 22:09   ` Junio C Hamano
2006-09-23  4:45     ` Christian Couder
2006-09-23  8:04       ` Junio C Hamano
2006-09-23 11:22         ` Christian Couder
2006-09-23 21:49           ` Junio C Hamano
2006-09-24  4:45             ` Christian Couder
2006-09-25  9:26               ` On ref locking Junio C Hamano
2006-09-25 17:05                 ` Daniel Barkalow
2006-09-26  4:11                   ` Junio C Hamano
2006-09-26  4:13                 ` [PATCH 1/3] Clean-up lock-ref implementation Junio C Hamano
2006-09-26  4:13                 ` [PATCH 2/3] update-ref: -d flag and ref creation safety Junio C Hamano
2006-09-26 18:05                 ` [PATCH 3/3] update a few Porcelain-ish for ref lock safety Junio C Hamano
2006-09-26 18:08                   ` Andy Whitcroft
2006-09-27  7:25                     ` 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).