/[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 979 by dpavlin, Fri Jan 9 23:26:25 2009 UTC revision 1072 by dpavlin, Tue Apr 28 17:04:24 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 20  has repository => ( Line 23  has repository => (
23          default => 'file:///home/dpavlin/private/svn/Frey',          default => 'file:///home/dpavlin/private/svn/Frey',
24  );  );
25    
26    has path => (
27            is => 'rw',
28            isa => 'Str'
29    );
30    
31  has limit => (  has limit => (
32          is => 'rw',          is => 'rw',
33          isa => 'Int',          isa => 'Int',
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 48  sub iterator { Line 68  sub iterator {
68                  return;                  return;
69          }          }
70    
71          my $path = $self->repository;          my $path = $self->repository . $self->path;
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 92  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 $cache = $svn_path;
124                            $cache =~ s{^\w+:/+}{};
125                            $cache = "var/svn/$cache";
126                            mkpath $cache unless -e $cache;
127                            my $diff_paths = $self->load( "$cache/$rev.yaml" );
128                            if ( ! $diff_paths ) {
129                                    my $cmd = "svn diff -c $rev $svn_path";
130                                    my ( $diff_fh, $diff_out );
131                                    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";
136    
137                                    my $diff_path;
138    
139                                    while( <$diff_fh> ) {
140                                            print $diff_out $_;
141    
142                                            if ( m{^\+\+\+ (\S+)} ) {
143                                                    $diff_path = "/$1"; # subversion paths start with /
144                                            } elsif ( m{^\+} && $diff_path ) {
145                                                    $diff_paths->{$diff_path}->{added}++;
146                                            } elsif ( m{^-} && $diff_path ) {
147                                                    $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);
158          }          }
159  }  }
# Line 115  sub as_markup { Line 177  sub as_markup {
177                  return $foo;                  return $foo;
178          }          }
179    
180          our $html = qq|<h1>| . $self->repository . qq|</h1>|;          my $repository = $self->repository;
181            my $path = $self->path;
182    
183            our $html = qq|
184                    <h1><a href="?repository=$repository">$repository</a></h1>
185                    <h2>$path</h2>
186            |;
187    
188          $self->add_css(qq|          $self->add_css(qq|
189                  .commit {                  .commit {
# Line 131  sub as_markup { Line 199  sub as_markup {
199                          float: right;                          float: right;
200                          padding-bottom: 1.2em; /* fix 80% back to original 1em */                          padding-bottom: 1.2em; /* fix 80% back to original 1em */
201                  }                  }
202                    .files a {
203                            text-decoration: none;
204                            color: #888;
205                    }
206                  .date, .revision { color: #666; }                  .date, .revision { color: #666; }
207                  .message {                  .message {
208                          padding-top: 0.5em;                          padding-top: 0.5em;
# Line 142  sub as_markup { Line 214  sub as_markup {
214                  del { color: #c88 }                  del { color: #c88 }
215          |);          |);
216    
217            my $max_path_len = 0;
218            my $path_count;
219    
220          $self->iterator( sub {          $self->iterator( sub {
221                  my $e = shift;                  my $e = shift;
222    
# Line 170  sub as_markup { Line 245  sub as_markup {
245                          } else {                          } else {
246                                  push @files, $path;                                  push @files, $path;
247                          }                          }
248    
249                            $max_path_len = length $path if length $path > $max_path_len;
250                            $path_count->{$path}++;
251                  }                  }
252    
253                    my $diff = $self->html_diff( $e->{diff} ) if $e->{diff};
254    
255                    $self->add_css(qq|
256                            .diff-lines {
257                                    margin-left: 1em;
258                                    float: right;
259                            }
260                    |);
261    
262                  $html .= qq|                  $html .= qq|
263                          <div class="commit">                          <div class="commit">
264                          <span class="date">$date</span>                                  <span class="date">$date</span>
265                          <em>$e->{author}</em>                                  <em>$e->{author}</em>
266                          <span class="revision">$e->{revision}</span>                                  <span class="revision">$e->{revision}</span>
267                          <div class="files">\n| . join("<br>\n",@files) . qq|\n</div>                                  <div class="files">\n
268                          $msg                                  |
269                                    . join("<br>\n",
270                                            map {
271                                                    my $path = $_;
272                                                    $path =~ s{<[^>]+>}{}g;
273                                                    my $diff = '';
274                                                    if ( $diff = $e->{diff_paths}->{$path} ) {
275                                                            $diff
276                                                            = qq|<span class="diff-lines">|
277                                                            . join(" ",
278                                                                    map {
279                                                                            my $v = $diff->{$_};
280                                                                            s[added][+$v];
281                                                                            s[removed][-$v];
282                                                                            $_;
283                                                                    } keys %$diff
284                                                            )
285                                                            . qq|</span>|
286                                                            ;
287                                                            warn "DIFF $diff";
288                                                    }
289    
290                                                    qq|$diff<a href="?repository=$repository;path=$path" title="$path ##">$_</a>|
291                                            } @files
292                                    )
293                                    . qq|
294                                    </div>
295                                    $msg
296                                    $diff
297                          </div>                          </div>
298                  |;                  |;
299    
300          });          });
301    
302            $self->add_css(qq|
303                    .files {
304                            width: ${max_path_len}ex;
305                    }
306            |);
307    
308            $html =~ s[title="(\S+) ##"]['title="' . $path_count->{$1} . '"']gse;
309    
310          return $html;          return $html;
311  }  }
312    
# Line 203  sub codeswarm_as_markup { Line 326  sub codeswarm_as_markup {
326    
327                  foreach my $p (@{$e->{'paths'}->{'path'}}) {                  foreach my $p (@{$e->{'paths'}->{'path'}}) {
328                          my ($action,$path) = ($p->{'action'},$p->{'content'});                          my ($action,$path) = ($p->{'action'},$p->{'content'});
329                          $file_events .= qq|\t<event filename="$path" date="$date" author="$author" />\n|;                          my $weight = '';
330                            if ( my $s = $e->{diff_paths}->{$path} ) {
331    
332                                    warn $self->dump( $s );
333                                    $weight  = $s->{removed}   if defined $s->{removed};
334                                    $weight += $s->{added} * 2 if defined $s->{added};
335                                    $weight  = qq| weight="$weight" |;
336                            }
337                            $file_events .= qq|\t<event filename="$path" date="$date" author="$author"$weight/>\n|;
338                  }                  }
339    
340          });          });

Legend:
Removed from v.979  
changed lines
  Added in v.1072

  ViewVC Help
Powered by ViewVC 1.1.26