Copy git_merge__bases_many() for new ahead-behind code

To be used as a basis for a function which marks nodes with parents
up to the merge base.
Morph copy of git_merge__bases_many() -> mark_parents()

Integrate mark_parents() with the ahead_behind() code.
Fix no_common_ancestor test for ahead_behind count

Ahead-behind count is still a valid operation, even if the two
commits don't have a common merge-base. The old implementation was
buggy, so it returned ENOTFOUND. Fixed now.
Fix mark_parents() to account for bad luck traversals

If commit timestamps are off, we're more likely to hit a traversal
where the first path ends up traversing past the root commit of the tree.
If that happens, it's possible that the loop will complete before the second
path marks some of those final parents. This fix keeps track of the root
nodes that are encountered in the traversal, and verify that they are
properly marked.

In the best case, with accurate timestamps, the traversal will continue
to terminate when all the commits are STALE (parents of a merge-base), as
it did before. In the worst case, where one path makes a complete traversal
past a root commit, we will continue the loop until the root commit itself
is marked.
Fix a bunch of leaks, error handling cases
Merge pull request #1131 from libgit2/correct-ahead-behind

Fix an issue with ahead-behind for lopsided traversal