-
Notifications
You must be signed in to change notification settings - Fork 3
/
authors.php
executable file
·90 lines (78 loc) · 1.91 KB
/
authors.php
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
#!/usr/bin/env php
<?php
# Copyright (C) 2014-2019, Apertium Project Management Committee <[email protected]>
# Licensed under the GNU GPL version 3 or later; see https://www.gnu.org/licenses/
# Usage: svn log -q | awk '{print $3 "\t" $5}' | authors.php
# Usage: git log '--date=format:%Y' '--format=format:%ad%x09%aN <%aE>' | authors.php
function sort_authors($a, $b) {
if ($a['hi'] != $b['hi']) {
return ($a['hi'] > $b['hi']) ? -1 : 1;
}
if ($a['lo'] != $b['lo']) {
return ($a['lo'] < $b['lo']) ? -1 : 1;
}
return strcmp($a['name'], $b['name']);
}
$map = file_get_contents(__DIR__.'/authors.json5');
$map = json_decode($map, true);
$authors = [];
$count = 0;
while ($line = fgets(STDIN)) {
$user = null;
$year = 0;
if (preg_match('@^(\S+)\s(\d+)@u', $line, $m)) {
$m[1] = mb_strtolower($m[1]);
if (empty($map[$m[1]])) {
echo "UNKNOWN: {$m[1]}\n";
continue;
}
$user = $map[$m[1]];
$year = intval($m[2]);
}
else if (preg_match('~^(\d+)\t(.+?)\s+<(.+?)>$~u', $line, $m)) {
$user = "{$m[2]} <{$m[3]}>";
$m[3] = mb_strtolower($m[3]);
if (!empty($map[$m[3]])) {
$user = $map[$m[3]];
}
$year = intval($m[1]);
}
else if (preg_match('~^(\d+)\t(.+)$~u', $line, $m)) {
$user = $m[2];
$m[2] = mb_strtolower($m[2]);
if (!empty($map[$m[2]])) {
$user = $map[$m[2]];
}
$year = intval($m[1]);
}
else {
continue;
}
++$count;
if (empty($authors[$user])) {
$authors[$user] = [
'name' => $user,
'lo' => $year,
'hi' => $year,
'cnt' => 1,
];
continue;
}
if ($year < $authors[$user]['lo']) {
$authors[$user]['lo'] = $year;
}
if ($year > $authors[$user]['hi']) {
$authors[$user]['hi'] = $year;
}
++$authors[$user]['cnt'];
}
uasort($authors, 'sort_authors');
foreach ($authors as $user => $hilo) {
echo $hilo['lo'];
if ($hilo['lo'] != $hilo['hi']) {
echo '-', $hilo['hi'];
}
echo ', ', $user;
//echo ' (', round($hilo['cnt']*100.0/$count), '%)';
echo "\n";
}