Im using NGit with C# to get data from our repo
I'm trying to figure out how to get the commit count of a sub folder in a repo from the current branch.
Something like (but with subfolder support)
git rev-list --count HEAD
edit: This works but it feels like there must be a better and faster way. for a large repo this would take time to complete
var git = Git.Open(@"repoPath");
var allCommits = git.Log().Call().OrderBy(c => c.CommitTime);
var commit = git.Log().AddPath("SubPath").Call().OrderByDescending(c => c.CommitTime).First();
var index = allCommits
.Select((c, i) => new {Commit = c, Index = i})
.First(c => c.Commit.Id.Name == commit.Id.Name)
.Index;
I don't really know NGit, but couldn't you just count
commits
directly instead ofallCommits
?