Leszek Mazur
Leszek Mazur

Reputation: 2531

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.

Upvotes: 4

Views: 1134

Answers (1)

bret.ehlert
bret.ehlert

Reputation: 76

return repo.Lookup<Commit>(sha);

Upvotes: 6

Related Questions