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

[PATCH] Dereference tag repeatedly until we get a non-tag.

From
Junio C Hamano <junkio@cox.net>
Date
Jul 11, 2005, 06:55 UTC
Message-ID
<7v8y0dx24j.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<7v7jg0wb77.fsf@assigned-by-dhcp.cox.net>

When we allow a tag object in place of a commit object, we only dereferenced the given tag once, which causes a tag that points at a tag that points at a commit to be rejected. Instead, dereference tag repeatedly until we get a non-tag.

This patch makes change to two functions:
 - commit.c::lookup_commit_reference() is used by merge-base,
   rev-tree and rev-parse to convert user supplied SHA1 to that of
   a commit.
 - rev-list uses its own get_commit_reference() to do the same.
Dereferencing tags this way helps both of these uses.
Signed-off-by: Junio C Hamano <junkio@cox.net>
---

*** Whether having a tag pointing at another tag is a separate *** issue, but I do not see a reason to forbid it. Maybe it *** is used to represent a chain of trust.

 commit.c   |    5 +++--
 rev-list.c |    4 ++--
 2 files changed, 5 insertions(+), 4 deletions(-)
0dc9377363ee73c5e3f3711d6f82e49886ce8c6a
diff --git a/commit.c b/commit.c
--- a/commit.c
+++ b/commit.c
@@ -52,8 +52,9 @@ struct commit *lookup_commit_reference(c
 
 	if (!obj)
 		return NULL;
-	if (obj->type == tag_type)
-		obj = ((struct tag *)obj)->tagged;
+	while (obj->type == tag_type)
+		obj = parse_object(((struct tag *)obj)->tagged->sha1);
+
 	return check_commit(obj, sha1);
 }
 
diff --git a/rev-list.c b/rev-list.c
--- a/rev-list.c
+++ b/rev-list.c
@@ -367,12 +367,12 @@ static struct commit *get_commit_referen
 	/*
 	 * Tag object? Look what it points to..
 	 */
-	if (object->type == tag_type) {
+	while (object->type == tag_type) {
 		struct tag *tag = (struct tag *) object;
 		object->flags |= flags;
 		if (tag_objects && !(object->flags & UNINTERESTING))
 			add_pending_object(object, tag->tag);
-		object = tag->tagged;
+		object = parse_object(tag->tagged->sha1);
 	}
 
 	/*
Previous: Junio C HamanoNext: Jon Seymour
Message 2 of 3 in “tag referring to a commit but not directly?”
  1. Junio C HamanoJul 9, 2005
  2. Dereference tag repeatedly until we get a non-tag.Junio C Hamano, Jul 11, 2005
  3. Jon SeymourJul 11, 2005

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.