#!/usr/bin/perl # Copyright (C) 2003 Derek Kite # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Library General Public # License as published by the Free Software Foundation; either # version 2 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Library General Public License for more details. # # You should have received a copy of the GNU Library General Public License # along with this library; see the file COPYING.LIB. If not, write to # the Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. # # script to build statistics report # parameters are start and end date # writes out an xml file with the data in current directory # cvs repository location path. $repository = "/home/extra/kde_svn"; ($start,$end) = @ARGV; print "\n"; print "\n"; # assign hashes and variables for data %authorlines = (); #authorname,number %authorcommits = (); %authorfiles = (); %modulecount = (); %atomicmodule = (); %atomicauthor = (); $totallines = 0; $totalcommits = 0; $newfiles = 0; $modfiles = 0; $delfiles = 0; $module = ""; sub esc_chars { # will change, for example, a!!a to a\!\!a @_[0] =~ s/([\; \<\>\*\|`\&\$\!\#\(\)\[\]\{\}:'"])/\\$1/g; return @_[0]; } sub getmodule { #pathname my $p = @_[0]; $p =~ /^\/([\w-\.]*)\/([\w-\.]*)\/{0,1}([\w-\.]*)\/{0,1}([\w-\.]*)/; if ($1 eq 'branches') { if ($2 eq 'KDE') { return $4; } return $2; } if ($1 eq 'trunk') { if ($2 eq 'KDE') { return $3; } return $2; } if ($1 eq 'tags') { if ($2 eq 'KDE') { return $4; } return $3; } return "borked"; } sub parsefilerevision {#pass revision and filename my $rev = @_[0]; my $fn = @_[1]; chomp($fn); my $logstr = `svn log -r $rev file://$repository/$fn`; my @lines = split(/\n/,$logstr); foreach my $i (@lines) { # r4000 | coolo | 1998-01-08 04:51:06 -0800 (Thu, 08 Jan 1998) | 2 lines if ($i =~ /^r\d*\s\S\s(\S*)\s\S\s(\d*\D\d*\D\d*\D\d*\D\d*).*\|\s(\d*)/) { my $date = $2; my $author = $1; my $lines = $3; # removed bot from statistics $modfiles++; $totallines += $lines; my $i = $authorlines{$author}; $i += $lines; $authorlines{$author} = $i; $i = 0; $i = $authorfiles{$author}; $i++; $authorfiles{$author} = $i; } } } sub parserevision { #pass revision, will extract list of files and attributes my $rev = @_[0]; my $logstr = `svn log -v -r $rev file://$repository`; my @lines = split(/\n/,$logstr); $totalcommits++; my $incmodule = 0; foreach my $i (@lines) { if ($i =~ /^r\d*\s\S\s(\S*)\s\S\s(\d*\D\d*\D\d*\D\d*\D\d*).*\|\s(\d*)/) { my $c = 0; $c = $authorcommits{$1}; $c++; $authorcommits{$1} = $c; } if ($i =~ /^\s*(M|D|A)\s(.*)$/) { if ($1 eq 'M') { parsefilerevision($rev,$2); } if ($1 eq 'A') { $newfiles++; } if ($1 eq 'D') { $delfiles++; } #modules my $m = getmodule($2); if ($incmodule == 0) { my $cm = $modulecount{$m}; $cm++; $modulecount{$m} = $cm; $incmodule = 1; } my $c = $modulefilecount{$m}; $c++; $modulefilecount{$m} = $c; } } } sub in_array { # pass array and scalar. returns 1 if true, 0 if false my $sc = pop(@_); foreach my $i (@_) { if ($i eq $sc) {return 1;} } return 0; } sub by_number { my @af = split(/\:/,$a); my @bf = split(/\:/,$b); if (@af[0] < @bf[0]) { return -1; } elsif (@af[0] == @bf[0]) { return 0; } elsif (@af[0] > @bf[0]) { return 1; } } for ($i = $start; $i <= $end; $i++) { parserevision($i); } while (($module,$count) = each %modulecount) { push(@modulelist, "$count:$module"); } @modulelist = sort by_number @modulelist; @modulelist = reverse(@modulelist); while (($author, $count) = each %authorcommits) { push(@authorclist, "$count:$author"); } @authorclist = sort by_number @authorclist; @authorclist = reverse(@authorclist); while (($author, $count) = each %authorlines) { push(@authorllist, "$count:$author"); } @authorllist = sort by_number @authorllist; $authorcount = @authorclist; print "\n$totalcommits\n$totallines\n"; print "$newfiles\n$modfiles\n$authorcount\n"; #bugstats(); print "\n"; #print "\n"; #i18nstat(); #print "\n"; print "\n"; foreach $imod (@modulelist) { my @ma = split(/:/,$imod); print "\n@ma[1]\n"; print "@ma[0]\n"; print "$modulefilecount{@ma[1]}\n\n"; } print "\n"; print "\n"; foreach $imod (@authorclist) { my @ma = split(/:/,$imod); if (@ma[1] eq 'scripty') {next;} print "\n@ma[1]\n$authorfiles{@ma[1]}\n"; print "@ma[0]"; print "$authorlines{@ma[1]}\n"; print "\n"; } print "\n"; print "";