git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>, Ingo Molnar <mingo@elte.hu>,
	Git Mailing List <git@vger.kernel.org>
Subject: [PATCH 1/2] fsck: HEAD is part of refs
Date: Fri, 30 Jan 2009 01:12:48 -0800	[thread overview]
Message-ID: <7veiylb1in.fsf_-_@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <alpine.LFD.2.00.0901291512260.3054@localhost.localdomain> (Linus Torvalds's message of "Thu, 29 Jan 2009 15:21:55 -0800 (PST)")

By default we looked at all refs but not HEAD.  The only thing that
made fsck not lose sight of comments that are only reachable from a
detached HEAD was the reflog for the HEAD.

This fixes it, with a new test.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---

 * This is unrelated to Peter's "missing blob", but should be an obviously
   right thing to do. 

 builtin-fsck.c  |   13 ++++++++-----
 t/t1450-fsck.sh |   18 ++++++++++++++++++
 2 files changed, 26 insertions(+), 5 deletions(-)
 create mode 100755 t/t1450-fsck.sh

diff --git a/builtin-fsck.c b/builtin-fsck.c
index aecc828..2cfff43 100644
--- a/builtin-fsck.c
+++ b/builtin-fsck.c
@@ -23,6 +23,7 @@ static int check_full;
 static int check_strict;
 static int keep_cache_objects;
 static unsigned char head_sha1[20];
+static const char *head_points_at;
 static int errors_found;
 static int write_lost_and_found;
 static int verbose;
@@ -473,6 +474,8 @@ static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int f
 
 static void get_default_heads(void)
 {
+	if (head_points_at && !is_null_sha1(head_sha1))
+		fsck_handle_ref("HEAD", head_sha1, 0, NULL);
 	for_each_ref(fsck_handle_ref, NULL);
 	if (include_reflogs)
 		for_each_reflog(fsck_handle_reflog, NULL);
@@ -512,14 +515,13 @@ static void fsck_object_dir(const char *path)
 
 static int fsck_head_link(void)
 {
-	unsigned char sha1[20];
 	int flag;
 	int null_is_error = 0;
-	const char *head_points_at = resolve_ref("HEAD", sha1, 0, &flag);
 
 	if (verbose)
 		fprintf(stderr, "Checking HEAD link\n");
 
+	head_points_at = resolve_ref("HEAD", head_sha1, 0, &flag);
 	if (!head_points_at)
 		return error("Invalid HEAD");
 	if (!strcmp(head_points_at, "HEAD"))
@@ -528,7 +530,7 @@ static int fsck_head_link(void)
 	else if (prefixcmp(head_points_at, "refs/heads/"))
 		return error("HEAD points to something strange (%s)",
 			     head_points_at);
-	if (is_null_sha1(sha1)) {
+	if (is_null_sha1(head_sha1)) {
 		if (null_is_error)
 			return error("HEAD: detached HEAD points at nothing");
 		fprintf(stderr, "notice: HEAD points to an unborn branch (%s)\n",
@@ -624,8 +626,9 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
 	heads = 0;
 	for (i = 0; i < argc; i++) {
 		const char *arg = argv[i];
-		if (!get_sha1(arg, head_sha1)) {
-			struct object *obj = lookup_object(head_sha1);
+		unsigned char sha1[20];
+		if (!get_sha1(arg, sha1)) {
+			struct object *obj = lookup_object(sha1);
 
 			/* Error is printed by lookup_object(). */
 			if (!obj)
diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh
new file mode 100755
index 0000000..5166566
--- /dev/null
+++ b/t/t1450-fsck.sh
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+test_description='git fsck random collection of tests'
+
+. ./test-lib.sh
+
+test_expect_success setup '
+	test_commit A &&
+	git checkout HEAD^0 &&
+	test_commit B &&
+	git reflog expire --expire=now --all
+'
+
+test_expect_success 'HEAD is part of refs' '
+	test 0 = $(git fsck | wc -l)
+'
+
+test_done
-- 
1.6.1.2.312.g5be3c

  reply	other threads:[~2009-01-30  9:14 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-29  6:24 Something weird is happening H. Peter Anvin
2009-01-29  6:56 ` Junio C Hamano
     [not found]   ` <20090129113846.GA10645@elte.hu>
2009-01-29 12:05     ` Ingo Molnar
2009-01-29 22:20       ` René Scharfe
2009-01-29 23:01         ` Daniel Barkalow
2009-01-31 14:39       ` [PATCH] merge: fix out-of-bounds memory access René Scharfe
2009-01-29 13:45   ` Something weird is happening Sverre Rabbelier
2009-02-01  1:31     ` Junio C Hamano
2009-01-29 10:50 ` Ingo Molnar
2009-01-29 10:52   ` Ingo Molnar
2009-01-29 21:45 ` Junio C Hamano
2009-01-29 22:10   ` H. Peter Anvin
2009-01-29 22:35     ` Ingo Molnar
     [not found]       ` <20090129224357.GA18471@elte.hu>
2009-01-29 22:47         ` H. Peter Anvin
2009-01-29 22:57           ` Junio C Hamano
2009-01-29 23:21             ` Linus Torvalds
2009-01-30  9:12               ` Junio C Hamano [this message]
2009-01-30  9:27                 ` [PATCH 1/2] fsck: HEAD is part of refs Johannes Sixt
2009-02-01  0:53                   ` Junio C Hamano
2009-01-30 16:47                 ` Johannes Schindelin
2009-01-31 21:45                 ` Nanako Shiraishi
2009-02-01  0:57                   ` Junio C Hamano
2009-01-30  9:13               ` [PATCH 2/2] fsck: check loose objects from alternate object stores by default Junio C Hamano
2009-01-29 22:34   ` Something weird is happening Ingo Molnar
2009-01-29 22:36     ` H. Peter Anvin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7veiylb1in.fsf_-_@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=hpa@zytor.com \
    --cc=mingo@elte.hu \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).