--- trunk/lib/Frey/SVN.pm 2009/01/09 23:26:25 979 +++ trunk/lib/Frey/SVN.pm 2009/04/27 19:55:32 1067 @@ -8,10 +8,12 @@ extends 'Frey'; with 'Frey::Web'; -#with 'Frey::Storage'; +with 'Frey::Storage'; +with 'Frey::HTML::Diff'; use XML::Simple; use DateTimeX::Easy; +use Text::Diff::Parser; has repository => ( is => 'rw', @@ -20,12 +22,29 @@ default => 'file:///home/dpavlin/private/svn/Frey', ); +has path => ( + is => 'rw', + isa => 'Str' +); + has limit => ( is => 'rw', isa => 'Int', default => 50, ); +has include_diff => ( + is => 'ro', + isa => 'Bool', + default => 1, +); + +has file_stats => ( + is => 'ro', + isa => 'Bool', + default => 1, +); + sub iterator { my ($self,$coderef) = @_; @@ -48,14 +67,16 @@ return; } - my $path = $self->repository; + my $path = $self->repository . $self->path; warn "# path $path\n"; my $cmd; + my $svn_path = $path; + if ($path =~ m#file://# || -e "$path/.svn") { $cmd = "svn log -v --xml $path"; } else { - my $svn_path = sh_regex('svk info', qr#Mirrored From:\s+([^,]+)#i); + $svn_path = sh_regex('svk info', qr#Mirrored From:\s+([^,]+)#i); if (! $svn_path) { @@ -92,6 +113,34 @@ foreach my $e (@{$xml->{'logentry'}}) { warn "# e = ",$self->dump( $e ) if $self->debug; + + if ( $self->include_diff || $self->file_stats ) { + 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; + + $e->{diff_paths}->{rev} = $rev; # XXX debug + + my $diff_path; + foreach my $line ( split(/[\n\r]/, $diff ) ) { + if ( $line =~ m{^\+\+\+ (\S+)} ) { + $diff_path = "/$1"; # subversion paths start with / + } elsif ( $line =~ m{^\+} ) { + $e->{diff_paths}->{$diff_path}->{added}++; + } elsif ( $line =~ m{^-} ) { + $e->{diff_paths}->{$diff_path}->{removed}++; + } + } + } + $coderef->($e); } } @@ -115,7 +164,13 @@ return $foo; } - our $html = qq|

| . $self->repository . qq|

|; + my $repository = $self->repository; + my $path = $self->path; + + our $html = qq| +

$repository

+

$path

+ |; $self->add_css(qq| .commit { @@ -131,6 +186,10 @@ float: right; padding-bottom: 1.2em; /* fix 80% back to original 1em */ } + .files a { + text-decoration: none; + color: #888; + } .date, .revision { color: #666; } .message { padding-top: 0.5em; @@ -142,6 +201,9 @@ del { color: #c88 } |); + my $max_path_len = 0; + my $path_count; + $self->iterator( sub { my $e = shift; @@ -170,20 +232,46 @@ } else { push @files, $path; } + + $max_path_len = length $path if length $path > $max_path_len; + $path_count->{$path}++; } + my $diff = $self->html_diff( $e->{diff} ) if $e->{diff}; + + $html .= $self->dump( $e->{diff_paths} ); + $html .= qq|
- $date - $e->{author} - $e->{revision} -
\n| . join("
\n",@files) . qq|\n
- $msg + $date + $e->{author} + $e->{revision} +
\n + | + . join("
\n", + map { + my $path = $_; + $path =~ s{<[^>]+>}{}g; + qq|$_| + } @files + ) + . qq| +
+ $msg + $diff
|; }); + $self->add_css(qq| + .files { + width: ${max_path_len}ex; + } + |); + + $html =~ s[title="(\S+) ##"]['title="' . $path_count->{$1} . '"']gse; + return $html; } @@ -203,7 +291,13 @@ foreach my $p (@{$e->{'paths'}->{'path'}}) { my ($action,$path) = ($p->{'action'},$p->{'content'}); - $file_events .= qq|\t\n|; + my $weight = ''; + if ( defined $e->{diff_paths}->{$path} ) { + $weight = $e->{diff_paths}->{$path}->{removed}; + $weight += $e->{diff_paths}->{$path}->{added} * 2; + $weight = qq| weight="$weight" |; + } + $file_events .= qq|\t\n|; } });