﻿#!/usr/bin/perl

# This perl script parses svn log (xml) and produces a day-to-day report. 
# Note: It doesn't show log messages per user.
#
# Usage:
# Get logs after Jan 10
# svn log -r {2010-01-10}:HEAD --xml http://your-svn-location.com/repo > data.xml
# perl svn-log-parser.pl data.xml
# License: LGPL
# Author: Svetoslav Marinov 
# Sites: slavi.biz , devcha.com
# Twitter: lordspace
# (C) July  2010
# P.S.: Feel free to sent me improvements, bug fixes, ... and/or donations ;)

use XML::Simple;
#use Data::Dumper;

$xml = new XML::Simple;

$data = $xml->XMLin(shift(@ARGV) || "data.xml");

my $arr_ref = ($data->{logentry});
my $date = '';
my $new_date = '';

for (my $i = 0; $i < scalar @$arr_ref; $i++) {
    my $ln = $arr_ref->[$i]->{msg};
    $ln =~ s/\s*$//sig;
    $new_date = $arr_ref->[$i]->{date};
    $new_date =~ s/(\d{4}\-\d{2}\-\d{2}).*/$1/sig;    
    
    if ($date ne $new_date) {
        print "\n" . $new_date . "\n------------------------------------------------------------------------\n";
        $date = $new_date;
    }
    
    print ($ln . "\n")
        if ref($arr_ref->[$i]->{msg}) ne 'HASH'; # when the log message is empty the XML parser makes it a hash {}
}
#print Dumper($data->{logentry});
exit(0);

__END__

# example

$VAR1 = [
          {
            'msg' => 'fixed preview
',
            'revision' => '4417',
            'date' => '2009-12-31T21:06:01.286453Z',
            'author' => 'someuser',
            'paths' => {
                       'path' => [
                                 {
                                   'kind' => '',
                                   'content' => '/wsdev/branches/rel-2009-12-05-multi-lang/.........',
                                   'action' => 'M'
                                 },
                                 {
                                   'kind' => '',
                                   'content' => '/wsdev/branches/rel-2009-12-05-multi-lang/.......',
                                   'action' => 'M'
                                 },
                                 {
                                   'kind' => '',
                                   'content' => '/wsdev/branches/rel-2009-12-05-multi-lang/.........',
                                   'action' => 'M'
                                 }
                               ]
                     }
          },
