forked from gwaerondor/committer_stats
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommitter_stats.bash
More file actions
executable file
·99 lines (86 loc) · 2.44 KB
/
committer_stats.bash
File metadata and controls
executable file
·99 lines (86 loc) · 2.44 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
#!/bin/bash
if [ -z "${1}" ]
then
GIT_USER="$(git config --global --list | grep user.name | cut -d= -f2)"
else
GIT_USER="${1}"
fi
if [ -z "${2}" ]
then
AfterDate=""
else
AfterDate="--after=${2}"
fi
main() {
exit_if_not_repository
local branch changes
local user_commits all_commits
local average_delta percentage typical_time
branch="$(get_branch)"
changes="$(lines_changed)"
user_commits="$(get_user_commits)"
all_commits="$(get_all_commits)"
percentage="$(calculate_percentage ${user_commits} ${all_commits})"
average_delta="$(get_average_delta $((changes)) ${user_commits})"
typical_times="$(typical_commit_times)"
echo "Stats for ${GIT_USER} on ${branch}:"
echo " Commits: ${user_commits} (${percentage}% of all commits)"
echo " Lines: ${changes}"
echo " Total delta: $((changes))"
echo " Average delta/commit: ${average_delta}"
echo " Typical commit times (UTC):"
echo "${typical_times}"
echo ""
echo "Stats for all users on ${branch}:"
echo " Commits: ${all_commits}"
}
exit_if_not_repository() {
git status 1> /dev/null 2>&1 || print_error_and_exit
}
print_error_and_exit() {
echo "fatal: Not a git repository" >&2
exit 1
}
get_branch() {
git branch | grep '^\*' | cut -d' ' -f2
}
lines_changed() {
git log ${AfterDate} --author="${GIT_USER}" --pretty=tformat: --numstat \
| awk 'BEGIN {ins=0; rem=0}; {ins+=$1; rem+=$2} END {print "+" ins " -" rem}'
}
get_user_commits() {
git rev-list HEAD --count --author="${GIT_USER}" ${AfterDate}
}
get_all_commits() {
git rev-list HEAD --count ${AfterDate}
}
calculate_percentage() {
local num denom
num="${1}"
denom="${2}"
echo "scale=6; ${num}/${denom}" | bc | awk '{printf "%.4f\n", $0*100}'
}
get_average_delta() {
local changes user_commits
changes="${1}"
user_commits="${2}"
if [ ${changes} -eq 0 ]
then
echo "0"
else
echo "$((changes / user_commits))"
fi
}
typical_commit_times() {
TZ=UTC git log ${AfterDate} --author="${GIT_USER}" \
--pretty=format:"%ad" --date=iso-local \
| awk '{print $2}' \
| cut -d: -f1 \
| sort \
| uniq -c \
| sort -nr \
| head -n3 \
| awk '{print $2 ":00-" sprintf("%02d", $2+1) ":00 (" $1 " commits)"}' \
| sed 's/^/ /g'
}
main