-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathget-versions.pl
executable file
·59 lines (47 loc) · 1.23 KB
/
get-versions.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env perl
use strict;
use warnings;
use v5.12;
use JSON;
use Git;
use File::Slurp::Tiny qw(read_file);
my $file = shift || die "Usage: $0 <fichero> [git directory] [Baseline file (not in repo)]\n";
my $dir = shift || ".";
my $baseline = shift;
my $repo = Git->repository (Directory => $dir);
my @revs = $repo->command('rev-list', '--all', '--', $file);
my @data;
my @columns = qw( contributions stars followers );
say "users;",join(";",@columns);
#For files not in repo
if ($baseline) {
my $file_contents = read_file( $baseline );
my @row = extract_data( $file_contents);
say join(";",@row);
}
for my $commit ( reverse @revs ) {
my $file_contents = $repo->command('show',"$commit:$file" );
my @row = extract_data( $file_contents);
say join(";",@row);
}
#Extract data from JSON
sub extract_data {
my $file_contents = shift;
my $user_data = decode_json( $file_contents);
my $totals = {};
for my $c (@columns) {
$totals->{$c} = 0;
}
my $users = 0;
for my $u (@$user_data ) {
$users++;
for my $column ( @columns ) {
( $totals->{$column} += $u->{$column} ) if $u->{$column};
}
}
my @row = ( $users );
for my $column ( @columns ) {
push @row, $totals->{$column};
}
return @row;
}