# If SVN:: library support is added, please make the dependencies
# optional and preserve the capability to use the command-line client.
-# See what I do with XML::Simple to make the dependency optional.
+# use eval { require SVN::... } to make it lazy load
use Carp qw/croak/;
use IO::File qw//;
use File::Basename qw/dirname basename/;
push @log_args, "-r$_revision";
push @log_args, '--stop-on-copy' unless $_no_stop_copy;
- eval { require XML::Simple or croak $! };
- my $svn_log = $@ ? svn_log_raw(@log_args) : svn_log_xml(@log_args);
+ my $svn_log = svn_log_raw(@log_args);
@$svn_log = sort { $a->{revision} <=> $b->{revision} } @$svn_log;
my $base = shift @$svn_log or croak "No base revision!\n";
return fetch("$rev_committed=$commit")->{revision};
}
-sub svn_log_xml {
- my (@log_args) = @_;
- my $log_fh = IO::File->new_tmpfile or croak $!;
-
- my $pid = fork;
- defined $pid or croak $!;
-
- if ($pid == 0) {
- open STDOUT, '>&', $log_fh or croak $!;
- exec (qw(svn log --xml), @log_args) or croak $!
- }
-
- waitpid $pid, 0;
- croak $? if $?;
-
- seek $log_fh, 0, 0;
- my @svn_log;
- my $log = XML::Simple::XMLin( $log_fh,
- ForceArray => ['path','revision','logentry'],
- KeepRoot => 0,
- KeyAttr => { logentry => '+revision',
- paths => '+path' },
- )->{logentry};
- foreach my $r (sort {$a <=> $b} keys %$log) {
- my $log_msg = $log->{$r};
- my ($Y,$m,$d,$H,$M,$S) = ($log_msg->{date} =~
- /(\d{4})\-(\d\d)\-(\d\d)T
- (\d\d)\:(\d\d)\:(\d\d)\.\d+Z$/x)
- or croak "Failed to parse date: ",
- $log->{$r}->{date};
- $log_msg->{date} = "+0000 $Y-$m-$d $H:$M:$S";
-
- # XML::Simple can't handle <msg></msg> as a string:
- if (ref $log_msg->{msg} eq 'HASH') {
- $log_msg->{msg} = "\n";
- } else {
- $log_msg->{msg} .= "\n";
- }
- push @svn_log, $log->{$r};
- }
- return \@svn_log;
-}
-
sub svn_log_raw {
my (@log_args) = @_;
my $pid = open my $log_fh,'-|';
}
my @svn_log;
- my $state;
+ my $state = 'sep';
while (<$log_fh>) {
chomp;
if (/^\-{72}$/) {
+ if ($state eq 'msg') {
+ if ($svn_log[$#svn_log]->{lines}) {
+ $svn_log[$#svn_log]->{msg} .= $_."\n";
+ unless(--$svn_log[$#svn_log]->{lines}) {
+ $state = 'sep';
+ }
+ } else {
+ croak "Log parse error at: $_\n",
+ $svn_log[$#svn_log]->{revision},
+ "\n";
+ }
+ next;
+ }
+ if ($state ne 'sep') {
+ croak "Log parse error at: $_\n",
+ "state: $state\n",
+ $svn_log[$#svn_log]->{revision},
+ "\n";
+ }
$state = 'rev';
# if we have an empty log message, put something there:
if (@svn_log) {
$svn_log[$#svn_log]->{msg} ||= "\n";
+ delete $svn_log[$#svn_log]->{lines};
}
next;
}
if ($state eq 'rev' && s/^r(\d+)\s*\|\s*//) {
my $rev = $1;
- my ($author, $date) = split(/\s*\|\s*/, $_, 2);
+ my ($author, $date, $lines) = split(/\s*\|\s*/, $_, 3);
+ ($lines) = ($lines =~ /(\d+)/);
my ($Y,$m,$d,$H,$M,$S,$tz) = ($date =~
/(\d{4})\-(\d\d)\-(\d\d)\s
(\d\d)\:(\d\d)\:(\d\d)\s([\-\+]\d+)/x)
my %log_msg = ( revision => $rev,
date => "$tz $Y-$m-$d $H:$M:$S",
author => $author,
+ lines => $lines,
msg => '' );
push @svn_log, \%log_msg;
$state = 'msg_start';
if ($state eq 'msg_start' && /^$/) {
$state = 'msg';
} elsif ($state eq 'msg') {
- $svn_log[$#svn_log]->{msg} .= $_."\n";
+ if ($svn_log[$#svn_log]->{lines}) {
+ $svn_log[$#svn_log]->{msg} .= $_."\n";
+ unless (--$svn_log[$#svn_log]->{lines}) {
+ $state = 'sep';
+ }
+ } else {
+ croak "Log parse error at: $_\n",
+ $svn_log[$#svn_log]->{revision},"\n";
+ }
}
}
close $log_fh or croak $?;