Proper way to find commit by sha with LibGit2Sharp

Viewed 551

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.

1 Answers
return repo.Lookup<Commit>(sha);
Related