/[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

revision 987 by dpavlin, Sat Jan 10 21:42:00 2009 UTC revision 1068 by dpavlin, Mon Apr 27 20:30:20 2009 UTC
# Line 8  use Moose; Line 8  use Moose;
8    
9  extends 'Frey';  extends 'Frey';
10  with 'Frey::Web';  with 'Frey::Web';
11  #with 'Frey::Storage';  with 'Frey::Storage';
12    with 'Frey::HTML::Diff';
13    
14  use XML::Simple;  use XML::Simple;
15  use DateTimeX::Easy;  use DateTimeX::Easy;
16    use Text::Diff::Parser;
17    use File::Path qw/mkpath/;
18    
19  has repository => (  has repository => (
20          is => 'rw',          is => 'rw',
# Line 31  has limit => ( Line 34  has limit => (
34          default => 50,          default => 50,
35  );  );
36    
37    has include_diff => (
38            is => 'ro',
39            isa => 'Bool',
40            default => 0,
41    );
42    
43    has file_stats => (
44            is => 'ro',
45            isa => 'Bool',
46            default => 1,
47    );
48    
49  sub iterator {  sub iterator {
50          my ($self,$coderef) = @_;          my ($self,$coderef) = @_;
51                    
# Line 57  sub iterator { Line 72  sub iterator {
72          warn "# path $path\n";          warn "# path $path\n";
73    
74          my $cmd;          my $cmd;
75            my $svn_path = $path;
76    
77          if ($path =~ m#file://# || -e "$path/.svn") {          if ($path =~ m#file://# || -e "$path/.svn") {
78                  $cmd = "svn log -v --xml $path";                  $cmd = "svn log -v --xml $path";
79          } else {          } else {
80                  my $svn_path = sh_regex('svk info', qr#Mirrored From:\s+([^,]+)#i);                  $svn_path = sh_regex('svk info', qr#Mirrored From:\s+([^,]+)#i);
81    
82                  if (! $svn_path) {                  if (! $svn_path) {
83    
# Line 97  sub iterator { Line 114  sub iterator {
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                            $e->{diff_paths}->{rev} = $rev; # XXX debug
122    
123                            my $diff_file = $svn_path;
124                            $diff_file =~ s{^\w+:/+}{};
125                            mkpath "var/svn/$diff_file" unless -e "var/svn/$diff_file";
126                            $diff_file = "var/svn/$diff_file/$rev.diff";
127                            my $diff_fh;
128                            my $diff_out;
129                            if ( ! -e $diff_file || ! -s $diff_file ) {
130                                    my $cmd = "svn diff -c $rev $svn_path";
131                                    open($diff_fh, '-|', $cmd )  || die "can't open pipe from $cmd: $!";
132                                    open($diff_out,'>' , $diff_file ) || die "can't write $diff_file: $!";
133                                    warn "# creating $diff_file from $cmd\n";
134                            } else {
135                                    open($diff_fh, '<' , $diff_file ) || die "can't read $diff_file: $!";
136                            }
137    
138                            my $diff_path;
139    
140                            while( <$diff_fh> ) {
141                                    $e->{diff} .= $_ if $self->include_diff;
142                                    print $diff_out $_ if defined $diff_out;
143    
144                                    if ( m{^\+\+\+ (\S+)} ) {
145                                            $diff_path = "/$1"; # subversion paths start with /
146                                    } elsif ( m{^\+} && $diff_path ) {
147                                            $e->{diff_paths}->{$diff_path}->{added}++;
148                                    } elsif ( m{^-} && $diff_path ) {
149                                            $e->{diff_paths}->{$diff_path}->{removed}++;
150                                    }
151                            }
152                    }
153    
154                  $coderef->($e);                  $coderef->($e);
155          }          }
156  }  }
# Line 157  sub as_markup { Line 211  sub as_markup {
211                  del { color: #c88 }                  del { color: #c88 }
212          |);          |);
213    
214            my $max_path_len = 0;
215            my $path_count;
216    
217          $self->iterator( sub {          $self->iterator( sub {
218                  my $e = shift;                  my $e = shift;
219    
# Line 185  sub as_markup { Line 242  sub as_markup {
242                          } else {                          } else {
243                                  push @files, $path;                                  push @files, $path;
244                          }                          }
245    
246                            $max_path_len = length $path if length $path > $max_path_len;
247                            $path_count->{$path}++;
248                  }                  }
249    
250                    my $diff = $self->html_diff( $e->{diff} ) if $e->{diff};
251    
252                    $html .= $self->dump( $e->{diff_paths} );
253    
254                  $html .= qq|                  $html .= qq|
255                          <div class="commit">                          <div class="commit">
256                                  <span class="date">$date</span>                                  <span class="date">$date</span>
# Line 196  sub as_markup { Line 260  sub as_markup {
260                                  |                                  |
261                                  . join("<br>\n",                                  . join("<br>\n",
262                                          map {                                          map {
263                                                  qq|<a href="?repository=$repository;path=$_">$_</a>|                                                  my $path = $_;
264                                                    $path =~ s{<[^>]+>}{}g;
265                                                    qq|<a href="?repository=$repository;path=$path" title="$path ##">$_</a>|
266                                          } @files                                          } @files
267                                  )                                  )
268                                  . qq|                                  . qq|
269                                  </div>                                  </div>
270                                  $msg                                  $msg
271                                    $diff
272                          </div>                          </div>
273                  |;                  |;
274    
275          });          });
276    
277            $self->add_css(qq|
278                    .files {
279                            width: ${max_path_len}ex;
280                    }
281            |);
282    
283            $html =~ s[title="(\S+) ##"]['title="' . $path_count->{$1} . '"']gse;
284    
285          return $html;          return $html;
286  }  }
287    
# Line 226  sub codeswarm_as_markup { Line 301  sub codeswarm_as_markup {
301    
302                  foreach my $p (@{$e->{'paths'}->{'path'}}) {                  foreach my $p (@{$e->{'paths'}->{'path'}}) {
303                          my ($action,$path) = ($p->{'action'},$p->{'content'});                          my ($action,$path) = ($p->{'action'},$p->{'content'});
304                          $file_events .= qq|\t<event filename="$path" date="$date" author="$author" />\n|;                          my $weight = '';
305                            if ( my $s = $e->{diff_paths}->{$path} ) {
306                                    $weight  = $s->{removed}   if $s->{removed};
307                                    $weight += $s->{added} * 2 if $s->{added};
308                                    $weight  = qq| weight="$weight" |;
309                            }
310                            $file_events .= qq|\t<event filename="$path" date="$date" author="$author"$weight/>\n|;
311                  }                  }
312    
313          });          });

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

  ViewVC Help
Powered by ViewVC 1.1.26