#!/bin/sh

REVS=" \
inky-1.0 \
clyde-2.0 \
blinky-3.0 \
pinky-3.1 \
purple-3.2 \
green-3.3 \
laverne-4.0 \
bernard-5.0 \
edison-6.0 \
denzil-7.0 \
danny-8.0 \
dylan-9.0.0 \
dora-10.0.0 \
daisy-11.0.0 \
dizzy-12.0.0 \
fido-13.0.0 \
jethro-14.0.0 \
krogoth-15.0.0 \
morty-16.0.0 \
pyro-17.0.0 \
rocko-18.0.0 \
sumo-19.0.0 \
thud-20.0.0 \
warrior-21.0.0 \
zeus-22.0.0 \
master \
"

gather_data() {
	local name=$1 rev=$2

	git checkout -f $rev >/dev/null 2>&1
	printf "%s\t%s\t%d\t%d\n" \
		$name \
		$(git show -s --format=%cd --date=format:%Y-%m-%d) \
		$(grep --exclude-dir=.git --exclude='*.patch' -ri '["'\''] % ' | wc -l) \
		$(grep --exclude-dir=.git --exclude='*.patch' -ri '\.format(' | wc -l)
}

[ -f formattingwar.dat ] || {
	for rev in $REVS; do
		release=${rev%-*}
		gather_data $release $rev
	done
} > formattingwar.dat

git checkout master >/dev/null 2>&1

gnuplot <<-EOF
	# Uncomment the following two lines to write the graph to a file.
#	set terminal pngcairo size 800,600
#	set output "formattingwar.png"

	set title "Use of % vs .format()"
	set xtics rotate by 45 right
	set key noenhanced
	set style data linespoints
	set timefmt "%Y-%m-%d"
	set xdata time
	set mouse mouseformat 3
	plot 'formattingwar.dat' using 2:3:xtic(1) title '%', \
	     ''                  using 2:4         title '.format()'

	pause mouse close
EOF

#rm formattingwar.dat
