forked from apis/gitstatistics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.awk
145 lines (127 loc) · 2.64 KB
/
stats.awk
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# Copyright © 2010, Alexey Pisanko ([email protected]) All rights reserved.
#
# License: GPL 3/LGPL 3
#
# Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
# either express or implied. See the License for the specific language governing rights and limitations
# under the License.
# -------------------------------------------------------------------------------------------------------
#
# Record format for 'git log --numstat' output
#
# --- begin ---
# commit 2394ae0e9883c8834f2e506786f1132ff694b655
# Author: Scrooge McDuck <[email protected]>
# Date: Sun Dec 19 22:51:32 2010 -0500
#
# fixed redirect issue
#
# 1 1 app/controllers/money_controller.rb
#
# --- end ---
BEGIN {
COMMIT_TEXT = "commit"
AUTHOR_TEXT = "Author:"
DATE_TEXT = "Date:"
AUTHOR_COUNT = 0
}
END {
print_stats()
}
{
parse_header()
process_message()
process_stats()
}
function parse_header() {
parse_commit_field()
parse_author_field()
parse_date_field()
FS = " "
get_line()
if ( $0 != "" ) {
fail()
}
}
function parse_commit_field() {
if (COMMIT_TEXT != $1) {
fail()
}
}
function parse_author_field() {
FS = AUTHOR_TEXT
get_line()
if ("" == $2) {
fail()
}
AUTHOR = $2
sub(/^ */, "", AUTHOR)
}
function parse_date_field() {
FS = DATE_TEXT
get_line()
if ("" == $2) {
fail()
}
}
function process_message() {
get_line()
while($0 != "") {
get_line()
}
}
function process_stats() {
init_author_index()
get_line()
result = 1
count = 0
while($0 != "" && result == 1) {
count++
update_stats($1, $2)
result = getline
}
AUTHOR_FILES[AUTHOR_INDEX] += count
AUTHOR_COMMITS[AUTHOR_INDEX] ++
}
function update_stats(added, deleted) {
if (added != "-") {
AUTHOR_ADDED[AUTHOR_INDEX] += added
}
if (deleted != "-") {
AUTHOR_DELETED[AUTHOR_INDEX] += deleted
}
}
function init_author_index() {
for (i = 0; i < AUTHOR_COUNT; i++) {
if (AUTHORS[i] == AUTHOR) {
AUTHOR_INDEX = i
return
}
}
AUTHORS[AUTHOR_COUNT] = AUTHOR
AUTHOR_ADDED[AUTHOR_COUNT] = 0
AUTHOR_DELETED[AUTHOR_COUNT] = 0
AUTHOR_FILES[AUTHOR_COUNT] = 0
AUTHOR_COMMITS[AUTHOR_COUNT] = 0
AUTHOR_INDEX = AUTHOR_COUNT
AUTHOR_COUNT++
}
function fail() {
print "===>>> Script failed! <<<==="
exit 1
}
function get_line() {
if (getline != 1) {
fail()
}
}
function print_stats() {
for (i = 0; i < AUTHOR_COUNT; i++) {
print "Author:", AUTHORS[i]
print "Insertions:", AUTHOR_ADDED[i]
print "Deletions:", AUTHOR_DELETED[i]
print "Files changed:", AUTHOR_FILES[i]
print "Commits:", AUTHOR_COMMITS[i]
print ""
}
}