1 |
#!/usr/bin/perl -w |
2 |
|
3 |
# Produce nice statistics from SubVersion repository |
4 |
|
5 |
use strict; |
6 |
use XML::Simple; |
7 |
|
8 |
my $repo = shift @ARGV || die "usage: $0 /path/to/svn/repository\n"; |
9 |
|
10 |
$repo = "file://$repo" if -e $repo; |
11 |
|
12 |
my $debug = 0; |
13 |
my $tsv = 0; |
14 |
|
15 |
my $from_rev = 1; |
16 |
my $to_rev = 'HEAD'; |
17 |
|
18 |
my %add; |
19 |
my %del; |
20 |
my %lin; |
21 |
|
22 |
# print headline |
23 |
|
24 |
print STDERR "reading log\n" if $debug; |
25 |
|
26 |
open(LOG, "svn log -v --xml -r $from_rev:$to_rev $repo |") || die "svn log: $!"; |
27 |
my $log; |
28 |
while(<LOG>) { |
29 |
$log .= $_; |
30 |
} |
31 |
close(LOG); |
32 |
|
33 |
my $fmt = "\n" . "-" x 79 . "\nr%5s| %8s | %s\n\n%s\n"; |
34 |
|
35 |
my $xml = XMLin($log, ForceArray => [ 'logentry', 'path' ]); |
36 |
foreach my $e (@{$xml->{'logentry'}}) { |
37 |
my $rev = $e->{'revision'}; |
38 |
my $date = $e->{'date'}; |
39 |
$date =~ s/T/ /; |
40 |
$date =~ s/\..*$//; |
41 |
# $date =~ s/(\d\d\d\d)-(\d\d)-(\d\d)/$2\/$3\/$1/ || die "can't parse date: $date"; |
42 |
|
43 |
printf STDERR ($fmt, $e->{'revision'}, $e->{'author'}, $e->{'date'}, $e->{'msg'}) if $debug; |
44 |
foreach my $p (@{$e->{'paths'}->{'path'}}) { |
45 |
my ($action,$path) = ($p->{'action'},$p->{'content'}); |
46 |
|
47 |
print STDERR "$action: $path\n" if $debug; |
48 |
} |
49 |
|
50 |
my $msg = $e->{'msg'}; |
51 |
$msg =~ s{\s+}{ }gs; |
52 |
|
53 |
# cound added/deleted lines for this revision |
54 |
|
55 |
open(DIFF, "svn diff -r".($rev-1).":$rev $repo |") || die "svn diff: $!"; |
56 |
|
57 |
my ($add,$del) = (0,0); |
58 |
|
59 |
my $skip = 1; |
60 |
my $files = 0; |
61 |
my $path; |
62 |
|
63 |
while(<DIFF>) { |
64 |
chomp; |
65 |
print STDERR "DIFF $_\n" if $debug; |
66 |
if (/^Index:\s+(\S+)/) { |
67 |
$path = $2; |
68 |
$files++; |
69 |
} elsif (/^(\+|-|\s)/) { |
70 |
if ("$1" eq "+") { |
71 |
$add++; |
72 |
} elsif ("$1" eq "-") { |
73 |
$del--; |
74 |
} |
75 |
} |
76 |
} |
77 |
close(DIFF); |
78 |
|
79 |
if ( $tsv ) { |
80 |
print $repo, '@', $rev, |
81 |
"\trepo\t$repo\trev\t$rev\tdate\t$date\tfiles\t$files\tadd\t$add\tdel\t$del\tmessage\t$msg\n"; |
82 |
} else { |
83 |
print "$repo\t$rev\t$date\t$files\t$add\t$del\t$msg\n"; |
84 |
} |
85 |
|
86 |
} |