-
-
Notifications
You must be signed in to change notification settings - Fork 111
/
git-committer-info
executable file
·110 lines (98 loc) · 2.8 KB
/
git-committer-info
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
#!/bin/sh
set -eu
usage () {
echo "usage: git committer-info [-aAh] <pattern> [<pattern> ...]" >&2
echo >&2
echo "Show contribution stats for any committer matching the given pattern." >&2
echo >&2
echo "Options:" >&2
echo "-A Consider all branches (instead of only the current branch)" >&2
echo "-a Print for all committers" >&2
echo "-h Show this help" >&2
}
all_branches=0
all_committers=0
while getopts aAh flag; do
case "$flag" in
a) all_committers=1;;
A) all_branches=1;;
h) usage; exit 2;;
esac
done
shift $(($OPTIND - 1))
if [ $all_committers -eq 1 ]; then
committers=$(git shortlog -s | cut -f2-)
else
if [ $# -eq 0 ]; then
usage
exit 2
fi
committers=$(for item in "$@"; do echo "$item"; done)
fi
count_by_dow () {
awk '
BEGIN {
map["Mon"] = 0
map["Tue"] = 0
map["Wed"] = 0
map["Thu"] = 0
map["Fri"] = 0
map["Sat"] = 0
map["Sun"] = 0
}
{
map[$1] += 1
}
function round(x, ival, aval, fraction)
{
ival = int(x) # integer part, int() truncates
# see if fractional part
if (ival == x) # no fraction
return ival # ensure no decimals
if (x < 0) {
aval = -x # absolute value
ival = int(aval)
fraction = aval - ival
if (fraction >= .5)
return int(x) - 1 # -2.5 --> -3
else
return int(x) # -2.3 --> -2
} else {
fraction = x - ival
if (fraction >= .5)
return ival + 1
else
return ival
}
}
END {
total = map["Mon"] + map["Tue"] + map["Wed"] + map["Thu"] + map["Fri"] + map["Sat"] + map["Sun"]
printf("%s %6s %4s%%\n", "Mon", map["Mon"], round(map["Mon"] / total * 100))
printf("%s %6s %4s%%\n", "Tue", map["Tue"], round(map["Tue"] / total * 100))
printf("%s %6s %4s%%\n", "Wed", map["Wed"], round(map["Wed"] / total * 100))
printf("%s %6s %4s%%\n", "Thu", map["Thu"], round(map["Thu"] / total * 100))
printf("%s %6s %4s%%\n", "Fri", map["Fri"], round(map["Fri"] / total * 100))
printf("%s %6s %4s%%\n", "Sat", map["Sat"], round(map["Sat"] / total * 100))
printf("%s %6s %4s%%\n", "Sun", map["Sun"], round(map["Sun"] / total * 100))
printf(" -----\n");
printf(" %6s\n", total);
}
'
}
indent () {
sed -Ee 's/^/ /'
}
opts=""
if [ $all_branches -eq 1 ]; then
opts="--all"
fi
first=1
echo "$committers" | while read committer; do
if [ $first -ne 1 ]; then
echo ""
else
first=0
fi
echo "$committer:"
git log $opts --author="$committer" --format="%ad" | count_by_dow | indent
done