/[Frey]/branches/zimbardo/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 /branches/zimbardo/lib/Frey/SVN.pm

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

trunk/lib/Frey/SVN.pm revision 987 by dpavlin, Sat Jan 10 21:42:00 2009 UTC branches/zimbardo/lib/Frey/SVN.pm revision 1190 by dpavlin, Mon Sep 28 20:24:18 2009 UTC
# Line 7  use Moose; Line 7  use Moose;
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',
# Line 31  has limit => ( Line 32  has limit => (
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                    
# Line 57  sub iterator { Line 70  sub iterator {
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    
# Line 93  sub iterator { Line 108  sub iterator {
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 $path = "$cache/$rev.storable";
134                            my $data;
135    
136                            if ( -e $path ) {
137                                    $data = $self->load( $path );
138                                    $e->{diff_paths} = $data->{diff_paths};
139                            } else {
140                                    my $cmd = "svn diff -c $rev $svn_path";
141                                    my ( $diff_fh, $diff_out );
142                                    my $diff_file = "$cache/$rev.diff";
143    
144                                    open($diff_fh, '-|', $cmd)       || die "can't open pipe from $cmd: $!";
145                                    open($diff_out,'>' , $diff_file) || die "can't write $diff_file: $!";
146                                    #warn "# creating $diff_file from $cmd\n";
147    
148                                    my $diff_path;
149                                    my $changes;
150                                    my $diff = '';
151    
152                                    while( <$diff_fh> ) {
153                                            $diff .= $_;
154                                            print $diff_out $_;
155    
156                                            if ( m{^\+\+\+ (\S+)} ) {
157                                                    $diff_path = "/$1"; # subversion paths start with /
158                                            } elsif ( m{^\+} && $diff_path ) {
159                                                    $changes->{$diff_path}->{added}++;
160                                            } elsif ( m{^-} && $diff_path ) {
161                                                    $changes->{$diff_path}->{removed}++;
162                                            }
163                                    }
164    
165                                    $e->{diff} = $diff if $self->include_diff;
166                                    $e->{diff_paths} = $changes;
167    
168                                    $self->store( $path, $e ) if $self->include_diff && $self->file_stats;
169                            }
170            
171                    }
172    
173                  $coderef->($e);                  $coderef->($e);
174          }          }
175  }  }
# Line 157  sub as_markup { Line 230  sub as_markup {
230                  del { color: #c88 }                  del { color: #c88 }
231          |);          |);
232    
233            my $max_path_len = 0;
234            my $path_count;
235            my $stats;
236    
237          $self->iterator( sub {          $self->iterator( sub {
238                  my $e = shift;                  my $e = shift;
239    
# Line 185  sub as_markup { Line 262  sub as_markup {
262                          } else {                          } else {
263                                  push @files, $path;                                  push @files, $path;
264                          }                          }
265    
266                            $max_path_len = length $path if length $path > $max_path_len;
267                            $path_count->{$path}++;
268    
269                            if ( my $added = $e->{diff_paths}->{$path}->{added} ) {
270                                    $stats->{total_added} += $added;
271                            }
272    
273                            if ( my $removed = $e->{diff_paths}->{$path}->{removed} ) {
274                                    $stats->{total_removed} += $removed;
275                            }
276                  }                  }
277    
278                    my $diff = $self->html_diff( $e->{diff} ) if $e->{diff};
279    
280                    $self->add_css(qq|
281                            .diff-lines {
282                                    margin-left: 1em;
283                                    float: right;
284                            }
285                    |);
286    
287                  $html .= qq|                  $html .= qq|
288                          <div class="commit">                          <div class="commit">
289                                  <span class="date">$date</span>                                  <span class="date">$date</span>
# Line 196  sub as_markup { Line 293  sub as_markup {
293                                  |                                  |
294                                  . join("<br>\n",                                  . join("<br>\n",
295                                          map {                                          map {
296                                                  qq|<a href="?repository=$repository;path=$_">$_</a>|                                                  my $path = $_;
297                                                    $path =~ s{<[^>]+>}{}g;
298                                                    my $diff = '';
299                                                    if ( $diff = $e->{diff_paths}->{$path} ) {
300                                                            $diff
301                                                            = qq|<span class="diff-lines">|
302                                                            . join(" ",
303                                                                    map {
304                                                                            my $v = $diff->{$_};
305                                                                            s[added][+$v];
306                                                                            s[removed][-$v];
307                                                                            $_;
308                                                                    } keys %$diff
309                                                            )
310                                                            . qq|</span>|
311                                                            ;
312                                                            warn "DIFF $diff";
313                                                    }
314    
315                                                    qq|$diff<a href="?repository=$repository;path=$path" title="$path ##">$_</a>|
316                                          } @files                                          } @files
317                                  )                                  )
318                                  . qq|                                  . qq|
319                                  </div>                                  </div>
320                                  $msg                                  $msg
321                                    $diff
322                          </div>                          </div>
323                  |;                  |;
324    
325          });          });
326    
327            $max_path_len +=
328                  length( $stats->{total_added} )
329                    + length( $stats->{total_removed} )
330                    ;
331    
332            $max_path_len += int( $max_path_len / 4 ); # we are using ex, so we adjust length
333    
334            $self->add_css(qq|
335                    .files {
336                            width: ${max_path_len}ex;
337                    }
338            |);
339    
340            $html =~ s[title="(\S+) ##"]['title="' . $path_count->{$1} . '"']gse;
341    
342            $html .= $self->dump( 'stats', $stats );
343    
344          return $html;          return $html;
345  }  }
346    
# Line 226  sub codeswarm_as_markup { Line 360  sub codeswarm_as_markup {
360    
361                  foreach my $p (@{$e->{'paths'}->{'path'}}) {                  foreach my $p (@{$e->{'paths'}->{'path'}}) {
362                          my ($action,$path) = ($p->{'action'},$p->{'content'});                          my ($action,$path) = ($p->{'action'},$p->{'content'});
363                          $file_events .= qq|\t<event filename="$path" date="$date" author="$author" />\n|;                          my $weight = '';
364                            if ( my $s = $e->{diff_paths}->{$path} ) {
365                                    $weight  = $s->{removed} || 0;
366                                    $weight += $s->{added} * 2 if $s->{added};
367                                    $weight  = qq| weight="$weight" |;
368                            }
369                            $file_events .= qq|\t<event filename="$path" date="$date" author="$author"$weight/>\n|;
370                  }                  }
371    
372          });          });
373    
374            warn "generated ",length($file_events)," bytes of file events\n";
375    
376          return qq|<?xml version="1.0"?>          return qq|<?xml version="1.0"?>
377          <!-- One commit per day for one month by a documenter and programmer. -->          <!-- One commit per day for one month by a documenter and programmer. -->
378          <file_events>          <file_events>
# Line 240  sub codeswarm_as_markup { Line 382  sub codeswarm_as_markup {
382    
383  }  }
384    
385    __PACKAGE__->meta->make_immutable;
386    no Moose;
387    
388  1;  1;

Legend:
Removed from v.987  
changed lines
  Added in v.1190

  ViewVC Help
Powered by ViewVC 1.1.26