File tree Expand file tree Collapse file tree 4 files changed +45
-7
lines changed Expand file tree Collapse file tree 4 files changed +45
-7
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ name = "git-commit-stats"
33version = " 0.1.22"
44edition = " 2021"
55authors = [" Alexander Konietzko <me@alexanderkonietzko.com>" ]
6- license-file = " LICENSE "
6+ license = " MIT "
77description = " A tool to analyze git commits"
88readme = " README.md"
99homepage = " https://github.com/alex289/git-commit-stats"
Original file line number Diff line number Diff line change @@ -28,6 +28,11 @@ update: 77
2828Commit activity:
2929Most active day: 05-01-2024 with 33 commits
3030Most active hour: 14 with 19 commits
31+
32+ Top 3 committers:
33+ Alex: 88
34+ alex289: 36
35+ github-actions[bot]: 23
3136```
3237
3338## Features
@@ -61,12 +66,20 @@ A tool to analyze git commits
6166Usage: git-commit-stats [OPTIONS]
6267
6368Options:
64- -r, --repo-path < REPO_PATH> Path to the Git repository (default = current directory) [default: ]
65- -a, --after < AFTER> Commit hash which commits should be analyzed (default = all) [default: ]
66- -b, --before < BEFORE> Commit hash before which commits should be analyzed (default = all) [default: ]
67- -u, --user < USER> User name for commit analysis (default = git config user.name) [default: ]
68- -h, --help Print help
69- -V, --version Print version
69+ -r, --repo-path < REPO_PATH>
70+ Path to the Git repository (default = current directory) [default: ]
71+ -a, --after < AFTER>
72+ Commit hash which commits should be analyzed (default = all) [default: ]
73+ -b, --before < BEFORE>
74+ Commit hash before which commits should be analyzed (default = all) [default: ]
75+ -u, --user < USER>
76+ User name for commit analysis (default = git config user.name) [default: ]
77+ -t, --top-committers < TOP_COMMITTERS>
78+ Amount of of top committers to show (default = 3) [default: 3]
79+ -h, --help
80+ Print help
81+ -V, --version
82+ Print version
7083```
7184
7285### Contributing
Original file line number Diff line number Diff line change @@ -155,6 +155,25 @@ pub(crate) fn show_coding_habits(commits: &Vec<Commit>) {
155155 ) ;
156156}
157157
158+ pub ( crate ) fn show_top_committers ( max : usize , commits : & Vec < Commit > ) {
159+ let mut commit_counts: HashMap < String , usize > = HashMap :: new ( ) ;
160+
161+ for commit in commits {
162+ if let Some ( author_name) = commit. author ( ) . name ( ) {
163+ * commit_counts. entry ( author_name. to_string ( ) ) . or_insert ( 0 ) += commit. parent_count ( ) ;
164+ }
165+ }
166+
167+ let mut top_committers: Vec < ( & String , & usize ) > = commit_counts. iter ( ) . collect ( ) ;
168+
169+ top_committers. sort_by ( |a, b| b. 1 . cmp ( a. 1 ) ) ;
170+
171+ println ! ( "Top {} committers:" , max) ;
172+ for ( name, count) in top_committers. iter ( ) . take ( max) {
173+ println ! ( "{}: {}" , name, count) ;
174+ }
175+ }
176+
158177/// Get the user name from the Git configuration.
159178pub ( crate ) fn get_user_name ( ) -> String {
160179 git2:: Config :: open_default ( )
Original file line number Diff line number Diff line change @@ -22,6 +22,10 @@ struct Args {
2222 /// User name for commit analysis (default = git config user.name)
2323 #[ arg( short, long, default_value = "" ) ]
2424 user : String ,
25+
26+ /// Amount of of top committers to show (default = 3)
27+ #[ arg( short, long, default_value_t = 3 ) ]
28+ top_committers : usize ,
2529}
2630
2731fn main ( ) {
@@ -81,6 +85,8 @@ fn main() {
8185 analyzer:: show_commit_stats ( & stats) ;
8286 println ! ( ) ;
8387 analyzer:: show_coding_habits ( & commits_vec) ;
88+ println ! ( ) ;
89+ analyzer:: show_top_committers ( args. top_committers , & commits_vec) ;
8490}
8591
8692/// Check if the specified path is a directory and a Git repository.
You can’t perform that action at this time.
0 commit comments