Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Extract number of active authors in a git repository at the time of each commit
#!/usr/bin/perl
my @a = `git log --use-mailmap --reverse --pretty=fuller --no-color --date=short --decorate=full | egrep "^(Author|CommitDate):"`;
use Time::Piece;
sub delta {
my ($from, $to) = @_;
my $f = Time::Piece->strptime($from, "%Y-%m-%d");
my $t = Time::Piece->strptime($to, "%Y-%m-%d");
my $diff = $t - $f;
return int($diff->days);
}
my $auth;
for(@a) {
chomp;
my $line = $_;
if(/^Author: *([^\<]*) \</) {
($auth)=($1);
$person{$auth}++;
}
elsif(/^CommitDate: (.*)/) {
my $d = $1;
$date{$auth}=$d;
my @active12;
my @active9;
my @active6;
my @active3;
my @activew;
foreach my $p (keys %person) {
my $de = delta($date{$p}, $d);
push @active12, $p if($de < 120);
push @active9, $p if($de < 90);
push @active6, $p if($de < 60);
push @active3, $p if($de < 30);
push @activew, $p if($de < 7);
}
if(delta("2010-01-01", $d) < 0) {
# counted, but don't output data from before 2010
next;
}
#printf "$d (%d): %s\n", $#active+1, join(", ", sort @active);
printf "$d;%d;%d;%d;%d;%d\n",
$#active12+1,
$#active9+1,
$#active6+1,
$#active3+1,
$#activew+1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment