-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-participation.sh
executable file
·89 lines (80 loc) · 1.73 KB
/
git-participation.sh
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
#/bin/bash
#
# Parse arguments
#
crop=1e9
term=
output=
while [ "$1" != "--" ] && [ "$1" != "" ] ; do
if [ "$1" = "-c" ] ; then
crop=$2
shift 2
elif [ "$1" = "-t" ] ; then
term=$2
shift 2
elif [ "$1" = "-o" ] ; then
output=$2
shift 2
else
echo "Usage: `basename $0` [options] [-- <git-log options>]" 1>&2
echo "Options:" 1>&2
echo " -c int crop changes count to int (default $crop)" 1>&2
echo " -h print this help" 1>&2
echo " -t str Gnuplot term (default '$term')" 1>&2
echo " -o filename Gnuplot output (default '$output')" 1>&2
echo 1>&2
exit 1
fi
done;
if [ "$1" = "--" ] ; then
shift
fi
#
# Load a parse history
#
git status 2>&1 >/dev/null || exit 1
tmp=`mktemp`
(
ins=0
del=0
while read type A B ; do
case $type in
time)
date=$A
if [ -n "$prevDate" ] && [ $date != $prevDate ] ; then
echo $prevDate $ins $del
ins=0
del=0
fi
prevDate=$date
;;
change)
ins=$(($ins + $A))
del=$(($del + $B))
;;
esac
done < <(\
git log --shortstat --pretty="format:time %ai" "$@" | \
sed -r 's/ [0-9]+ files changed,/change/;s/ insertions\(\+\),//;s/ deletions\(-\)//' \
)
echo $date $ins $del
) >$tmp
#
# Plot graph
#
[ $output ] && output="'$output'"
[ $term ] && term="set term $term"
gnuplot -p -e "set key top left outside horizontal;
set xtics rotate by 90 offset 0,-5 out nomirror;
set ytics out nomirror;
set format x '%Y-%m-%d';
set xdata time;
set timefmt '%Y-%m-%d';
set boxwidth 86400 absolute;
min(a,b)=(a<b)?a:b;
$term;
set output $output;
plot '$tmp' using 1:(min($crop,\$2)) w boxes fs solid 0.8 lc rgb 'green' title 'insertions',
'$tmp' using 1:(min($crop,\$3)) w boxes fs solid 0.8 lc rgb 'red' title 'deletions';
set output" 2>/dev/null
rm $tmp