With libgit2sharp I would like to do the following:
foreach( Commit commit in repo.Commits )
{
// How to implement assignedTags?
foreach( Tag tag in commit.assignedTags ) {}
}
I want to get all tags assigned to the current commit. Whats the best way to do that? Iterate through all Tags and see if tag.Target.Sha == commit.Sha
? Thats not very performant. Is there another way?
There are two things to take into account when it comes to Tags.
The code below should fit your need by taking these points above into account.
Note:
repo.Commits
will only enumerate the commits reachable from the current branch (HEAD
). The code below extends this to easily browse all the reachable commits.Here is another version of nulltoken's answer but with using
ILookup
class instead of dictionary. A bit nicer IMO:and simple usage example: