/[Frey]/trunk/lib/Frey/SVN.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/Frey/SVN.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1067 by dpavlin, Mon Apr 27 19:55:32 2009 UTC revision 1078 by dpavlin, Thu Jun 4 19:23:32 2009 UTC
# Line 14  with 'Frey::HTML::Diff'; Line 14  with 'Frey::HTML::Diff';
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',
# Line 36  has limit => ( Line 37  has limit => (
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 => (
# Line 109  sub iterator { Line 110  sub iterator {
110          }          }
111          close($fh);          close($fh);
112    
113            warn "got ", length($log), " bytes of XML changes\n";
114    
115          my $xml = XMLin($log, ForceArray => [ 'logentry', 'path' ]);          my $xml = XMLin($log, ForceArray => [ 'logentry', 'path' ]);
116    
117          foreach my $e (@{$xml->{'logentry'}}) {          foreach my $e (@{$xml->{'logentry'}}) {
# Line 116  sub iterator { Line 119  sub iterator {
119    
120                  if ( $self->include_diff || $self->file_stats ) {                  if ( $self->include_diff || $self->file_stats ) {
121                          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;  
122    
123                          $e->{diff_paths}->{rev} = $rev; # XXX debug                          $e->{diff_paths}->{rev} = $rev; # XXX debug
124    
125                          my $diff_path;                          my $cache = $svn_path;
126                          foreach my $line ( split(/[\n\r]/, $diff ) ) {                          $cache =~ s{^\w+:/+}{};
127                                  if ( $line =~ m{^\+\+\+ (\S+)} ) {                          $cache = "var/svn/$cache";
128                                          $diff_path = "/$1"; # subversion paths start with /                          mkpath $cache unless -e $cache;
129                                  } elsif ( $line =~ m{^\+} ) {  
130                                          $e->{diff_paths}->{$diff_path}->{added}++;                          my $diff_path = "$cache/$rev.diff";
131                                  } elsif ( $line =~ m{^-} ) {                          $e->{diff} = $self->load( $diff_path ) if $self->include_diff && -e $diff_path;
132                                          $e->{diff_paths}->{$diff_path}->{removed}++;  
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);
# Line 203  sub as_markup { Line 230  sub as_markup {
230    
231          my $max_path_len = 0;          my $max_path_len = 0;
232          my $path_count;          my $path_count;
233            my $stats;
234    
235          $self->iterator( sub {          $self->iterator( sub {
236                  my $e = shift;                  my $e = shift;
# Line 235  sub as_markup { Line 263  sub as_markup {
263    
264                          $max_path_len = length $path if length $path > $max_path_len;                          $max_path_len = length $path if length $path > $max_path_len;
265                          $path_count->{$path}++;                          $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};                  my $diff = $self->html_diff( $e->{diff} ) if $e->{diff};
277    
278                  $html .= $self->dump( $e->{diff_paths} );                  $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">
# Line 252  sub as_markup { Line 293  sub as_markup {
293                                          map {                                          map {
294                                                  my $path = $_;                                                  my $path = $_;
295                                                  $path =~ s{<[^>]+>}{}g;                                                  $path =~ s{<[^>]+>}{}g;
296                                                  qq|<a href="?repository=$repository;path=$path" title="$path ##">$_</a>|                                                  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|
# Line 264  sub as_markup { Line 322  sub as_markup {
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 / 10 ); # we are using ex, so we add 10%
331    
332          $self->add_css(qq|          $self->add_css(qq|
333                  .files {                  .files {
334                          width: ${max_path_len}ex;                          width: ${max_path_len}ex;
# Line 272  sub as_markup { Line 337  sub as_markup {
337    
338          $html =~ s[title="(\S+) ##"]['title="' . $path_count->{$1} . '"']gse;          $html =~ s[title="(\S+) ##"]['title="' . $path_count->{$1} . '"']gse;
339    
340            $html .= $self->dump( 'stats', $stats );
341    
342          return $html;          return $html;
343  }  }
344    
# Line 292  sub codeswarm_as_markup { Line 359  sub codeswarm_as_markup {
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                          my $weight = '';                          my $weight = '';
362                          if ( defined   $e->{diff_paths}->{$path} ) {                          if ( my $s = $e->{diff_paths}->{$path} ) {
363                                  $weight  = $e->{diff_paths}->{$path}->{removed};                                  $weight  = $s->{removed} || 0;
364                                  $weight += $e->{diff_paths}->{$path}->{added} * 2;                                  $weight += $s->{added} * 2 if $s->{added};
365                                  $weight  = qq| weight="$weight" |;                                  $weight  = qq| weight="$weight" |;
366                          }                          }
367                          $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|;

Legend:
Removed from v.1067  
changed lines
  Added in v.1078

  ViewVC Help
Powered by ViewVC 1.1.26