git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] fsck: check loose objects from alternate object stores by default

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 30, 2009, 09:13 UTC
Message-ID
<7vd4e5b1i7.fsf_-_@gitster.siamese.dyndns.org>
In-Reply-To
<alpine.LFD.2.00.0901291512260.3054@localhost.localdomain>

"git fsck" used to validate only loose objects that are local and nothing else by default. This is not just too little when a repository is borrowing objects from other object stores, but also caused the connectivity check to mistakenly declare loose objects borrowed from them to be missing.

The rationale behind the default mode that validates only loose objects is because these objects are still young and more unlikely to have been pushed to other repositories yet. That holds for loose objects borrowed from alternate object stores as well.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * This implements your earlier suggestion.  We might want to say where
   the corrupt object was found when fsck_sha1() reports problems, but
   that is an issue that already exists when the command is run with
   --full.
 builtin-fsck.c  |   21 ++++++++++++---------
 t/t1450-fsck.sh |   16 ++++++++++++++--
 2 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/builtin-fsck.c b/builtin-fsck.c
index 2cfff43..64dffa5 100644
--- a/builtin-fsck.c
+++ b/builtin-fsck.c
@@ -586,6 +586,7 @@ static struct option fsck_opts[] = {
 int cmd_fsck(int argc, const char **argv, const char *prefix)
 {
 	int i, heads;
+	struct alternate_object_database *alt;
 
 	errors_found = 0;
 
@@ -597,17 +598,19 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
 
 	fsck_head_link();
 	fsck_object_dir(get_object_directory());
+
+	prepare_alt_odb();
+	for (alt = alt_odb_list; alt; alt = alt->next) {
+		char namebuf[PATH_MAX];
+		int namelen = alt->name - alt->base;
+		memcpy(namebuf, alt->base, namelen);
+		namebuf[namelen - 1] = 0;
+		fsck_object_dir(namebuf);
+	}
+
 	if (check_full) {
-		struct alternate_object_database *alt;
 		struct packed_git *p;
-		prepare_alt_odb();
-		for (alt = alt_odb_list; alt; alt = alt->next) {
-			char namebuf[PATH_MAX];
-			int namelen = alt->name - alt->base;
-			memcpy(namebuf, alt->base, namelen);
-			namebuf[namelen - 1] = 0;
-			fsck_object_dir(namebuf);
-		}
+
 		prepare_packed_git();
 		for (p = packed_git; p; p = p->next)
 			/* verify gives error messages itself */
diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh
index 5166566..6e64e44 100755
--- a/t/t1450-fsck.sh
+++ b/t/t1450-fsck.sh
@@ -5,9 +5,9 @@ test_description='git fsck random collection of tests'
 . ./test-lib.sh
 
 test_expect_success setup '
-	test_commit A &&
+	test_commit A fileA one &&
 	git checkout HEAD^0 &&
-	test_commit B &&
+	test_commit B fileB two &&
 	git reflog expire --expire=now --all
 '
 
@@ -15,4 +15,16 @@ test_expect_success 'HEAD is part of refs' '
 	test 0 = $(git fsck | wc -l)
 '
 
+test_expect_success 'loose objects borrowed from alternate are not missing' '
+	mkdir another &&
+	(
+		cd another &&
+		git init &&
+		echo ../../../.git/objects >.git/objects/info/alternates &&
+		test_commit C fileC one &&
+		git fsck >out &&
+		! grep "missing blob" out
+	)
+'
+
 test_done
-- 
1.6.1.2.312.g5be3c
Previous: Junio C Hamano
Message 25 of 25 in “Something weird is happening...”
  1. H. Peter AnvinJan 29, 2009
  2. Junio C HamanoJan 29, 2009
  3. Sverre RabbelierJan 29, 2009
  4. Junio C HamanoFeb 1, 2009
  5. Ingo MolnarJan 29, 2009
  6. Ingo MolnarJan 29, 2009
  7. Junio C HamanoJan 29, 2009
  8. H. Peter AnvinJan 29, 2009
  9. Ingo MolnarJan 29, 2009
  10. Ingo MolnarJan 29, 2009
  11. H. Peter AnvinJan 29, 2009
  12. Ingo MolnarJan 29, 2009
  13. René ScharfeJan 29, 2009
  14. Daniel BarkalowJan 29, 2009
  15. merge: fix out-of-bounds memory accessRené Scharfe, Jan 31, 2009
  16. H. Peter AnvinJan 29, 2009
  17. Junio C HamanoJan 29, 2009
  18. Linus TorvaldsJan 29, 2009
  19. 1/2 fsck: HEAD is part of refsJunio C Hamano, Jan 30, 2009
  20. Johannes SixtJan 30, 2009
  21. Junio C HamanoFeb 1, 2009
  22. Johannes SchindelinJan 30, 2009
  23. Nanako ShiraishiJan 31, 2009
  24. Junio C HamanoFeb 1, 2009
  25. 2/2 fsck: check loose objects from alternate object stores by defaultJunio C Hamano, Jan 30, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.