/[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 851 by dpavlin, Mon Dec 15 20:10:48 2008 UTC revision 1078 by dpavlin, Thu Jun 4 19:23:32 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 88  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'}}) {
118                  warn "# e = ",$self->dump( $e );                  warn "# e = ",$self->dump( $e ) if $self->debug;
119    
120                    if ( $self->include_diff || $self->file_stats ) {
121                            my $rev = $e->{'revision'};
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 $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);
172          }          }
173  }  }
# Line 108  sub as_markup { Line 184  sub as_markup {
184                  $foo =~ s/</&lt;/g;                  $foo =~ s/</&lt;/g;
185                  $foo =~ s/>/&gt;/g;                  $foo =~ s/>/&gt;/g;
186                  $foo =~ s/"/&quot;/g;                  $foo =~ s/"/&quot;/g;
187                  $foo =~ s/([\n\r][\n\r]+)/<\/p>$1<p>/gis;  #               $foo =~ s/([\n\r][\n\r]+)/$1<br\/>/gis;
188                  $foo =~ s/([\n\r]+)([\-\*]\s+)/$1<br\/>$2/gis;                  $foo =~ s/([\n\r]+)([\-\*]\s+)/$1<br\/>$2/gis;
189                  $foo =~ s/([\n\r]+)(r\d+:\s+)/$1<br\/>$2/gis;                  $foo =~ s/([\n\r]+)(r\d+:\s+)/$1<br\/>$2/gis;
190                  $foo =~ s/([\n\r]+)(\s+r\d+@)/$1<br\/>$2/gis;           # svk                  $foo =~ s/([\n\r]+)(\s+r\d+@)/$1<br\/>$2/gis;           # svk
191                  return $foo;                  return $foo;
192          }          }
193    
194          our $html = '';          my $repository = $self->repository;
195          sub html {          my $path = $self->path;
196                  $html .= join("\n", @_);  
197          }          our $html = qq|
198                    <h1><a href="?repository=$repository">$repository</a></h1>
199                    <h2>$path</h2>
200            |;
201    
202            $self->add_css(qq|
203                    .commit {
204                            clear: both;
205                            padding-top: 1em;
206                            padding-bottom: 1em;
207                            border-top: 1px dashed #ccc;
208                    }
209                    .files {
210                            color: #888;
211                            font-family: monospace;
212                            font-size: 80%;
213                            float: right;
214                            padding-bottom: 1.2em; /* fix 80% back to original 1em */
215                    }
216                    .files a {
217                            text-decoration: none;
218                            color: #888;
219                    }
220                    .date, .revision { color: #666; }
221                    .message {
222                            padding-top: 0.5em;
223                            padding-left: 2em; /* like blockquote */
224                            white-space: pre-wrap;
225                    }
226    
227                    ins { color: #8c8 }
228                    del { color: #c88 }
229            |);
230    
231            my $max_path_len = 0;
232            my $path_count;
233            my $stats;
234    
235          $self->iterator( sub {          $self->iterator( sub {
236                  my $e = shift;                  my $e = shift;
# Line 129  sub as_markup { Line 241  sub as_markup {
241                  $date =~ s/T/ /;                  $date =~ s/T/ /;
242                  $date =~ s/\.\d+Z$//;                  $date =~ s/\.\d+Z$//;
243    
244                  html '<p><tt>'.$date.'</tt> <em>',$e->{'author'},'</em> <tt style="color:#808080">r',$e->{'revision'},'</tt></p>';                  my $msg = $e->{'msg'};
245                    $msg = '' if ref($msg); # FIXME why do I need this, dammit?
246                    if ( $msg ) {
247                            $msg = encode( $msg );
248                            $msg = qq|<div class="message">$msg</div>|;
249                    }
250    
251                  my @files;                  my @files;
252    
# Line 143  sub as_markup { Line 260  sub as_markup {
260                          } else {                          } else {
261                                  push @files, $path;                                  push @files, $path;
262                          }                          }
263    
264                            $max_path_len = length $path if length $path > $max_path_len;
265                            $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 $msg = $e->{'msg'};                  my $diff = $self->html_diff( $e->{diff} ) if $e->{diff};
277                  $msg = '' if ref($msg); # FIXME why do I need this, dammit?  
278                  $msg = encode( $msg );                  $self->add_css(qq|
279                            .diff-lines {
280                                    margin-left: 1em;
281                                    float: right;
282                            }
283                    |);
284    
285                  html '<blockquote><p><tt style="color:#808080">',join(", ",@files),'</tt> ',$msg,'</p></blockquote>';                  $html .= qq|
286                            <div class="commit">
287                                    <span class="date">$date</span>
288                                    <em>$e->{author}</em>
289                                    <span class="revision">$e->{revision}</span>
290                                    <div class="files">\n
291                                    |
292                                    . join("<br>\n",
293                                            map {
294                                                    my $path = $_;
295                                                    $path =~ s{<[^>]+>}{}g;
296                                                    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
315                                    )
316                                    . qq|
317                                    </div>
318                                    $msg
319                                    $diff
320                            </div>
321                    |;
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|
333                    .files {
334                            width: ${max_path_len}ex;
335                    }
336            |);
337    
338            $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 172  sub codeswarm_as_markup { Line 358  sub codeswarm_as_markup {
358    
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                          $file_events .= qq|\t<event filename="$path" date="$date" author="$author" />\n|;                          my $weight = '';
362                            if ( my $s = $e->{diff_paths}->{$path} ) {
363                                    $weight  = $s->{removed} || 0;
364                                    $weight += $s->{added} * 2 if $s->{added};
365                                    $weight  = qq| weight="$weight" |;
366                            }
367                            $file_events .= qq|\t<event filename="$path" date="$date" author="$author"$weight/>\n|;
368                  }                  }
369    
370          });          });

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

  ViewVC Help
Powered by ViewVC 1.1.26