在git2go(libgit2)中查找包含指定blob对象的提交

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?

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.