# [PATCH] do not loop around deref_tag()

2 messages from 2016-06-16 to 2016-06-16. Participants: Junio C Hamano, Jeff King.
Thread: https://gitlist.dev/t/42612

## Junio C Hamano, 2016-06-14 20:28

Subject: [PATCH] do not loop around deref_tag()
Message-ID: <xmqqfusf8qh4.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqfusf8qh4.fsf%40gitster.mtv.corp.google.com

```
These callers appear to expect that deref_tag() is to peel one layer
of a tag, but the function does not work that way; it has its own
loop to unwrap tags until an object that is not a tag appears.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin/blame.c | 6 ++----
 line-log.c      | 3 +--
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/builtin/blame.c b/builtin/blame.c
index 21f42b0..7417edf 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -2425,8 +2425,7 @@ static struct commit *find_single_final(struct rev_info *revs,
 		struct object *obj = revs->pending.objects[i].item;
 		if (obj->flags & UNINTERESTING)
 			continue;
-		while (obj->type == OBJ_TAG)
-			obj = deref_tag(obj, NULL, 0);
+		obj = deref_tag(obj, NULL, 0);
 		if (obj->type != OBJ_COMMIT)
 			die("Non commit %s?", revs->pending.objects[i].name);
 		if (found)
@@ -2461,8 +2460,7 @@ static char *prepare_initial(struct scoreboard *sb)
 		struct object *obj = revs->pending.objects[i].item;
 		if (!(obj->flags & UNINTERESTING))
 			continue;
-		while (obj->type == OBJ_TAG)
-			obj = deref_tag(obj, NULL, 0);
+		obj = deref_tag(obj, NULL, 0);
 		if (obj->type != OBJ_COMMIT)
 			die("Non commit %s?", revs->pending.objects[i].name);
 		if (sb->final)
diff --git a/line-log.c b/line-log.c
index bbe31ed..1fbbe4f 100644
--- a/line-log.c
+++ b/line-log.c
@@ -480,8 +480,7 @@ static struct commit *check_single_commit(struct rev_info *revs)
 		struct object *obj = revs->pending.objects[i].item;
 		if (obj->flags & UNINTERESTING)
 			continue;
-		while (obj->type == OBJ_TAG)
-			obj = deref_tag(obj, NULL, 0);
+		obj = deref_tag(obj, NULL, 0);
 		if (obj->type != OBJ_COMMIT)
 			die("Non commit %s?", revs->pending.objects[i].name);
 		if (commit)

```

## Jeff King, 2016-06-14 21:21

Subject: Re: [PATCH] do not loop around deref_tag()
Message-ID: <20160614212105.GA21445@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20160614212105.GA21445%40sigill.intra.peff.net
In-Reply-To: <xmqqfusf8qh4.fsf@gitster.mtv.corp.google.com>

```
On Tue, Jun 14, 2016 at 01:28:39PM -0700, Junio C Hamano wrote:

> These callers appear to expect that deref_tag() is to peel one layer
> of a tag, but the function does not work that way; it has its own
> loop to unwrap tags until an object that is not a tag appears.

Looks obviously correct.

-Peff

```
