librelist archives

« back to archive

Getting a list of a tags on a repository

Getting a list of a tags on a repository

From:
Mikael Helbo Kjær
Date:
2011-03-16 @ 13:07
Hi guys
 
I am building a solution based on libgit2 and I was wondering if it was 
possible to somehow build a list of all tags on a repository with the 
current API. It seems to me that you pretty much lose touch with your tags
after you put them on a commit unless you keep a list of them elsewhere. 
Any suggestions how to accomplish this is most welcome.

I am having a lot of fun tying the library together with my codebase and 
replacing a git shell invocation tool with the library is offering great 
benefits so kudos for doing the heavy lifting.
 
Regards,
Mikael H. Kjaer
Software Engineer @ Designtech ApS

Re: [libgit2] Getting a list of a tags on a repository

From:
Vicent Marti
Date:
2011-03-16 @ 16:21
Hey Mikael,

glad to hear you are finding libgit2 useful when replacing git shell
invocations in your codebase. :)

Regarding your issue, here's what's going on:

- When git.git creates a new tag, it creates a tag object in the ODB,
and it also creates a direct reference in the refs/tags/ folder
pointing to that object.
- Since libgit2 implements the low level plumbing commands of git,
when you create a new git_tag and write it to the ODB, you are also
expected to create a reference (`git_reference_create_oid`) pointing
to that tag object you've created. That's the proper way to create a
tag -- we may automate this process in a following release (i.e.
having a method that writes the object and the reference at the same
time).
- If you create all your references this way, you can use the
`git_reference_listall` method (use a GIT_REF_OID filter) and you'll
get a list of all the tags that exist in your repository. Boom!

I hope this answered your question,

stay awesome & using libgit2,
Vicent Marti



2011/3/16 Mikael Helbo Kjær <mhk@designtech.dk>:
> Hi guys
>
> I am building a solution based on libgit2 and I was wondering if it was 
possible to somehow build a list of all tags on a repository with the 
current API. It seems to me that you pretty much lose touch with your tags
after you put them on a commit unless you keep a list of them elsewhere. 
Any suggestions how to accomplish this is most welcome.
>
> I am having a lot of fun tying the library together with my codebase and
replacing a git shell invocation tool with the library is offering great 
benefits so kudos for doing the heavy lifting.
>
> Regards,
> Mikael H. Kjaer
> Software Engineer @ Designtech ApS
>

Re: [libgit2] Getting a list of a tags on a repository

From:
Mike Rosset
Date:
2011-03-16 @ 14:00
2011/3/16 Mikael Helbo Kjær <mhk@designtech.dk>

> Hi guys
>
> I am building a solution based on libgit2 and I was wondering if it was
> possible to somehow build a list of all tags on a repository with the
> current API. It seems to me that you pretty much lose touch with your tags
> after you put them on a commit unless you keep a list of them elsewhere. Any
> suggestions how to accomplish this is most welcome.
>
> I am having a lot of fun tying the library together with my codebase and
> replacing a git shell invocation tool with the library is offering great
> benefits so kudos for doing the heavy lifting.
>
> Regards,
> Mikael H. Kjaer
> Software Engineer @ Designtech ApS
>

Mikael read the refs/tags/ dir then use git_reference_lookup . there maybe a
better way to get a list of tags then this. if there is it probably uses the
same method.

Regards,

Mike

Re: [libgit2] Getting a list of a tags on a repository

From:
Mikael Helbo Kjær
Date:
2011-03-16 @ 14:16
Thank you for the reply

 

I knew about the refs/tags dir, but what refs type should I give to 
git_reference_lookup?

 

Regards,

Mikael

 

 

Mikael read the refs/tags/ dir then use git_reference_lookup . there maybe
a better way to get a list of tags then this. if there is it probably uses
the same method.

 

Regards,

 

Mike

Re: [libgit2] Getting a list of a tags on a repository

From:
Mike Rosset
Date:
2011-03-16 @ 14:20
2011/3/16 Mikael Helbo Kjær <mhk@designtech.dk>

> Thank you for the reply
>
>
>
> I knew about the refs/tags dir, but what refs type should I give to
> git_reference_lookup?
>
>
>
> Regards,
>
> Mikael
>

use a empty reference one will be created after you pass it through
get_refrence_lookup.

Re: [libgit2] Getting a list of a tags on a repository

From:
Thomas Rast
Date:
2011-03-16 @ 14:19
Mike Rosset wrote:
> Mikael read the refs/tags/ dir then use git_reference_lookup . there maybe a
> better way to get a list of tags then this. if there is it probably uses the
> same method.

That's not enough because packed_refs may also contain tags.

(Sorry, I can't really help with how to *solve* the problem, but this
isn't it.)

-- 
Thomas Rast
trast@{inf,student}.ethz.ch