Skip to content

Instantly share code, notes, and snippets.

@johannilsson
Created October 24, 2009 18:49
Show Gist options
  • Select an option

  • Save johannilsson/217684 to your computer and use it in GitHub Desktop.

Select an option

Save johannilsson/217684 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# whodunnit
# Parses the result of svn blame and displays a report of how many rows and
# percent each username has contributed with.
#
# created by johan.nilsson a bwin dot org and hans.nilsson a bwin dot org
#
if [ "$1" = "-h" ]
then
echo -e "whodunnit - Parses the result of svn blame and displays a report
usage: whodunnit TARGET[@REV]... display statistics from svn target
or: whodunnit read text from stdin
Arguments:
-h Print Help (this message) and exit"
exit 1
else
if [ "$1" = "" ]
then
blame_list=`cat /dev/stdin | sed 's/^ *[0-9]*[ \t]* //g' | cut -d" " -f1 | sort`
else
blame_list=`svn blame $* | sed 's/^ *[0-9]*[ \t]* //g' | cut -d" " -f1 | sort`
fi
fi
total_rows=`echo $blame_list | sed s/" "/"\n"/g | wc -l`
commiter_list=`echo $blame_list | sed s/" "/"\n"/g | uniq -c | sort -nr | sed s/" "//g`
stats=""
for i in `echo $commiter_list`
do
rows=`echo $i | sed 's/[a-z]//g'`;
commiter=`echo $i | sed 's/[0-9]//g'`;
percent=`echo "scale=10; ($rows / $total_rows) * 100" | bc`
commit_stat="$commiter $percent $rows"
if [ "$stats" = "" ]
then
stats=$commit_stat
else
stats="$stats\n$commit_stat"
fi
done
echo "------------------------------------------------------------------------"
echo "- Fields: username, percent, rows"
echo "------------------------------------------------------------------------"
echo -e $stats | awk '{printf "%-13s %5.2f %5d\n", $1, $2, $3 }'
echo "------------------------------------------------------------------------"
echo "Total rows: $total_rows"
echo "------------------------------------------------------------------------"
echo "End-of-Report"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment