1

Given a blob object, how can you find the (first) commit that contains that object?

One solution I think is to start a revwalk from the tip of a branch and walk your way down the graph, inspecting the tree for each commit and use something like git_tree_entry_byid to see if it contains your object. This would find commits accessible from a particular branch, but it is a solution in my case.

Is there a better way of doing this?

Calin
  • 2,110
  • 1
  • 21
  • 36
  • This may be duplicate of http://stackoverflow.com/questions/223678/which-commit-has-this-blob – joran Jul 25 '15 at 18:00
  • 1
    Pretty much yes but the solution uses git cli not libgit or git2go, and it's basically the same idea as written in this question. – Calin Jul 26 '15 at 11:48

1 Answers1

0

If you want to check whether an object is contained in a particular commit, the only way to do that is to walk down the object graph and see if it's there.

There is however one way you can re-use some of those searches. If you diff a pair of commits, and you know that the object in question is contained (or not) in one of them, you can look at the diff for the appearance/disappearance of that blob from the commit's tree, which would avoid walking down equal trees.

git supports reachability bitmaps, which make this rather quick, but libgit2 does not support reading them.

Carlos Martín Nieto
  • 5,207
  • 1
  • 15
  • 16