-
Notifications
You must be signed in to change notification settings - Fork 44
/
git-summary
executable file
·152 lines (126 loc) · 4.17 KB
/
git-summary
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
145
146
147
148
149
150
151
152
#!/usr/bin/env sh
# Show a summary of the commits, authors, and files in a Git repo
#
# Requires ~/bin/transpose
#
# Omit file stats with `-f` for a substantially faster processing time for
# large repositories. Can also summarize subsets of just files or paths by
# passing those as additional `git log` arguments.
#
# Usage:
#
# git summary
# git summary -f
# git summary -- ./path/to/file
show_files=1
while getopts hf opt; do
case $opt in
h) awk 'NR == 1 { next } /^$/ { exit } { print substr($0, 3) }' "$0"
exit ;;
f) unset show_files;;
esac
done
shift $(( OPTIND - 1 ))
test -t 1 && show_progress=1
# %x09 is a tab character
git log --no-renames ${show_files:+--numstat} \
--format='XXX%x09%h%x09%an%x09%ae%x09%cn%x09%ce%x09%cD%x09%cr' "$@" \
| awk -v show_progress="$show_progress" '
function alen(a, i, c) { for (i in a) c += 1; return c; }
function isnum(x){ return (x == x + 0) }
function max(n, m) { return n >= m ? n : m; }
BEGIN { FS="\t"; OFS="\t" }
/^$/ { next }
/^XXX/ {
sha=$2
author=$3 " <" $4 ">"
committer=$5 " <" $6 ">"
reldate=$8
split($7, cal_segs, " ")
weekday=cal_segs[1]
weekday=substr(weekday, 1, length(weekday) - 1)
day=cal_segs[2]
month=cal_segs[3]
year=cal_segs[4]
hour=cal_segs[5]
hour=substr(hour, 1, index(hour, ":") - 1)
tz=cal_segs[6]
auth_date=month ", " day " " year
commit_count += 1
author_list[author] += 1
committer_list[committer] += 1
active_days[auth_date] = 1
top_hours[hour] += 1
top_weekdays[weekday] += 1
if (show_progress) {
printf("\033[2K\033[1GCommits processed: %s", commit_count)
}
}
NR == 1 { last_date=auth_date; last_reldate=reldate; last_sha=sha }
!/^XXX/ {
added=isnum($1) ? $1 : 0
removed=isnum($2) ? $2 : 0
filename=$3
file_list[filename] += 1
lines_changed_count += added - removed
}
END {
# No Git output? (Probably an error.)
if (NR == 0) { exit 1 }
if (show_progress) { printf("\033[2K\033[1G") }
commit_str = "%s:\t%s - %s (%s)\n"
printf(commit_str commit_str "\n",
"First Commit", sha, auth_date, reldate,
"Last Commit", last_sha, last_date, last_reldate)
summary_cmd = "transpose"
print "Commits", commit_count | summary_cmd
print "Files", alen(file_list) | summary_cmd
print "Lines", lines_changed_count | summary_cmd
print "Authors", alen(author_list) | summary_cmd
print "Committers", alen(committer_list) | summary_cmd
print "Active Days", alen(active_days) | summary_cmd
close(summary_cmd)
printf("\nTop days:\n\n")
weekday_cmd = "sort -n -r | cut -f2,3 | transpose"
for (h in top_weekdays) {
wd = top_weekdays[h]
printf("%s\t%s\t%.1f%%\n", wd, h, (wd / commit_count) * 100 ) \
| weekday_cmd
}
close(weekday_cmd)
printf("\nTop hours:\n\n")
hour_cmd = "sort -n -r | cut -f2,3 | head -12 | transpose"
for (i in top_hours) {
hr = top_hours[i]
printf("%s\t%s\t%.0f%%\n", hr, i, (hr / commit_count) * 100 ) \
| hour_cmd
}
close(hour_cmd)
printf("\nTop authors:\n\n")
cmd = "sort -n -r | head -5"
for (j in author_list) {
printf("%s\t%*.1f%%\t%s\n",
author_list[j],
5, (author_list[j] / commit_count) * 100,
j) | cmd
}
close(cmd)
printf("\nTop committers:\n\n")
cmd = "sort -n -r | head -5"
for (l in committer_list) {
printf("%s\t%*.1f%%\t%s\n",
committer_list[l],
5, (committer_list[l] / commit_count) * 100,
l) | cmd
}
close(cmd)
if (alen(file_list)) {
cmd = "sort -n -r | head -5"
printf("\nTop files:\n\n")
for (k in file_list) {
print file_list[k], k | cmd
}
close(cmd)
}
}
'