-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathgit_graph_commit_history_gnuplot.sh
More file actions
executable file
·156 lines (130 loc) · 3.93 KB
/
git_graph_commit_history_gnuplot.sh
File metadata and controls
executable file
·156 lines (130 loc) · 3.93 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
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
153
154
155
156
#!/usr/bin/env bash
# vim:ts=4:sts=4:sw=4:et
#
# Author: Hari Sekhon
# Date: 2024-10-03 04:55:02 +0300 (Thu, 03 Oct 2024)
#
# https///github.com/HariSekhon/DevOps-Bash-tools
#
# License: see accompanying Hari Sekhon LICENSE file
#
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
#
# https://www.linkedin.com/in/HariSekhon
#
set -euo pipefail
[ -n "${DEBUG:-}" ] && set -x
srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck disable=SC1090,SC1091
. "$srcdir/lib/git.sh"
code_month="git_commits_per_month.gnuplot"
code_year="git_commits_per_year.gnuplot"
data_month="data/git_commits_per_month.dat"
data_year="data/git_commits_per_year.dat"
image_year="images/git_commits_per_year.png"
image_month="images/git_commits_per_month.png"
# shellcheck disable=SC2034,SC2154
usage_description="
Generates GNUplot graphs of Git commits per year and per month for the entire history of the local Git repo checkout
Generates the following files:
$code_month - Code
$code_year - Code
$data_month - Data
$data_year - Data
$image_month - Image
$image_year - Image
A MermaidJS version of this script is adjacent at:
git_graph_commit_history_mermaidjs.sh
Requires Git and GNUplot to be installed to generate the graphs
"
# used by usage() in lib/utils.sh
# shellcheck disable=SC2034
usage_args="[<git_log_paths_to_check_only>]"
help_usage "$@"
if ! is_in_git_repo; then
die "Error: Not inside a git repository!"
fi
for x in $code_month \
$code_year \
$data_month \
$data_year \
$image_month \
$image_year; do
mkdir -p -v "$(dirname "$x")"
done
# output git commits as simple YYYY-MM and then just sort and count them by month
timestamp "Calculating commit counts per month from the Git log"
git log --date=format:'%Y-%m' --pretty=format:'%ad' "$@" |
sort |
uniq -c |
awk '{print $2, $1}' > "$data_month"
timestamp "Wrote data: $data_month"
echo
timestamp "Calculating commit counts per year from the Git log"
git log --date=format:'%Y' --pretty=format:'%ad' "$@" |
sort |
uniq -c |
awk '{print $2, $1}' > "$data_year"
timestamp "Wrote data: $data_year"
echo
gnuplot_common_settings="
#
# Generated by ${0##*/}
#
# from https://github.com/HariSekhon/DevOps-Bash-tools
#
set terminal pngcairo size 1280,720 enhanced font 'Arial,14'
set ylabel 'Number of Commits'
set grid
set xtics rotate by -45
set boxwidth 0.5 relative
set style fill solid
set datafile separator ' '
"
#set xtics auto # cannot find a way to make this show every year
timestamp "Generating GNUplot code for Commits per Month"
sed '/^[[:space:]]*$/d' > "$code_month" <<EOF
$gnuplot_common_settings
set title "Git Commits per Month"
set xlabel "Month-Year"
set format x "%b %Y"
set xdata time
set timefmt "%Y-%m"
set output "$image_month"
plot "$data_month" using 1:2 with boxes title 'Commits'
EOF
timestamp "Generated GNUplot code: $code_month"
echo
timestamp "Generating GNUplot code for Commits per Year"
sed '/^[[:space:]]*$/d' > "$code_year" <<EOF
$gnuplot_common_settings
set title "Git Commits per Year"
set xlabel "Year"
# results in X axis labels every 2 years
#set xdata time
#set timefmt "%Y"
#set format x "%Y"
# trick to get X axis labels for every year
stats "$data_year" using 1 nooutput
set xrange [STATS_min:STATS_max]
set xtics 1
set output "$image_year"
plot "$data_year" using 1:2 with boxes title 'Commits'
EOF
timestamp "Generated GNUplot code: $code_year"
echo
timestamp "Generating bar chart for Commits per Month"
gnuplot "$code_month"
timestamp "Generated bar chart image: $image_month"
echo
timestamp "Generating bar chart for Commits per Year"
gnuplot "$code_year"
timestamp "Generated bar chart image: $image_year"
echo
if is_CI; then
exit 0
fi
timestamp "Opening: $image_month"
"$srcdir/../media/imageopen.sh" "$image_month"
timestamp "Opening: $image_year"
"$srcdir/../media/imageopen.sh" "$image_year"