# name-ref on annotated-tags is null terminated, but lightweight tags arent

4 messages from 2020-06-05 to 2020-06-05. Participants: Max Resnick, Junio C Hamano.
Thread: https://gitlist.dev/t/53618

## Max Resnick, 2020-06-05 16:51

Subject: name-ref on annotated-tags is null terminated, but lightweight tags arent
Message-ID: <20200605165109.jr6mjl6xz7upofdy@forgemax.local>
URL: https://gitlist.dev/e/20200605165109.jr6mjl6xz7upofdy%40forgemax.local

```
Thank you for filling out a Git bug report!
Please answer the following questions to help us understand your issue.

What did you do before the bug happened? (Steps to reproduce your issue)
I was using name-rev to resolve a commits tag name. Annotated tags seem
to have a null termination and lightweight tags dont.
ˋˋˋ
/tmp
❯ git clone https://github.com/maxres-fr/null-termination-issue.git
Cloning into 'null-termination-issue'...
remote: Enumerating objects: 10, done.
remote: Counting objects: 100% (10/10), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 10 (delta 0), reused 10 (delta 0), pack-reused 0
Unpacking objects: 100% (10/10), 757 bytes | 189.00 KiB/s, done.

/tmp
❯ cd null-termination-issue

/tmp/null-termination-issue on  master
❯ git pull --tags
Already up to date.

/tmp/null-termination-issue on  master
❯ git tag --list

/tmp/null-termination-issue on  master
❯ git name-rev --tag --name-only
38bdebc9107cab4ab3718d0581632702e74d9209
annotated-tag^0

/tmp/null-termination-issue on  master
❯ git name-rev --tag --name-only
a340894d3ee655ae6c336a85b42d2215d52609e3
lightweight-tag
ˋˋˋ

What did you expect to happen? (Expected behavior)

`git name-rev --tag --name-only ANNOTATED-COMMIT-ID` to return the name
without null termination

What happened instead? (Actual behavior)

`git name-rev --tag --name-only ANNOTATED-COMMIT-ID` returns the name
but it's null terminated

What's different between what you expected and what actually happened?

a null control character exists.

Anything else you want to add:

I tried this with the following git versions:

2.11, 2.23, 2.26, 2.27. I've also been able to reproduce on MacOS.

Please review the rest of the bug report below.
You can delete any lines you don't wish to share.

[System Info]
git version:
git version 2.27.0.rc0
cpu: x86_64
no commit associated with this build
sizeof-long: 8
sizeof-size_t: 8
uname: Linux 5.6.0-1-amd64 #1 SMP Debian 5.6.7-1 (2020-04-29) x86_64
compiler info: gnuc: 9.3
libc info: glibc: 2.30


[Enabled Hooks]


```

## Junio C Hamano, 2020-06-05 17:04

Subject: Re: name-ref on annotated-tags is null terminated, but lightweight tags arent
Message-ID: <xmqqa71ho34p.fsf@gitster.c.googlers.com>
URL: https://gitlist.dev/e/xmqqa71ho34p.fsf%40gitster.c.googlers.com
In-Reply-To: <20200605165109.jr6mjl6xz7upofdy@forgemax.local>

```
Max Resnick <max.resnick@forgerock.com> writes:

> What did you do before the bug happened? (Steps to reproduce your issue)
> I was using name-rev to resolve a commits tag name. Annotated tags seem
> to have a null termination and lightweight tags dont.

> ❯ git name-rev --tag --name-only
> 38bdebc9107cab4ab3718d0581632702e74d9209
> annotated-tag^0
>
> /tmp/null-termination-issue on  master
> ❯ git name-rev --tag --name-only
> a340894d3ee655ae6c336a85b42d2215d52609e3
> lightweight-tag

Presumably the long hexadecimal are supposed to be on the same line
as the "name-rev" command itself?

There is nothing broken in the above output.  The anotated tag
(annotated-tag in your example) is an object that merely points at
another object (in which case, the object whose name is 38bdebc9,
which I guess would be a commit) and it itself has an object name
different from 38bdebc9.  The suffix "^0" (which has nothing to do
with null-termination) means "I do not mean the tag object itself,
but the object that is pointed by it".

On the other hand, your lightweight-tag is directly pointing at the
object a340894d, so saying "lightweight-tag" is sufficient, as there
is no extra layer of indirection (i.e. a tag object) involved.

Hope it helps.

```

