-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheatmaps.sh
More file actions
executable file
·107 lines (97 loc) · 2.41 KB
/
heatmaps.sh
File metadata and controls
executable file
·107 lines (97 loc) · 2.41 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
#!/usr/bin/env bash
# Build a commit frequency histogram
ccyan="$(echo -ne '\033[0;36m')"
cnone="$(echo -ne '\033[0m')"
set -euo pipefail
ARGV=()
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-n)
LIMIT="$2"
shift
shift
;;
-b | --base)
REVIEW_BASE="$2"
shift
shift
;;
-c | --char)
CHAR="$2"
shift
shift
;;
--width)
WIDTH="$2"
shift
shift
;;
-f | --filter)
FILTER="$2"
shift
shift
;;
-h)
cat <<EOF
Heatmap of oft-edited files.
Usage:
git heatmap [options] [<path>...]
Options:
-n <top> Limit to top <n> files. [default: 30]
--width <n> Limit histogram to <n> chars.
-b <branch>, --base <branch> Compare relative to <branch>. If on <branch>,
show heatmap for entire repo. [default: master]
-c <char>, --char <char> Use <char> to draw the bars. [default: █]
-f <cmd>, --filter <cmd> Filter output through <cmd> before creating the
the histogram.
-h Show this message.
EOF
exit
;;
*)
ARGV+=("$1")
shift
;;
esac
done
LIMIT=${LIMIT:-30}
REVIEW_BASE=${REVIEW_BASE:-master}
CHAR=${CHAR:-█}
WIDTH=${WIDTH:-60}
FILTER=${FILTER:-cat -}
files() {
# https://stackoverflow.com/questions/7577052/
git log --name-status --pretty=format: -- "${ARGV[@]+"${ARGV[@]}"}" |
cut -f 2-
}
color_name() {
if [ -t 1 ]; then
sed -e "s/\(..*\/\)*\(.[^|]*\) |/\1$ccyan\2$cnone |/"
else
cat -
fi
}
filter() {
grep '.' |
eval "$FILTER" |
sort |
uniq -c |
sort -nr |
head -n "$LIMIT"
}
histogram() {
bars --bar "$CHAR" --width "$WIDTH"
}
if [[ "$(git branch | grep '\*')" =~ $REVIEW_BASE ]]; then
# If on master, show heatmap for whole repo
files | filter | histogram | color_name
else
MERGE_BASE="$(git merge-base HEAD "$REVIEW_BASE")"
files |
# If on separate branch, show heatmap for files changed since master
grep -xF -f <(git diff --name-only "$MERGE_BASE") |
filter |
histogram |
color_name
fi