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

Comments (9)

Comments RSS - Trackback - Write Comment

  1. Jason says:

    Interesting article. Will post a link to it on StatSVN’s wiki.

    Posted February 27, 2007 @ 8:18 pm
  2. andre´s blog » Blog Archive » subversion reports says:
    Posted July 23, 2007 @ 1:45 pm
  3. cron says:

    Hi, I’m a Chinese, currently using 0.3.1 of statsvn, but failed to do it.
    my platform is winxp chinese version, jdk 1.5
    can you help me ?

    thx in advance
    ==================== ERROR LOG ============
    E:\path\to\svn>svn log -v –xml > logfile.log

    E:\Downloads\statsvn>java -jar statsvn.jar -output-dir d:/xx -include **/*.java;
    **/*.jsp;**/*.js -exclude **/*.gif;**/*.jpg;**/*.css;**/*.htm;**/*.html -threads
    50 logfile.log E:\Downloads\statsvn\code
    2007-10-17 14:38:01 net.sf.statsvn.util.JavaUtilTaskLogger info
    信息: StatSVN - SVN statistics generation

    Parsing SVN log ‘logfile.log’ exclude pattern ‘**/*.gif;**/*.jpg;**/*.css;**/*.h
    tm;**/*.html’
    svn: ?\229?\174?\137?\229?\133?\168?\230?\149?\176?\230?\141?\174?\226?\128?\156
    web\images\default\toolbar\?\226?\128?\157?\229?\144?\142?\233?\157?\162?\230?\1
    52?\175?\233?\157?\158ASCII?\229?\173?\151?\232?\138?\130 231: ?\228?\184?\141?\
    232?\131?\189?\232?\189?\172?\230?\141?\162?\229?\136?\176/?\232?\135?\170 UTF-8

    Contacting server to obtain line count information.
    This information will be cached so that the next time you run StatSVN, results w
    ill be returned more quickly.
    IOException: Unable to obtain diff: java.io.IOException: svn: ?\229?\174?\137?\2
    29?\133?\168?\230?\149?\176?\230?\141?\174?\226?\128?\156— ExpsuppAction.java
    ?\226?\128?\157?\229?\144?\142?\233?\157?\162?\230?\152?\175?\233?\157?\158ASCII
    ?\229?\173?\151?\232?\138?\130 239: ?\228?\184?\141?\232?\131?\189?\232?\189?\17
    2?\230?\141?\162?\229?\136?\176/?\232?\135?\170 UTF-8
    IOException: Unable to obtain diff: java.io.IOException: svn: ?\229?\174?\137?\2
    29?\133?\168?\230?\149?\176?\230?\141?\174?\226?\128?\156— ExpsuppAction.java
    ?\226?\128?\157?\229?\144?\142?\233?\157?\162?\230?\152?\175?\233?\157?\158ASCII
    ?\229?\173?\151?\232?\138?\130 239: ?\228?\184?\141?\232?\131?\189?\232?\189?\17
    2?\230?\141?\162?\229?\136?\176/?\232?\135?\170 UTF-8
    IOException: Unable to obtain diff: java.io.IOException: svn: ?\229?\174?\137?\2
    29?\133?\168?\230?\149?\176?\230?\141?\174?\226?\128?\156— send_finance.jsp
    ?\226?\128?\157?\229?\144?\142?\233?\157?\162?\230?\152?\175?\233?\157?\158ASCII
    ?\229?\173?\151?\232?\138?\130 239: ?\228?\184?\141?\232?\131?\189?\232?\189?\17
    2?\230?\141?\162?\229?\136?\176/?\232?\135?\170 UTF-8
    IOException: Unable to obtain diff: java.io.IOException: svn: ?\229?\174?\137?\2
    29?\133?\168?\230?\149?\176?\230?\141?\174?\226?\128?\156— send_finance.jsp
    ?\226?\128?\157?\229?\144?\142?\233?\157?\162?\230?\152?\175?\233?\157?\158ASCII
    ?\229?\173?\151?\232?\138?\130 239: ?\228?\184?\141?\232?\131?\189?\232?\189?\17
    2?\230?\141?\162?\229?\136?\176/?\232?\135?\170 UTF-8

    E:\Downloads\statsvn>svn –help
    ?\231?\148?\168?\230?\179?\149: svn [options] [args]
    Subversion ?\229?\145?\189?\228?\187?\164?\232?\161?\140?\229?\174?\162?\230?\13
    6?\183?\231?\171?\175?\239?\188?\140?\231?\137?\136?\230?\156?\172 1.4.4?\227?\1
    28?\130
    ?\228?\189?\191?\231?\148?\168?\226?\128?\156svn help ?\226?\128?\15
    7 ?\230?\152?\190?\231?\164?\186?\229?\173?\144?\229?\145?\189?\228?\187?\164?\2
    31?\154?\132?\229?\184?\174?\229?\138?\169?\228?\191?\161?\230?\129?\175?\227?\1

    Posted October 17, 2007 @ 12:43 pm
  4. cron says:

    append my words:

    svn version: svn-win32-1.4.4

    Posted October 17, 2007 @ 12:45 pm
  5. cron says:

    Oh, it seems my svn is work in wrong stat, it works after update svn 1.4.4 to 1.4.5.

    :) thx

    Posted October 17, 2007 @ 1:00 pm
  6. cano says:

    hi, I need help.

    After I key in the command “java -jar statsvn.jar XXX.log .”,I confront error message same with cron.

    my svn client version is 1.4.8, and I tried 1.4.5 too as cron metioned, but still failed. statsvn version is 0.4.0.

    I am now looking forward to your feedback and futhur help. thanks.

    Posted May 6, 2008 @ 1:26 pm
  7. John says:

    Cano,

    You might try asking your question on the StatSVN forum (http://sourceforge.net/tracker/?group_id=164845), where they would have more experience with the internals than I.

    I also noticed a message on the StatSVN home page about i18n issues, if that would apply for you (http://www.statsvn.org/):

    “Warning: if you’re not using an English locale, please set the LANG environment variable to en_US when running the application until we resolve some i18n issues with StatSVN”

    Hope that helps,
    John

    Posted May 6, 2008 @ 7:14 pm
  8. Submerged中文版 | Subversion专家Blog » Blog Archive » 使用statsvn says:

    […] Ant中使用statsvn的一个例子,介绍了如何使用哪个日期指定范围 http://jbrugge.com/blog/2007/02/27/using-date-ranges-with-statsvn/ […]

    Posted December 19, 2008 @ 5:41 pm
  9. Submerged中文版 | Subversion专家Blog » Blog Archive » 使用statsvn says:

    […] Ant中使用statsvn的一个例子,介绍了如何使用哪个日期指定范围 http://jbrugge.com/blog/2007/02/27/using-date-ranges-with-statsvn/ […]

    Posted December 19, 2008 @ 5:41 pm

Write Comment