Last active
August 17, 2018 13:01
-
-
Save viklund/1d711b7407e0daf5c3d780fe01d8e4fe to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
my %stats = ( | |
'+' => { qw/comment 0 whitespace 0 code 0/ }, | |
'-' => { qw/comment 0 whitespace 0 code 0/ }, | |
); | |
my $calc_commit = ''; | |
my $calc_diff = ''; | |
my $in_diff = ''; | |
my $n_commits = 0; | |
while (<>) { | |
if (/^commit/) { | |
$calc_commit = ''; | |
$in_diff = ''; | |
next; | |
} | |
if (/^Author:\s*([^<]+) <([^>]+)>/) { | |
my ($author, $email) = ($1, $2); | |
if ($email =~ /johan.viklund@/) { | |
$calc_commit = 1; | |
$n_commits++; | |
} | |
else { | |
$calc_commit = ''; | |
} | |
next; | |
} | |
next unless $calc_commit; | |
if (m{^diff .*? a/.*?\.(?:py|sh|pl)}) { | |
$calc_diff = 1; | |
$in_diff = ''; | |
} | |
elsif (/^diff/) { | |
$calc_diff = ''; | |
$in_diff = ''; | |
} | |
next unless $calc_diff; | |
if ( /^@@/ ) { | |
$in_diff = 1; | |
} | |
if ( $in_diff ) { | |
my $type; | |
($type,$_) = /^(.)(.*)$/; | |
next unless $type && ($type eq '+' || $type eq '-'); | |
if ( /^\s*#/ ) { | |
$stats{$type}{comment}++; | |
} | |
elsif ( /^\s*$/ ) { | |
$stats{$type}{whitespace}++; | |
} | |
else { | |
$stats{$type}{code}++; | |
} | |
} | |
} | |
printf "A total of %d commits were analysed\n", $n_commits; | |
for my $type (qw/code comment whitespace/) { | |
printf "%-10s: %5.3f (%d/%d)\n", | |
ucfirst $type, | |
$stats{'+'}{$type}/$stats{'-'}{$type}, | |
$stats{'+'}{$type}, $stats{'-'}{$type}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment