#!/bin/sh
BASEDIR=$(dirname $0)
if [ -n "$1" ]; then
	starttime=$1
else
	starttime=$(date -d 'last monday' +%s)
fi
if [ -n "$2" ]; then
	endtime=$2
else
	endtime=$(date -d 'monday' +%s)
fi
#echo starttime=$starttime endtime=$endtime
bf=add-removals.$endtime
lf=$bf.log
hf=$bf.html
tf=$bf.txt
#echo 'Building data' 1>&2
# Put your up to date Git Path here - maybe add a git pull?
python2 $BASEDIR/find-git-adds-and-removals.py /mnt/btrfs/gentoo $starttime $endtime >$lf
fw=$(cut -d, -f1 $lf |grep / | awk '{print length($1)}' | sort -n  | tail -n1)
fmt="%-${fw}s\t%19s\t%s"

echo 'Building text output' 1>&2
echo 'Removals:' >$tf
cat $lf | grep ,removed, | sed 's|removed,||g' | awk -F,  "{printf \"$fmt\n\",\$1,\$3,\$2}" | sort >>$tf
echo >>$tf
echo 'Additions:' >>$tf
cat $lf | grep ,added, | sed 's|added,||g' | awk -F, "{printf \"$fmt\n\",\$1,\$3,\$2}" | sort >>$tf
