Using date ranges with StatSVN
Published February 27, 2007 by John
I started checking out StatSVN a few months ago, and have since been able to set it up for a couple of projects. I’ve got to say that the developers have been very helpful in resolving a couple of problems quickly, and have even gone and added some really interesting features, like a code churn report and a “heat map”. These are more intriguing than useful to me at the moment, but I like seeing them exploring what the data can show.
One of the things that they originally said in their user manual, though, was that the svn log command could not specify date ranges the way that cvs log can, and that therefore there isn’t a way to give a start and end date to the analysis. It turns out, though, that you can, and with Ant you can pretty easily set it up to give you a rolling window of activity of almost any time range you want.
The key is Ant’s format element of the tstamp task. Besides specifying the actual format of the date, you can tell it an offset (past or future) and a unit (hour, day, month, year). To get a date range for the past week, for example, you could have a simple Ant target like this.
<target name="calc-report-period">
<tstamp>
<format property="statsvn.start" pattern="yyyy-MM-dd"/>
</tstamp>
<tstamp>
<format property="statsvn.stop" pattern="yyyy-MM-dd"
offset="-7" unit="day" />
</tstamp>
</target>
Put the offset and unit in properties, and you can be even more flexible.
Now that you have two dates, you can run the svn log command.
<target name="generate-svn-log" depends="calc-report-period">
<exec dir="${project.root}" executable="svn"
output="${gen.report.dir}/logfile.log">
<arg line="log"/>
<arg line="-v"/>
<arg line="--xml"/>
<arg line="-r {${statsvn.start}}:{${statsvn.stop}}"/>
</exec>
</target>
You’ve now got a log file for a given range of dates, and you can hand this off to the StatSVN task.
<target name="statsvn" depends="generate-svn-log">
<statsvn path="${src.dir}"
log="${gen.report.dir}/logfile.log"
outputDir="${gen.report.dir}"
title="${src.project.name}"
include="${svn.include.pattern}"
/>
</target>
If you’re using CVS, you can use the same idea, since StatCVS works by the same chain of actions, where you first create a log file and then run the StatCVS code against that. The CVS log command has a more complex set of options, but for the basic type of range like that above, you can use almost the same syntax.
<target name="generate-cvs-log" depends="calc-report-period">
<exec dir="${project.root}" executable="cvs"
output="${gen.report.dir}/logfile.log">
<arg line="log"/>
<arg line="-d${statcvs.start}<${statcvs.stop}"/>
</exec>
</target>
Filed under Tools
Posts