/[tokyocabinet-toys]/svn-tsv.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /svn-tsv.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 7 - (show annotations)
Sat Jul 25 10:55:35 2009 UTC (14 years, 8 months ago) by dpavlin
File MIME type: text/plain
File size: 1685 byte(s)
parse subversion repositories and dump tsv file

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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26