## Max Resnick, 2020-06-05 17:16

Subject: Re: name-ref on annotated-tags is null terminated, but lightweight tags arent
Message-ID: <20200605171607.rducvc4xretxacn5@forgemax.local>
URL: https://gitlist.dev/e/20200605171607.rducvc4xretxacn5%40forgemax.local
In-Reply-To: <xmqqa71ho34p.fsf@gitster.c.googlers.com>

```

Thanks Junio for the quick response.

> Presumably the long hexadecimal are supposed to be on the same line 
> as the "name-rev" command itself?                                   

Yes, sorry I didn't see that the formatting was broken before I sent.

> The suffix "^0" (which has nothing to do 
> with null-termination) means "I do not mean the tag object itself, 
> but the object that is pointed by it".                             

Ok, thanks. I need to unpack that a bit more. I tried to dig around in
the man to see if there was indication if that's what was expected but
didn't find anything at less for name-rev.



On 20/06/05 10:04AM, Junio C Hamano wrote:
> Max Resnick <max.resnick@forgerock.com> writes:
> 
> > What did you do before the bug happened? (Steps to reproduce your issue)
> > I was using name-rev to resolve a commits tag name. Annotated tags seem
> > to have a null termination and lightweight tags dont.
> 
> > ❯ git name-rev --tag --name-only
> > 38bdebc9107cab4ab3718d0581632702e74d9209
> > annotated-tag^0
> >
> > /tmp/null-termination-issue on  master
> > ❯ git name-rev --tag --name-only
> > a340894d3ee655ae6c336a85b42d2215d52609e3
> > lightweight-tag
> 
> Presumably the long hexadecimal are supposed to be on the same line
> as the "name-rev" command itself?
> 
> There is nothing broken in the above output.  The anotated tag
> (annotated-tag in your example) is an object that merely points at
> another object (in which case, the object whose name is 38bdebc9,
> which I guess would be a commit) and it itself has an object name
> different from 38bdebc9.  The suffix "^0" (which has nothing to do
> with null-termination) means "I do not mean the tag object itself,
> but the object that is pointed by it".
> 
> On the other hand, your lightweight-tag is directly pointing at the
> object a340894d, so saying "lightweight-tag" is sufficient, as there
> is no extra layer of indirection (i.e. a tag object) involved.
> 
> Hope it helps.

```

## Junio C Hamano, 2020-06-05 17:59

Subject: Re: name-ref on annotated-tags is null terminated, but lightweight tags arent
Message-ID: <xmqq3679o0lr.fsf@gitster.c.googlers.com>
URL: https://gitlist.dev/e/xmqq3679o0lr.fsf%40gitster.c.googlers.com
In-Reply-To: <20200605171607.rducvc4xretxacn5@forgemax.local>

```
Max Resnick <max.resnick@forgerock.com> writes:

> Thanks Junio for the quick response.
>
>> Presumably the long hexadecimal are supposed to be on the same line 
>> as the "name-rev" command itself?                                   
>
> Yes, sorry I didn't see that the formatting was broken before I sent.
>
>> The suffix "^0" (which has nothing to do 
>> with null-termination) means "I do not mean the tag object itself, 
>> but the object that is pointed by it".                             
>
> Ok, thanks. I need to unpack that a bit more. I tried to dig around in
> the man to see if there was indication if that's what was expected but
> didn't find anything at less for name-rev.

"git help revisions" has this, which may help.

       <rev>^[<n>], e.g. HEAD^, v1.5.1^0
                  A suffix ^ to a revision parameter means the first
                  parent of that commit object.  ^<n> means the
                  <n>th parent (i.e.  <rev>^ is equivalent to
                  <rev>^1).  As a special rule, <rev>^0 means the
                  commit itself and is used when <rev> is the object
                  name of a tag object that refers to a commit
                  object.

The help text in "git help name-rev" only says "names suitable for
human digestion", which may want to be clarified.

Thanks.

```
