7 |
# 2004-04-28 Dobrica Pavlinusic <dpavlin@rot13.org> |
# 2004-04-28 Dobrica Pavlinusic <dpavlin@rot13.org> |
8 |
|
|
9 |
extends 'Frey'; |
extends 'Frey'; |
10 |
with 'Frey::Web'; |
with 'Frey::Web', 'Frey::Storage', 'Frey::HTML::Diff'; |
|
#with 'Frey::Storage'; |
|
11 |
|
|
12 |
use XML::Simple; |
use XML::Simple; |
13 |
use DateTimeX::Easy; |
use DateTimeX::Easy; |
14 |
|
use Text::Diff::Parser; |
15 |
|
use File::Path qw/mkpath/; |
16 |
|
|
17 |
has repository => ( |
has repository => ( |
18 |
is => 'rw', |
is => 'rw', |
32 |
default => 50, |
default => 50, |
33 |
); |
); |
34 |
|
|
35 |
|
has include_diff => ( |
36 |
|
is => 'ro', |
37 |
|
isa => 'Bool', |
38 |
|
default => 0, |
39 |
|
); |
40 |
|
|
41 |
|
has file_stats => ( |
42 |
|
is => 'ro', |
43 |
|
isa => 'Bool', |
44 |
|
default => 1, |
45 |
|
); |
46 |
|
|
47 |
sub iterator { |
sub iterator { |
48 |
my ($self,$coderef) = @_; |
my ($self,$coderef) = @_; |
49 |
|
|
70 |
warn "# path $path\n"; |
warn "# path $path\n"; |
71 |
|
|
72 |
my $cmd; |
my $cmd; |
73 |
|
my $svn_path = $path; |
74 |
|
|
75 |
if ($path =~ m#file://# || -e "$path/.svn") { |
if ($path =~ m#file://# || -e "$path/.svn") { |
76 |
$cmd = "svn log -v --xml $path"; |
$cmd = "svn log -v --xml $path"; |
77 |
} else { |
} else { |
78 |
my $svn_path = sh_regex('svk info', qr#Mirrored From:\s+([^,]+)#i); |
$svn_path = sh_regex('svk info', qr#Mirrored From:\s+([^,]+)#i); |
79 |
|
|
80 |
if (! $svn_path) { |
if (! $svn_path) { |
81 |
|
|
108 |
} |
} |
109 |
close($fh); |
close($fh); |
110 |
|
|
111 |
|
warn "got ", length($log), " bytes of XML changes\n"; |
112 |
|
|
113 |
my $xml = XMLin($log, ForceArray => [ 'logentry', 'path' ]); |
my $xml = XMLin($log, ForceArray => [ 'logentry', 'path' ]); |
114 |
|
|
115 |
foreach my $e (@{$xml->{'logentry'}}) { |
foreach my $e (@{$xml->{'logentry'}}) { |
116 |
warn "# e = ",$self->dump( $e ) if $self->debug; |
warn "# e = ",$self->dump( $e ) if $self->debug; |
117 |
|
|
118 |
|
if ( $self->include_diff || $self->file_stats ) { |
119 |
|
my $rev = $e->{'revision'}; |
120 |
|
|
121 |
|
warn "# revision $rev\n" if $rev % 100 == 0; |
122 |
|
|
123 |
|
$e->{diff_paths}->{rev} = $rev; # XXX debug |
124 |
|
|
125 |
|
my $cache = $svn_path; |
126 |
|
$cache =~ s{^\w+:/+}{}; |
127 |
|
$cache = "var/svn/$cache"; |
128 |
|
mkpath $cache unless -e $cache; |
129 |
|
|
130 |
|
my $diff_path = "$cache/$rev.diff"; |
131 |
|
$e->{diff} = $self->load( $diff_path ) if $self->include_diff && -e $diff_path; |
132 |
|
|
133 |
|
my $diff_yaml = "$cache/$rev.yaml"; |
134 |
|
|
135 |
|
if ( -e $diff_yaml ) { |
136 |
|
$e->{diff_paths} = $self->load( $diff_yaml ); |
137 |
|
} else { |
138 |
|
my $cmd = "svn diff -c $rev $svn_path"; |
139 |
|
my ( $diff_fh, $diff_out ); |
140 |
|
my $diff_file = "$cache/$rev.diff"; |
141 |
|
|
142 |
|
open($diff_fh, '-|', $cmd) || die "can't open pipe from $cmd: $!"; |
143 |
|
open($diff_out,'>' , $diff_file) || die "can't write $diff_file: $!"; |
144 |
|
#warn "# creating $diff_file from $cmd\n"; |
145 |
|
|
146 |
|
my $diff_path; |
147 |
|
my $changes; |
148 |
|
my $diff = ''; |
149 |
|
|
150 |
|
while( <$diff_fh> ) { |
151 |
|
$diff .= $_; |
152 |
|
print $diff_out $_; |
153 |
|
|
154 |
|
if ( m{^\+\+\+ (\S+)} ) { |
155 |
|
$diff_path = "/$1"; # subversion paths start with / |
156 |
|
} elsif ( m{^\+} && $diff_path ) { |
157 |
|
$changes->{$diff_path}->{added}++; |
158 |
|
} elsif ( m{^-} && $diff_path ) { |
159 |
|
$changes->{$diff_path}->{removed}++; |
160 |
|
} |
161 |
|
} |
162 |
|
|
163 |
|
$e->{diff} = $diff if $self->include_diff; |
164 |
|
|
165 |
|
$self->store( "$cache/$rev.yaml", $changes ); |
166 |
|
$e->{diff_paths} = $changes; |
167 |
|
} |
168 |
|
|
169 |
|
} |
170 |
|
|
171 |
$coderef->($e); |
$coderef->($e); |
172 |
} |
} |
173 |
} |
} |
228 |
del { color: #c88 } |
del { color: #c88 } |
229 |
|); |
|); |
230 |
|
|
231 |
|
my $max_path_len = 0; |
232 |
|
my $path_count; |
233 |
|
my $stats; |
234 |
|
|
235 |
$self->iterator( sub { |
$self->iterator( sub { |
236 |
my $e = shift; |
my $e = shift; |
237 |
|
|
260 |
} else { |
} else { |
261 |
push @files, $path; |
push @files, $path; |
262 |
} |
} |
263 |
|
|
264 |
|
$max_path_len = length $path if length $path > $max_path_len; |
265 |
|
$path_count->{$path}++; |
266 |
|
|
267 |
|
if ( my $added = $e->{diff_paths}->{$path}->{added} ) { |
268 |
|
$stats->{total_added} += $added; |
269 |
|
} |
270 |
|
|
271 |
|
if ( my $removed = $e->{diff_paths}->{$path}->{removed} ) { |
272 |
|
$stats->{total_removed} += $removed; |
273 |
|
} |
274 |
} |
} |
275 |
|
|
276 |
|
my $diff = $self->html_diff( $e->{diff} ) if $e->{diff}; |
277 |
|
|
278 |
|
$self->add_css(qq| |
279 |
|
.diff-lines { |
280 |
|
margin-left: 1em; |
281 |
|
float: right; |
282 |
|
} |
283 |
|
|); |
284 |
|
|
285 |
$html .= qq| |
$html .= qq| |
286 |
<div class="commit"> |
<div class="commit"> |
287 |
<span class="date">$date</span> |
<span class="date">$date</span> |
291 |
| |
| |
292 |
. join("<br>\n", |
. join("<br>\n", |
293 |
map { |
map { |
294 |
qq|<a href="?repository=$repository;path=$_">$_</a>| |
my $path = $_; |
295 |
|
$path =~ s{<[^>]+>}{}g; |
296 |
|
my $diff = ''; |
297 |
|
if ( $diff = $e->{diff_paths}->{$path} ) { |
298 |
|
$diff |
299 |
|
= qq|<span class="diff-lines">| |
300 |
|
. join(" ", |
301 |
|
map { |
302 |
|
my $v = $diff->{$_}; |
303 |
|
s[added][+$v]; |
304 |
|
s[removed][-$v]; |
305 |
|
$_; |
306 |
|
} keys %$diff |
307 |
|
) |
308 |
|
. qq|</span>| |
309 |
|
; |
310 |
|
warn "DIFF $diff"; |
311 |
|
} |
312 |
|
|
313 |
|
qq|$diff<a href="?repository=$repository;path=$path" title="$path ##">$_</a>| |
314 |
} @files |
} @files |
315 |
) |
) |
316 |
. qq| |
. qq| |
317 |
</div> |
</div> |
318 |
$msg |
$msg |
319 |
|
$diff |
320 |
</div> |
</div> |
321 |
|; |
|; |
322 |
|
|
323 |
}); |
}); |
324 |
|
|
325 |
|
$max_path_len += |
326 |
|
length( $stats->{total_added} ) |
327 |
|
+ length( $stats->{total_removed} ) |
328 |
|
; |
329 |
|
|
330 |
|
$max_path_len += int( $max_path_len / 4 ); # we are using ex, so we adjust length |
331 |
|
|
332 |
|
$self->add_css(qq| |
333 |
|
.files { |
334 |
|
width: ${max_path_len}ex; |
335 |
|
} |
336 |
|
|); |
337 |
|
|
338 |
|
$html =~ s[title="(\S+) ##"]['title="' . $path_count->{$1} . '"']gse; |
339 |
|
|
340 |
|
$html .= $self->dump( 'stats', $stats ); |
341 |
|
|
342 |
return $html; |
return $html; |
343 |
} |
} |
344 |
|
|
358 |
|
|
359 |
foreach my $p (@{$e->{'paths'}->{'path'}}) { |
foreach my $p (@{$e->{'paths'}->{'path'}}) { |
360 |
my ($action,$path) = ($p->{'action'},$p->{'content'}); |
my ($action,$path) = ($p->{'action'},$p->{'content'}); |
361 |
$file_events .= qq|\t<event filename="$path" date="$date" author="$author" />\n|; |
my $weight = ''; |
362 |
|
if ( my $s = $e->{diff_paths}->{$path} ) { |
363 |
|
$weight = $s->{removed} || 0; |
364 |
|
$weight += $s->{added} * 2 if $s->{added}; |
365 |
|
$weight = qq| weight="$weight" |; |
366 |
|
} |
367 |
|
$file_events .= qq|\t<event filename="$path" date="$date" author="$author"$weight/>\n|; |
368 |
} |
} |
369 |
|
|
370 |
}); |
}); |
371 |
|
|
372 |
|
warn "generated ",length($file_events)," bytes of file events\n"; |
373 |
|
|
374 |
return qq|<?xml version="1.0"?> |
return qq|<?xml version="1.0"?> |
375 |
<!-- One commit per day for one month by a documenter and programmer. --> |
<!-- One commit per day for one month by a documenter and programmer. --> |
376 |
<file_events> |
<file_events> |
380 |
|
|
381 |
} |
} |
382 |
|
|
383 |
|
__PACKAGE__->meta->make_immutable; |
384 |
|
no Moose; |
385 |
|
|
386 |
1; |
1; |