libgit2/libgit2 — pull request #1108 by scottjg (2012-11-28 00:49:28+00:00)
Title: Add API to calculate ahead/behind count

Given two commits, it tells you how many parents are unique to each commit.

I'm concerned the algorithm might be subtly wrong, in that it relys on the merge-base algorithm to mark the commits first, and there are some cases where the merge-base algorithm might stop early with the STALE commit detection? I don't totally understand that part of the code.

That being said, all the existing test cases where the existing merge-base is running appear to give proper results for ahead-behind.