Thursday, June 24, 2010

Daily SVN report script

How can i get svn log information for my own commits? How can i see what i committed on a specific day? How do i list all svn repositories i'm working on?


#!/bin/bash
#
# svn_daily_report.sh
#
# A script to extract SVN log info for all repositories you're working on,
# yielding only your own commits, on a particular day.
#
# The script does this:
# * find unique repository roots you're working on
# * get the revision numbers for your own commits in each repo
# * print the full log for each of these revisions
#
# Syntax: svn_daily_report.sh [DATE1] [DATE2]
#
# DATE1 is an optional argument in the format yyyy-mm-dd. If DATE1 is not
# present, today is assumed. DATE2 is an optional end date, the default is
# DATE1.
#
# As this may take a long time, you may want to write the output to a
# file: svn_daily_report.sh 2>&1 | tee -a /tmp/svn_daily_report.txt
#
# TODO:
#
# * Allow passing usernames and directories from the command line

# Set your SVN username. You can set multiple SVN usernames (handy if the
# same person has a different username for different repositories) by
# delimiting them with \|.
username="hink\|khink"

if [ ! -n "$1" ]
then
# No date set; use today
date1=`date +%F`
date2=$date1
else
date1=$1
if [ ! -n "$2" ]
then
# No end date set; using start date
date2=$date1
else
date2=$2
fi
fi
echo "Looking for $username's repository changes from $date1 00:00 to $date2 23:59"

# Find unique repository roots below current working directory
for repo in `find . -name .svn -type d | sed 's/\(.*\).svn$/\1/' | xargs svn info | sed -n 's/^Repository Root: *//p' | sort | uniq`;
do
echo "Repository root: $repo"
# Find all svn revision numbers made in this timespan by this svn user
for revision in `svn log -qr {"$date1 00:00"}:{"$date2 23:59"} $repo | sed -n "s/r\([0-9]*\) | \($username\) |.*/\1/p"`
do
# Print log info
svn log -vr $revision $repo
done
echo
done

No comments: