11using LibGit2Sharp ;
22using vv . CLI . Rendering ;
33using vv . CLI . Settings ;
4+ using vv . Core ;
45
56namespace vv . CLI . Commands ;
67
@@ -13,40 +14,8 @@ protected override int ExecuteImpl(GitSettings settings)
1314 var repoPath = ResolvePath . ResolveRepoPath ( settings ) ;
1415 using var repo = new Repository ( repoPath ) ;
1516
16- var currentBranchLastCommit = repo . Head . Commits . First ( ) ;
17- var currentBranchFirstCommit = repo . Head . Commits . Last ( ) ;
18-
19- var lastCommit = repo . Commits . First ( ) ;
20- var firstCommit = repo . Commits . Last ( ) ;
21-
22- var contributors = repo . Commits
23- . GroupBy ( c => c . Author . Email )
24- . Select ( g => new
25- {
26- Name = g . First ( ) . Author . Name ,
27- Email = g . Key ,
28- CommitCount = g . Count ( )
29- } )
30- . OrderByDescending ( c => c . CommitCount )
31- . ToList ( ) ;
32-
33- string currentBranchName = repo . Head . FriendlyName ;
34- int currentBranchTotalCommits = repo . Head . Commits . Count ( ) ;
35- string currentBranchLastCommitDate = currentBranchLastCommit . Committer . When . ToString ( "dd.MM.yyyy HH:mm:ss" ) ;
36- string currentBranchLastCommitMessage = currentBranchLastCommit . MessageShort ;
37- string currentBranchFirstCommitDate = currentBranchFirstCommit . Committer . When . ToString ( "dd.MM.yyyy HH:mm:ss" ) ;
38- string currentBranchFirstCommitMessage = currentBranchFirstCommit . MessageShort ;
39-
40- int totalCommits = repo . Commits . Count ( ) ;
41- string lastCommitMessage = lastCommit . MessageShort ;
42- string lastCommitDate = lastCommit . Committer . When . ToString ( "dd.MM.yyyy HH:mm:ss" ) ;
43- string firstCommitMessage = firstCommit . MessageShort ;
44- string firstCommitDate = firstCommit . Committer . When . ToString ( "dd.MM.yyyy HH:mm:ss" ) ;
45-
46- int totalBranches = repo . Branches . Count ( b => ! b . IsRemote ) ;
47-
48- int totalContributors = contributors . Count ;
49- var topContributors = contributors . Take ( MAX_TOP_COUNT ) ;
17+ var repoData = RepositoriesHandle . GetRepoData ( repo , MAX_TOP_COUNT ) ;
18+ var currentBranchData = RepositoriesHandle . GetBranchData ( repo . Head ) ;
5019
5120 DefaultRendering . Rule ( "[blue]Repo git stats[/]" ) ;
5221
@@ -57,53 +26,45 @@ protected override int ExecuteImpl(GitSettings settings)
5726
5827 var specifiedBranchTable = DefaultRendering . Table ( "Content" , "Value" ) ;
5928
60- var specifiedBranch = repo . Branches [ specifiedBranchGivenName ] ;
61- var specifiedBranchFirstCommit = specifiedBranch . Commits . Last ( ) ;
62- var specifiedBranchLastCommit = specifiedBranch . Commits . First ( ) ;
29+ var specifiedBranchData = RepositoriesHandle . GetBranchData ( repo . Branches [ specifiedBranchGivenName ] ) ;
6330
64- string specifiedBranchName = specifiedBranch . FriendlyName ;
65- int specifiedBranchTotalCommits = specifiedBranch . Commits . Count ( ) ;
66-
67- string specifiedBranchLastCommitDate = specifiedBranchLastCommit . Committer . When . ToString ( "dd.MM.yyyy HH:mm:ss" ) ; ;
68- string specifiedBranchLastCommitMessage = specifiedBranchLastCommit . MessageShort ;
69-
70- string specifiedBranchFirstCommitDate = specifiedBranchFirstCommit . Committer . When . ToString ( "dd.MM.yyyy HH:mm:ss" ) ; ;
71- string specifiedBranchFirstCommitMessage = specifiedBranchFirstCommit . MessageShort ;
72-
73- DisplayBranch ( specifiedBranchName , specifiedBranchTotalCommits , specifiedBranchFirstCommitMessage ,
74- specifiedBranchFirstCommitDate , specifiedBranchLastCommitMessage , specifiedBranchLastCommitDate , specifiedBranchTable ) ;
31+ DisplayBranch ( specifiedBranchData . Name , specifiedBranchData . TotalCommits ,
32+ specifiedBranchData . FirstCommitMessage , specifiedBranchData . FirstCommitDate ,
33+ specifiedBranchData . LastCommitMessage , specifiedBranchData . LastCommitDate ,
34+ specifiedBranchTable ) ;
7535
7636 AnsiConsole . Write ( specifiedBranchTable ) ;
7737 }
7838
7939 var statsTable = DefaultRendering . Table ( "Content" , "Value" ) ;
8040
81- DisplayBranch ( currentBranchName , currentBranchTotalCommits , currentBranchFirstCommitMessage ,
82- currentBranchFirstCommitDate , currentBranchLastCommitMessage , currentBranchLastCommitDate , statsTable ) ;
41+ DisplayBranch ( currentBranchData . Name , currentBranchData . TotalCommits ,
42+ currentBranchData . FirstCommitMessage , currentBranchData . FirstCommitDate ,
43+ currentBranchData . LastCommitMessage , currentBranchData . LastCommitDate ,
44+ statsTable ) ;
8345
8446 // Don't use DisplayBranch since it's global repo stats
8547 statsTable . AddEmptyRow ( ) ;
86- statsTable . AddRow ( "Commits" , $ "{ totalCommits } ") ;
87- statsTable . AddRow ( "First commit message" , firstCommitMessage ) ;
88- statsTable . AddRow ( "First commit date" , firstCommitDate ) ;
89- statsTable . AddRow ( "Last commit message" , lastCommitMessage ) ;
90- statsTable . AddRow ( "Last commit date" , lastCommitDate ) ;
48+ statsTable . AddRow ( "Commits" , $ "{ repoData . TotalCommits } ") ;
49+ statsTable . AddRow ( "First commit date" , repoData . FirstCommitDate ) ;
50+ statsTable . AddRow ( "Last commit date" , repoData . LastCommitDate ) ;
9151 statsTable . AddEmptyRow ( ) ;
92- statsTable . AddRow ( "Branches" , $ "{ totalBranches } ") ;
52+ statsTable . AddRow ( "Branches" , $ "{ repoData . TotalBranches } ") ;
9353 statsTable . AddEmptyRow ( ) ;
94- statsTable . AddRow ( "Contributors" , $ "{ totalContributors } ") ;
54+ statsTable . AddRow ( "Contributors" , $ "{ repoData . TotalCommits } ") ;
9555
96- foreach ( var contributor in topContributors )
97- statsTable . AddRow ( contributor . Name , $ "{ contributor . CommitCount } ") ;
56+ foreach ( var contributor in repoData . TopContributors )
57+ statsTable . AddRow ( contributor . Name , $ "{ contributor . CommitsCount } ") ;
9858
9959 AnsiConsole . Write ( statsTable ) ;
10060 return 0 ;
10161 }
10262
10363 private void DisplayBranch ( string branchName , int branchTotalCommits , string firstCommitMessage ,
104- string firstCommitDate , string lastCommitMessage , string lastCommitDate , Table table ,
105- string displayBranchName = "Current" )
64+ string firstCommitDate , string lastCommitMessage , string lastCommitDate , Table table )
10665 {
66+ var displayBranchName = "Current" ;
67+
10768 table . AddRow ( $ "{ displayBranchName } branch", branchName ) ;
10869 table . AddRow ( $ "{ displayBranchName } branch commits", $ "{ branchTotalCommits } ") ;
10970 table . AddRow ( $ "{ displayBranchName } branch first commit", firstCommitMessage ) ;
0 commit comments