The code below retrieves all the references that can reach the selected commit.
using( Repository repo = new Repository( path_to_repo ) )
{
foreach( Commit commit in repo.Commits )
{
IEnumerable<Reference> refs =
repo.Refs.ReachableFrom(new[] { commit });
}
}
If you want to only retrieve Tag
s, the method exposes an overload to help you with this.
using( Repository repo = new Repository( path_to_repo ) )
{
var allTags = repo.Refs.Where(r => r.IsTag()).ToList();
foreach( Commit commit in repo.Commits )
{
IEnumerable<Reference> refs =
repo.Refs.ReachableFrom(allTags, new[] { commit });
}
}
Note: This code will retrieve all refs that either directly point to the chosen commit or point to an ancestor of this commit. In this sense, it behaves similarly to the git rev-list command.
repo.Refs.ReachableFrom
is very slow. I guess I have to get all Refs once and map them into a dictionary if I want to display a list of commits along with its refs (likegit log --decorate
)? – Demulsify