-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathget-versions-csv.pl
executable file
·73 lines (58 loc) · 1.67 KB
/
get-versions-csv.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env perl
use strict;
use warnings;
use v5.12;
use Git;
use File::Slurp::Tiny qw(read_lines);
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( followers contributions stars );
my %column_row = ( followers => 2,
contributions => 3,
stars => 4 );
say "users;",join(";",@columns),";commitdate";
#For files not in repo
if ($baseline) {
my @file_contents = read_lines( $baseline );
my @row = extract_data( @file_contents);
say scalar @file_contents,";",join(";",@row);
}
for my $commit ( reverse @revs ) {
my $commit_date = `git show -s --format=\%ci $commit`;
my $file_contents = $repo->command('show',"$commit:$file" );
my @file_lines = split("\n",$file_contents);
my @row = extract_data(@file_lines );
print scalar @file_lines,";",join(";",@row),";$commit_date";
}
#Extract data from JSON
sub extract_data {
my @lines = @_;
my $totals = {};
if ( $lines[0] !~ /place/ ) { # Hack for initial format
%column_row = ( followers => 2,
contributions => 3,
stars => 4 );
} else {
%column_row = ( followers => 3,
contributions => 4,
stars => 5 );
}
for my $c (@columns) {
$totals->{$c} = 0;
}
for my $u (@lines[1..$#lines] ) {
my @row = split(";",$u);
for my $column ( @columns ) {
$totals->{$column} += $row[$column_row{$column}] || 0;
}
}
my @row;
for my $column ( @columns ) {
push @row, $totals->{$column};
}
return @row;
}