/[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 1068 by dpavlin, Mon Apr 27 20:30:20 2009 UTC revision 1077 by dpavlin, Wed Jun 3 18:19:03 2009 UTC
# Line 120  sub iterator { Line 120  sub iterator {
120    
121                          $e->{diff_paths}->{rev} = $rev; # XXX debug                          $e->{diff_paths}->{rev} = $rev; # XXX debug
122    
123                          my $diff_file = $svn_path;                          my $cache = $svn_path;
124                          $diff_file =~ s{^\w+:/+}{};                          $cache =~ s{^\w+:/+}{};
125                          mkpath "var/svn/$diff_file" unless -e "var/svn/$diff_file";                          $cache = "var/svn/$cache";
126                          $diff_file = "var/svn/$diff_file/$rev.diff";                          mkpath $cache unless -e $cache;
127                          my $diff_fh;                          my $diff_paths = $self->load( "$cache/$rev.yaml" );
128                          my $diff_out;                          if ( ! $diff_paths ) {
                         if ( ! -e $diff_file || ! -s $diff_file ) {  
129                                  my $cmd = "svn diff -c $rev $svn_path";                                  my $cmd = "svn diff -c $rev $svn_path";
130                                  open($diff_fh, '-|', $cmd )  || die "can't open pipe from $cmd: $!";                                  my ( $diff_fh, $diff_out );
131                                  open($diff_out,'>' , $diff_file ) || die "can't write $diff_file: $!";                                  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";                                  warn "# creating $diff_file from $cmd\n";
                         } else {  
                                 open($diff_fh, '<' , $diff_file ) || die "can't read $diff_file: $!";  
                         }  
136    
137                          my $diff_path;                                  my $diff_path;
138    
139                          while( <$diff_fh> ) {                                  while( <$diff_fh> ) {
140                                  $e->{diff} .= $_ if $self->include_diff;                                          print $diff_out $_;
                                 print $diff_out $_ if defined $diff_out;  
141    
142                                  if ( m{^\+\+\+ (\S+)} ) {                                          if ( m{^\+\+\+ (\S+)} ) {
143                                          $diff_path = "/$1"; # subversion paths start with /                                                  $diff_path = "/$1"; # subversion paths start with /
144                                  } elsif ( m{^\+} && $diff_path ) {                                          } elsif ( m{^\+} && $diff_path ) {
145                                          $e->{diff_paths}->{$diff_path}->{added}++;                                                  $diff_paths->{$diff_path}->{added}++;
146                                  } elsif ( m{^-} && $diff_path ) {                                          } elsif ( m{^-} && $diff_path ) {
147                                          $e->{diff_paths}->{$diff_path}->{removed}++;                                                  $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);
# Line 213  sub as_markup { Line 216  sub as_markup {
216    
217          my $max_path_len = 0;          my $max_path_len = 0;
218          my $path_count;          my $path_count;
219            my $stats;
220    
221          $self->iterator( sub {          $self->iterator( sub {
222                  my $e = shift;                  my $e = shift;
# Line 245  sub as_markup { Line 249  sub as_markup {
249    
250                          $max_path_len = length $path if length $path > $max_path_len;                          $max_path_len = length $path if length $path > $max_path_len;
251                          $path_count->{$path}++;                          $path_count->{$path}++;
252    
253                            if ( my $added = $e->{diff_paths}->{$path}->{added} ) {
254                                    $stats->{total_added} += $added;
255                            }
256    
257                            if ( my $removed = $e->{diff_paths}->{$path}->{removed} ) {
258                                    $stats->{total_removed} += $removed;
259                            }
260                  }                  }
261    
262                  my $diff = $self->html_diff( $e->{diff} ) if $e->{diff};                  my $diff = $self->html_diff( $e->{diff} ) if $e->{diff};
263    
264                  $html .= $self->dump( $e->{diff_paths} );                  $self->add_css(qq|
265                            .diff-lines {
266                                    margin-left: 1em;
267                                    float: right;
268                            }
269                    |);
270    
271                  $html .= qq|                  $html .= qq|
272                          <div class="commit">                          <div class="commit">
# Line 262  sub as_markup { Line 279  sub as_markup {
279                                          map {                                          map {
280                                                  my $path = $_;                                                  my $path = $_;
281                                                  $path =~ s{<[^>]+>}{}g;                                                  $path =~ s{<[^>]+>}{}g;
282                                                  qq|<a href="?repository=$repository;path=$path" title="$path ##">$_</a>|                                                  my $diff = '';
283                                                    if ( $diff = $e->{diff_paths}->{$path} ) {
284                                                            $diff
285                                                            = qq|<span class="diff-lines">|
286                                                            . join(" ",
287                                                                    map {
288                                                                            my $v = $diff->{$_};
289                                                                            s[added][+$v];
290                                                                            s[removed][-$v];
291                                                                            $_;
292                                                                    } keys %$diff
293                                                            )
294                                                            . qq|</span>|
295                                                            ;
296                                                            warn "DIFF $diff";
297                                                    }
298    
299                                                    qq|$diff<a href="?repository=$repository;path=$path" title="$path ##">$_</a>|
300                                          } @files                                          } @files
301                                  )                                  )
302                                  . qq|                                  . qq|
# Line 274  sub as_markup { Line 308  sub as_markup {
308    
309          });          });
310    
311            $max_path_len +=
312                  length( $stats->{total_added} )
313                    + length( $stats->{total_removed} )
314                    ;
315    
316            $max_path_len += int( $max_path_len / 10 ); # we are using ex, so we add 10%
317    
318          $self->add_css(qq|          $self->add_css(qq|
319                  .files {                  .files {
320                          width: ${max_path_len}ex;                          width: ${max_path_len}ex;
# Line 282  sub as_markup { Line 323  sub as_markup {
323    
324          $html =~ s[title="(\S+) ##"]['title="' . $path_count->{$1} . '"']gse;          $html =~ s[title="(\S+) ##"]['title="' . $path_count->{$1} . '"']gse;
325    
326            $html .= $self->dump( 'stats', $stats );
327    
328          return $html;          return $html;
329  }  }
330    
# Line 303  sub codeswarm_as_markup { Line 346  sub codeswarm_as_markup {
346                          my ($action,$path) = ($p->{'action'},$p->{'content'});                          my ($action,$path) = ($p->{'action'},$p->{'content'});
347                          my $weight = '';                          my $weight = '';
348                          if ( my $s = $e->{diff_paths}->{$path} ) {                          if ( my $s = $e->{diff_paths}->{$path} ) {
349                                  $weight  = $s->{removed}   if $s->{removed};                                  $weight  = $s->{removed} || 0;
350                                  $weight += $s->{added} * 2 if $s->{added};                                  $weight += $s->{added} * 2 if $s->{added};
351                                  $weight  = qq| weight="$weight" |;                                  $weight  = qq| weight="$weight" |;
352                          }                          }

Legend:
Removed from v.1068  
changed lines
  Added in v.1077

  ViewVC Help
Powered by ViewVC 1.1.26