Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper way to find commit by sha with LibGit2Sharp

Repository have several types of commits:

  1. Commits which are branch heads
  2. Commits which are tag reference
  3. Parents of commits from point 1, 2 and 3.

How can I properly find commit by a SHA number?

My current solution:

return (Commit)repo.ObjectDatabase
  .First(o =>
    o.GetType() == typeof(Commit) &&
    o.Sha.Equals(shortSha, StringComparison.InvariantCultureIgnoreCase));

My current solution iterates by all git objects, and searching takes a while.

I think here must be a better way.

like image 579
Leszek Mazur Avatar asked Oct 17 '25 14:10

Leszek Mazur


1 Answers

return repo.Lookup<Commit>(sha);
like image 173
bret.ehlert Avatar answered Oct 20 '25 04:10

bret.ehlert