Created
October 21, 2011 20:29
-
-
Save r2p2/1304867 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/perl -w | |
| use strict; | |
| use warnings; | |
| my $debug = 0; | |
| my $progress = 1; | |
| my %users = (); | |
| sub print_debug { | |
| if($debug == 1) { | |
| print(shift(@_) . "\n"); | |
| } | |
| } | |
| sub print_progress { | |
| if($progress == 0) { | |
| return; | |
| } | |
| my $process = shift @_; | |
| my $current = shift @_; | |
| my $maximum = shift @_; | |
| printf "%5d/%-5d %s\r", $current, $maximum, $process; | |
| } | |
| sub user_exists { | |
| exists $users{shift @_}; | |
| } | |
| sub create_user { | |
| $users{shift @_} = { | |
| 'lines_in_code' => 0, | |
| 'lines_in_code_except_empty' => 0, | |
| 'commits' => 0, | |
| 'smallest_commit' => 0, | |
| 'biggest_commit' => 0 | |
| }; | |
| } | |
| sub parse_git_blame { | |
| my @vcfiles = `git ls-files`; | |
| my $last_author = 'Unknown Unknown'; | |
| my $last_email = '[email protected]'; | |
| my $current_file_index = 0; | |
| my $file_count = @vcfiles; | |
| foreach (@vcfiles) { | |
| my $vcfile = $_; | |
| my @blame = `git blame --porcelain $vcfile`; | |
| $current_file_index = $current_file_index + 1; | |
| print_progress("calculate lines of code", $current_file_index, $file_count); | |
| foreach (@blame) | |
| { | |
| my $bline = $_; | |
| print_debug("parse line: $bline"); | |
| if($bline =~ /^[0-9a-f]{40}\s/) { | |
| print_debug("hash line found"); | |
| } | |
| elsif($bline =~ /^\t/) { | |
| print_debug("code line found"); | |
| if(! user_exists($last_author.' '.$last_email)) { | |
| create_user($last_author.' '.$last_email); | |
| } | |
| $users{$last_author.' '.$last_email}->{'lines_in_code'} = | |
| $users{$last_author.' '.$last_email}->{'lines_in_code'} + 1; | |
| if(! ($bline =~ /^\s*$/)) { | |
| print_debug("full line"); | |
| $users{$last_author.' '.$last_email}->{'lines_in_code_except_empty'} = | |
| $users{$last_author.' '.$last_email}->{'lines_in_code_except_empty'} + 1; | |
| } | |
| } | |
| elsif($bline =~ /^author\s(.*)$/ ) { | |
| print_debug("author found: $1"); | |
| $last_author = $1; | |
| } | |
| elsif($bline =~ /^author-mail\s(.*)$/) { | |
| print_debug("author-mail found: $1"); | |
| $last_email = $1; | |
| } | |
| else { | |
| print_debug("line ignored: $bline"); | |
| } | |
| } | |
| } | |
| } | |
| sub parse_git_log { | |
| my @loglines = `git log --oneline --stat --no-merges`; | |
| foreach (@loglines) { | |
| my $logline = $_; | |
| if($logline =~ /^\s.*[^|].*$/) | |
| { | |
| print "$logline\n"; | |
| } | |
| } | |
| } | |
| sub print_results { | |
| for (keys %users) | |
| { | |
| my $user = $_; | |
| my $lic = $users{$user}->{'lines_in_code'}; | |
| my $licee = $users{$user}->{'lines_in_code_except_empty'}; | |
| print "$user\n"; | |
| print "\tlines in code: $lic/$licee\n"; | |
| } | |
| } | |
| parse_git_blame(); | |
| parse_git_log(); | |
| print_results(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment