-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathcommit-sizes.pl
More file actions
119 lines (103 loc) · 2.57 KB
/
commit-sizes.pl
File metadata and controls
119 lines (103 loc) · 2.57 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/perl
# - single file commit
# - single line changed (one add, one remove)
# - > 5 files changed
# - > 50 lines delta
# - > 20 and > 50 lines changed
open(G, "git log --reverse --pretty=fuller --no-color --date=short --decorate=full --stat|");
use Time::Piece;
my %dateday;
sub days {
my ($date) = @_;
if($dateday{$date}) {
return $dateday{$date};
}
my $d = Time::Piece->strptime($date, "%Y-%m-%d");
$dateday{$date} = $d;
return $d;
}
sub delta {
my ($from, $to) = @_;
my $f = days($from);
my $t = days($to);
my $diff = $t - $f;
return int($diff->days);
}
sub percentone {
my (@nums) = @_;
if(scalar(@nums)) {
my $single = grep {$_ == 1 } @nums;
return $single * 100 / scalar(@nums);
}
else {
return 0;
}
}
sub equal_or_more {
my ($limit, @nums) = @_;
if(scalar(@nums)) {
my $single = grep { $_ >= $limit } @nums;
return $single * 100 / scalar(@nums);
}
else {
return 0;
}
}
my $span = 365;
my $date;
my $pdate;
while(<G>) {
chomp;
my $line = $_;
if($line =~ /^CommitDate: (.*)/) {
$date = $1;
if($pdate ne $date) {
printf "$pdate;%.1f;%.1f;%.1f;%.1f;%.1f;%.1f\n",
percentone(@filenum), # single file edit
percentone(@singledit), # single line edit
equal_or_more(5, @filenum),
equal_or_more(50, @delta),
equal_or_more(20, @linesmod),
equal_or_more(50, @linesmod) if($pdate);
$pdate = $date;
}
}
if($line =~ /^ (\d+) file/) {
my $add = 0;
my $del = 0;
my $max;
if($line =~ /, (\d+) insertion/) {
$add = $1;
}
if($line =~ /, (\d+) deletion/) {
$del = $1;
}
while($commitdate[0] && delta($commitdate[0], $date) > $span) {
# shift off all the bad dates
shift @commitdate;
shift @filenum;
shift @singledit;
shift @delta;
shift @linesmod;
}
push @filenum, $1;
push @commitdate, $date;
$max = $add;
if($del > $max) {
$max = $del
}
$add -= $del;
if(!$add && ($del == 1)) {
push @singledit, 1;
}
else {
# not 1
push @singledit, 2;
}
push @delta, $add;
push @linesmod, $max;
}
}
close(G);
# The script never emits a line for the last commit date, but having a single
# day off should be fine.