2

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;
Anders
  • 17,306
  • 10
  • 76
  • 144

1 Answers1

0

I don't really know NGit, but couldn't you just count commits directly instead of allCommits?

var commits = git.Log().AddPath("SubPath").Call().OrderByDescending(c => c.CommitTime);
var index = commits
.Select((c, i) => new {Commit = c, Index = i})
.Index;
Klas Mellbourn
  • 42,571
  • 24
  • 140
  • 158
  • That will only get the count from that path, I want to get the count from all commits so that I can use it for version number. – Anders Jun 08 '13 at 19:26
  • In that case, I (for one) am really confused about what you're asking. Do you want the count up to the commit that introduced the given subfolder? – jpaugh Jun 13 '13 at 07:52
  • Sorry missed this comment. I want the count (Or maybe call it index) for the given subfolder, but the count must be based on the total count. You get me? :D Lets say you have 10 commits for entire repo. In a subfolder there are 4 commits, the latest commit in that subfolder is also the latest commit for entire repo. THe result should then me 10.. Hope I make myself clear – Anders Jun 19 '13 at 08:03