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

[PATCH 4/4] tag: don't emit potentially incorrect "object is a X, not a Y"

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Nov 18, 2022, 11:46 UTC
Message-ID
<patch-4.4-1a9dcb9e05d-20221118T113442Z-avarab@gmail.com>
In-Reply-To
<cover-0.4-00000000000-20221118T113442Z-avarab@gmail.com>

As noted in the preceding commit we weren't handling cases where we see a reference to a bad "type" in a "tag", but then end up not fully parsing the object.

In those cases let's only claim that we have a bad tag pointer, but emit "is a %s, not a %s".

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t6102-rev-list-unexpected-objects.sh | 6 +++---
 tag.c                                  | 5 +++--
 2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/t/t6102-rev-list-unexpected-objects.sh b/t/t6102-rev-list-unexpected-objects.sh
index 2e36d8bcfd9..ffc1672d7dc 100755
--- a/t/t6102-rev-list-unexpected-objects.sh
+++ b/t/t6102-rev-list-unexpected-objects.sh
@@ -231,7 +231,7 @@ test_expect_success 'traverse unexpected non-tag tag (tree seen to blob)' '
 '
 
 
-test_expect_failure 'traverse unexpected objects with for-each-ref' '
+test_expect_success 'traverse unexpected objects with for-each-ref' '
 	cat >expect <<-EOF &&
 	error: bad tag pointer to $tree in $tag_tag_tree
 	fatal: parse_object_buffer failed on $tag_tag_tree for refs/tags/tag_tag_tree
@@ -241,7 +241,7 @@ test_expect_failure 'traverse unexpected objects with for-each-ref' '
 '
 
 >fsck-object-isa
-test_expect_failure 'setup: unexpected objects with fsck' '
+test_expect_success 'setup: unexpected objects with fsck' '
 	test_must_fail git fsck 2>err &&
 	sed -n -e "/^error: object .* is a .*, not a .*$/ {
 		s/^error: object \([0-9a-f]*\) is a \([a-z]*\), not a [a-z]*$/\\1 \\2/;
@@ -251,7 +251,7 @@ test_expect_failure 'setup: unexpected objects with fsck' '
 
 while read oid type
 do
-	test_expect_failure "fsck knows unexpected object $oid is $type" '
+	test_expect_success "fsck knows unexpected object $oid is $type" '
 		git cat-file -t $oid >expect &&
 		echo $type >actual &&
 		test_cmp expect actual
diff --git a/tag.c b/tag.c
index 19453c2edbf..ad92cf89209 100644
--- a/tag.c
+++ b/tag.c
@@ -193,8 +193,9 @@ int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, u
 	}
 
 	if (!item->tagged || strcmp(type_name(item->tagged->type), type)) {
-		error(_("object %s is a %s, not a %s"), oid_to_hex(&oid),
-		      type_name(item->tagged->type), type);
+		if (item->tagged && item->tagged->parsed)
+			error(_("object %s is a %s, not a %s"), oid_to_hex(&oid),
+			      type_name(item->tagged->type), type);
 		return error("bad tag pointer to %s in %s",
 			     oid_to_hex(&oid),
 			     oid_to_hex(&item->object.oid));
-- 
2.38.0.1511.gcdcff1f1dc2
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 12 of 22 in “object.c: use has_object() instead of repo_has_object_file()”
  1. Kousik SanagavarapuNov 16, 2022
  2. Jeff KingNov 16, 2022
  3. Jonathan TanNov 16, 2022
  4. 0/2 fixing parse_object() check for type mismatchJeff King, Nov 17, 2022
  5. 1/2 parse_object(): drop extra "has" check before checking object typeJeff King, Nov 17, 2022
  6. 2/2 parse_object(): check on-disk type of suspected blobJeff King, Nov 17, 2022
  7. Ævar Arnfjörð BjarmasonNov 18, 2022
  8. Jeff KingNov 21, 2022
  9. 0/4 tag: don't misreport type of tagged objects in errorsÆvar Arnfjörð Bjarmason, Nov 18, 2022
  10. 1/4 object-file.c: free the "t.tag" in check_tag()Ævar Arnfjörð Bjarmason, Nov 18, 2022
  11. 2/4 object tests: add test for unexpected objects in tagsÆvar Arnfjörð Bjarmason, Nov 18, 2022
  12. 4/4 tag: don't emit potentially incorrect "object is a X, not a Y"Ævar Arnfjörð Bjarmason, Nov 18, 2022
  13. 3/4 tag: don't misreport type of tagged objects in errorsÆvar Arnfjörð Bjarmason, Nov 18, 2022
  14. 0/3 tag: don't misreport type of tagged objects in errorsÆvar Arnfjörð Bjarmason, Dec 30, 2022
  15. 1/3 object tests: add test for unexpected objects in tagsÆvar Arnfjörð Bjarmason, Dec 30, 2022
  16. Junio C HamanoDec 30, 2022
  17. 3/3 tag: don't emit potentially incorrect "object is a X, not a Y"Ævar Arnfjörð Bjarmason, Dec 30, 2022
  18. 2/3 tag: don't misreport type of tagged objects in errorsÆvar Arnfjörð Bjarmason, Dec 30, 2022
  19. Junio C HamanoDec 30, 2022
  20. Taylor BlauNov 18, 2022
  21. Jeff KingNov 21, 2022
  22. Ævar Arnfjörð BjarmasonNov 22, 2022

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.