Skip to content

Instantly share code, notes, and snippets.

@userid
Last active July 24, 2019 08:41
Show Gist options
  • Save userid/b783267abc7433a6255885680aa161e7 to your computer and use it in GitHub Desktop.
Save userid/b783267abc7433a6255885680aa161e7 to your computer and use it in GitHub Desktop.
统计git代码修改行数
#!/usr/bin/perl -w
use 5.010;
use POSIX qw(strftime);
my $day_cnt = shift || 7;
my $date = strftime("%Y-%m-%d", localtime(time() - $day_cnt *86400));
say "从$date开始的统计";
my @all_user =split "\n", qx/git log --since='$date' --format='%aN' | sort | uniq /;
my %data=();
for my $user (@all_user){
open my $f, "git log --since='$date' --author='$user' --pretty=tformat: --numstat |";
my $add =0, $remove=0,$total=0;
while(<$f>){
next unless /\d/;
my @s = split;
$add+=$s[0];
$remove+=$s[1];
}
$total = $add+$remove;
$data{$user}={};
$data{$user}{'total'} = $total;
$data{$user}{'add'} = $add;
$data{$user}{'remove'} = $remove;
#printf("%-20s %-10d +%-10d -%-10d\n","$user",$total , $add , $remove);
close($f);
}
foreach my $user (sort { $data{$b}{'total'} <=> $data{$a}{'total'}} keys %data ){
printf("%-20s %-10d +%-10d -%-10d\n","$user", $data{$user}{'total'} , $data{$user}{'add'} , $data{$user}{'remove'});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment