-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvittugraph.sh
executable file
·67 lines (57 loc) · 1.84 KB
/
vittugraph.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
#!/bin/bash
words=$@
if [ -z "$words" ]; then
words='XXX FIXME KLUDGE WTF TODO'
fi
pattern="$(echo "$words" | perl -pe 's/ +/ /g' | tr ' ' '|')"
tempdir="$(mktemp -d)"
trap "rm -rf $tempdir" EXIT
# Get git commit -> tag mapping.
git show-ref --tags | sed -e 's,refs/tags/,,' | sort > "$tempdir/tags"
# Find interesting commits.
declare -A interesting
for commit in $(git log --reverse --pickaxe-regex -S"$pattern" --pretty="format:%H"); do
interesting[$commit]=1
done
declare -A counts
for word in $words; do
counts[$word]=0
done
# Loop over _all_ commits.
i=0
declare -A commitIndices
git log --oneline --no-abbrev-commit --reverse | \
while read -r commit rest; do
: $((i++))
echo $commit $i >> "$tempdir/commit-indices"
if [ "${interesting[$commit]}" = 1 ]; then
git show $commit > "$tempdir/diff"
for word in $(egrep '^\+' "$tempdir/diff" | egrep -v '^\+\+\+' | egrep -o "$pattern"); do
: $((counts[$word]++))
done
for word in $(egrep '^\-' "$tempdir/diff" | egrep -v '^\-\-\-' | egrep -o "$pattern"); do
: $((counts[$word]--))
done
fi
for word in $words; do
echo $word $i ${counts[$word]} >> "$tempdir/$word.dat"
done
done
(
echo -n 'set xtics nomirror rotate by -45 font ",12" ("" 0'
join <(sort "$tempdir/commit-indices") "$tempdir/tags" | while read -r commit index tag; do
echo -n ", \"$tag\" $index"
done
echo ")"
) >> "$tempdir/plot.gp"
cmd=""
for word in $words; do
cmd="$cmd \"$tempdir/$word.dat\" using 3 with lines title \"$word\", "
done
cat >> "$tempdir/plot.gp" <<EOF
set term pngcairo enhanced font "arial,10" size 1200,700
set output "vittugraph.png"
plot $(echo "$cmd" | sed -e 's/, $//')
EOF
gnuplot -persist "$tempdir/plot.gp"
xdg-open vittugraph.png