git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <junkio@cox.net>
To: Linus Torvalds <torvalds@osdl.org>
Cc: git@vger.kernel.org
Subject: [PATCH] Dereference tag repeatedly until we get a non-tag.
Date: Sun, 10 Jul 2005 23:55:56 -0700	[thread overview]
Message-ID: <7v8y0dx24j.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: <7v7jg0wb77.fsf@assigned-by-dhcp.cox.net> (Junio C. Hamano's message of "Sat, 09 Jul 2005 03:00:44 -0700")

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);
 	}
 
 	/*

  reply	other threads:[~2005-07-11  6:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-09 10:00 tag referring to a commit but not directly? Junio C Hamano
2005-07-11  6:55 ` Junio C Hamano [this message]
2005-07-11 15:14   ` [PATCH] Dereference tag repeatedly until we get a non-tag Jon Seymour

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=7v8y0dx24j.fsf@assigned-by-dhcp.cox.net \
    --to=junkio@cox.net \
    --cc=git@vger.kernel.org \
    --cc=torvalds@osdl.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).