14 |
use XML::Simple; |
use XML::Simple; |
15 |
use DateTimeX::Easy; |
use DateTimeX::Easy; |
16 |
use Text::Diff::Parser; |
use Text::Diff::Parser; |
17 |
|
use File::Path qw/mkpath/; |
18 |
|
|
19 |
has repository => ( |
has repository => ( |
20 |
is => 'rw', |
is => 'rw', |
37 |
has include_diff => ( |
has include_diff => ( |
38 |
is => 'ro', |
is => 'ro', |
39 |
isa => 'Bool', |
isa => 'Bool', |
40 |
default => 1, |
default => 0, |
41 |
); |
); |
42 |
|
|
43 |
has file_stats => ( |
has file_stats => ( |
117 |
|
|
118 |
if ( $self->include_diff || $self->file_stats ) { |
if ( $self->include_diff || $self->file_stats ) { |
119 |
my $rev = $e->{'revision'}; |
my $rev = $e->{'revision'}; |
|
my $file = $svn_path; |
|
|
$file =~ s{^\w+:/+}{}; |
|
|
my $file = "var/svn/$file/$rev.diff"; |
|
|
my $diff = $self->load( $file ); |
|
|
if ( ! $diff ) { |
|
|
$diff = `svn diff -c $rev $svn_path`; |
|
|
$self->store( $file, $diff ); |
|
|
} |
|
|
|
|
|
$e->{diff} .= $diff if $self->include_diff; |
|
120 |
|
|
121 |
$e->{diff_paths}->{rev} = $rev; # XXX debug |
$e->{diff_paths}->{rev} = $rev; # XXX debug |
122 |
|
|
123 |
my $diff_path; |
my $cache = $svn_path; |
124 |
foreach my $line ( split(/[\n\r]/, $diff ) ) { |
$cache =~ s{^\w+:/+}{}; |
125 |
if ( $line =~ m{^\+\+\+ (\S+)} ) { |
$cache = "var/svn/$cache"; |
126 |
$diff_path = "/$1"; # subversion paths start with / |
mkpath $cache unless -e $cache; |
127 |
} elsif ( $line =~ m{^\+} ) { |
my $diff_paths = $self->load( "$cache/$rev.yaml" ); |
128 |
$e->{diff_paths}->{$diff_path}->{added}++; |
if ( ! $diff_paths ) { |
129 |
} elsif ( $line =~ m{^-} ) { |
my $cmd = "svn diff -c $rev $svn_path"; |
130 |
$e->{diff_paths}->{$diff_path}->{removed}++; |
my ( $diff_fh, $diff_out ); |
131 |
|
my $diff_file = "$cache/$rev.diff"; |
132 |
|
|
133 |
|
open($diff_fh, '-|', $cmd) || die "can't open pipe from $cmd: $!"; |
134 |
|
open($diff_out,'>' , $diff_file) || die "can't write $diff_file: $!"; |
135 |
|
warn "# creating $diff_file from $cmd\n"; |
136 |
|
|
137 |
|
my $diff_path; |
138 |
|
|
139 |
|
while( <$diff_fh> ) { |
140 |
|
print $diff_out $_; |
141 |
|
|
142 |
|
if ( m{^\+\+\+ (\S+)} ) { |
143 |
|
$diff_path = "/$1"; # subversion paths start with / |
144 |
|
} elsif ( m{^\+} && $diff_path ) { |
145 |
|
$diff_paths->{$diff_path}->{added}++; |
146 |
|
} elsif ( m{^-} && $diff_path ) { |
147 |
|
$diff_paths->{$diff_path}->{removed}++; |
148 |
|
} |
149 |
} |
} |
150 |
|
|
151 |
|
$self->store( "$cache/$rev.yaml", $diff_paths ); |
152 |
} |
} |
153 |
|
$e->{diff} = $self->load( "$cache/$rev.diff" ) if $self->include_diff; |
154 |
|
$e->{diff_paths} = $self->load( "$cache/$rev.yaml" ); |
155 |
} |
} |
156 |
|
|
157 |
$coderef->($e); |
$coderef->($e); |
305 |
foreach my $p (@{$e->{'paths'}->{'path'}}) { |
foreach my $p (@{$e->{'paths'}->{'path'}}) { |
306 |
my ($action,$path) = ($p->{'action'},$p->{'content'}); |
my ($action,$path) = ($p->{'action'},$p->{'content'}); |
307 |
my $weight = ''; |
my $weight = ''; |
308 |
if ( defined $e->{diff_paths}->{$path} ) { |
if ( my $s = $e->{diff_paths}->{$path} ) { |
309 |
$weight = $e->{diff_paths}->{$path}->{removed}; |
|
310 |
$weight += $e->{diff_paths}->{$path}->{added} * 2; |
warn $self->dump( $s ); |
311 |
|
$weight = $s->{removed} if defined $s->{removed}; |
312 |
|
$weight += $s->{added} * 2 if defined $s->{added}; |
313 |
$weight = qq| weight="$weight" |; |
$weight = qq| weight="$weight" |; |
314 |
} |
} |
315 |
$file_events .= qq|\t<event filename="$path" date="$date" author="$author"$weight/>\n|; |
$file_events .= qq|\t<event filename="$path" date="$date" author="$author"$weight/>\n|; |