pub(super) fn revwalk_count_commits_since(
repo: &git2::Repository,
head_commit_id: git2::Oid,
start_commit_id: git2::Oid,
limit: usize,
) -> std::io::Result<usize> {
let commits = collect_revwalk_results(repo, head_commit_id, start_commit_id, limit)?;
Ok(commits.len())
}
fn collect_revwalk_results(
repo: &git2::Repository,
head_commit_id: git2::Oid,
start_commit_id: git2::Oid,
limit: usize,
) -> std::io::Result<Vec<git2::Oid>> {
let mut revwalk = repo
.revwalk()
.map_err(|e| std::io::Error::other(e.to_string()))?;
revwalk
.push(head_commit_id)
.map_err(|e| std::io::Error::other(e.to_string()))?;
revwalk
.map(|res| res.map_err(|e| std::io::Error::other(e.to_string())))
.take_while(|res| res.as_ref().map_or(true, |id| *id != start_commit_id))
.take(limit)
.collect()
}