/[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 769 by dpavlin, Tue Dec 9 20:31:31 2008 UTC revision 1070 by dpavlin, Mon Apr 27 21:06:40 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;
16    use Text::Diff::Parser;
17    use File::Path qw/mkpath/;
18    
19  has repository => (  has repository => (
20          is => 'rw',          is => 'rw',
# Line 19  has repository => ( Line 23  has repository => (
23          default => 'file:///home/dpavlin/private/svn/Frey',          default => 'file:///home/dpavlin/private/svn/Frey',
24  );  );
25    
26  sub as_markup {  has path => (
27          my ($self) = @_;          is => 'rw',
28            isa => 'Str'
29    );
30    
31          # extract svk revision: r113@athlon (orig r999): dpavlin | 2005-09-01 20:38:07 +0200  has limit => (
32          my $svk_rev_re = '\s+(r\d+@\w+(\s+\(orig\s+r\d+\))*:\s+\w+\s+\|\s+\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}\s+\+\d+)\s*';          is => 'rw',
33            isa => 'Int',
34            default => 50,
35    );
36    
37          sub encode {  has include_diff => (
38                  my $foo = shift;          is => 'ro',
39                  $foo =~ s/$svk_rev_re//gsm;          isa => 'Bool',
40                  $foo =~ s/</&lt;/g;          default => 0,
41                  $foo =~ s/>/&gt;/g;  );
42                  $foo =~ s/"/&quot;/g;  
43                  $foo =~ s/([\n\r][\n\r]+)/<\/p>$1<p>/gis;  has file_stats => (
44                  $foo =~ s/([\n\r]+)([\-\*]\s+)/$1<br\/>$2/gis;          is => 'ro',
45                  $foo =~ s/([\n\r]+)(r\d+:\s+)/$1<br\/>$2/gis;          isa => 'Bool',
46                  $foo =~ s/([\n\r]+)(\s+r\d+@)/$1<br\/>$2/gis;           # svk          default => 1,
47                  return $foo;  );
         }  
48    
49    sub iterator {
50            my ($self,$coderef) = @_;
51            
52          sub sh_regex($$) {          sub sh_regex($$) {
53                  my ($cmd,$regex) = @_;                  my ($cmd,$regex) = @_;
54                  open(my $sh, $cmd . ' |') || die "sh_regex failed on $cmd: $!";                  open(my $sh, $cmd . ' |') || die "sh_regex failed on $cmd: $!";
# Line 57  sub as_markup { Line 68  sub as_markup {
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 87  sub as_markup { Line 100  sub as_markup {
100                  $cmd = "svn log -v --xml $svn_path";                  $cmd = "svn log -v --xml $svn_path";
101          }          }
102    
103            $cmd .= " --limit " . $self->limit if $self->limit;
104    
105          warn "# $cmd\n";          warn "# $cmd\n";
106          open(my $fh, $cmd .' |') || die "failed $cmd: $!";          open(my $fh, $cmd .' |') || die "failed $cmd: $!";
107          my $log;          my $log;
# Line 97  sub as_markup { Line 112  sub as_markup {
112    
113          my $xml = XMLin($log, ForceArray => [ 'logentry', 'path' ]);          my $xml = XMLin($log, ForceArray => [ 'logentry', 'path' ]);
114    
115          our $html = '';          foreach my $e (@{$xml->{'logentry'}}) {
116          sub html {                  warn "# e = ",$self->dump( $e ) if $self->debug;
117                  $html .= join("\n", @_);  
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);
158          }          }
159    }
160    
161    sub as_markup {
162            my ($self) = @_;
163    
164            # extract svk revision: r113@athlon (orig r999): dpavlin | 2005-09-01 20:38:07 +0200
165            our $svk_rev_re = '\s+(r\d+@\w+(\s+\(orig\s+r\d+\))*:\s+\w+\s+\|\s+\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}\s+\+\d+)\s*';
166    
167            sub encode {
168                    my $foo = shift;
169                    $foo =~ s/$svk_rev_re//gsm;
170                    $foo =~ s/</&lt;/g;
171                    $foo =~ s/>/&gt;/g;
172                    $foo =~ s/"/&quot;/g;
173    #               $foo =~ s/([\n\r][\n\r]+)/$1<br\/>/gis;
174                    $foo =~ s/([\n\r]+)([\-\*]\s+)/$1<br\/>$2/gis;
175                    $foo =~ s/([\n\r]+)(r\d+:\s+)/$1<br\/>$2/gis;
176                    $foo =~ s/([\n\r]+)(\s+r\d+@)/$1<br\/>$2/gis;           # svk
177                    return $foo;
178            }
179    
180            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|
189                    .commit {
190                            clear: both;
191                            padding-top: 1em;
192                            padding-bottom: 1em;
193                            border-top: 1px dashed #ccc;
194                    }
195                    .files {
196                            color: #888;
197                            font-family: monospace;
198                            font-size: 80%;
199                            float: right;
200                            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; }
207                    .message {
208                            padding-top: 0.5em;
209                            padding-left: 2em; /* like blockquote */
210                            white-space: pre-wrap;
211                    }
212    
213                    ins { color: #8c8 }
214                    del { color: #c88 }
215            |);
216    
217            my $max_path_len = 0;
218            my $path_count;
219    
220            $self->iterator( sub {
221                    my $e = shift;
222    
         foreach my $e (@{$xml->{'logentry'}}) {  
223                  my $rev = $e->{'revision'};                  my $rev = $e->{'revision'};
224                  my $date = $e->{'date'};                  my $date = $e->{'date'};
225    
226                  $date =~ s/T/ /;                  $date =~ s/T/ /;
227                  $date =~ s/\.\d+Z$//;                  $date =~ s/\.\d+Z$//;
228    
229                  html '<p><tt>'.$date.'</tt> <em>',$e->{'author'},'</em> <tt style="color:#808080">r',$e->{'revision'},'</tt></p>';                  my $msg = $e->{'msg'};
230                    $msg = '' if ref($msg); # FIXME why do I need this, dammit?
231                    if ( $msg ) {
232                            $msg = encode( $msg );
233                            $msg = qq|<div class="message">$msg</div>|;
234                    }
235    
236                  my @files;                  my @files;
237    
# Line 120  sub as_markup { Line 242  sub as_markup {
242                                  push @files, "<ins>$path</ins>";                                  push @files, "<ins>$path</ins>";
243                          } elsif ($action eq "D") {                          } elsif ($action eq "D") {
244                                  push @files, "<del>$path</del>";                                  push @files, "<del>$path</del>";
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                  html '<blockquote><p><tt style="color:#808080">',join(", ",@files),':</tt> ',encode($e->{'msg'}),'</p></blockquote>';                  my $diff = $self->html_diff( $e->{diff} ) if $e->{diff};
254    
255          }                  $html .= $self->dump( $e->{diff_paths} );
256    
257                    $html .= qq|
258                            <div class="commit">
259                                    <span class="date">$date</span>
260                                    <em>$e->{author}</em>
261                                    <span class="revision">$e->{revision}</span>
262                                    <div class="files">\n
263                                    |
264                                    . join("<br>\n",
265                                            map {
266                                                    my $path = $_;
267                                                    $path =~ s{<[^>]+>}{}g;
268                                                    qq|<a href="?repository=$repository;path=$path" title="$path ##">$_</a>|
269                                            } @files
270                                    )
271                                    . qq|
272                                    </div>
273                                    $msg
274                                    $diff
275                            </div>
276                    |;
277    
278            });
279    
280            $self->add_css(qq|
281                    .files {
282                            width: ${max_path_len}ex;
283                    }
284            |);
285    
286            $html =~ s[title="(\S+) ##"]['title="' . $path_count->{$1} . '"']gse;
287    
288          return $html;          return $html;
289  }  }
290    
291    sub codeswarm_as_markup {
292            my ($self) = @_;
293    
294            $self->content_type('text/xml');
295    
296            my $file_events = '';
297    
298            $self->iterator( sub {
299                    my $e = shift;
300                    
301                    my $rev = $e->{'revision'};
302                    my $date = DateTimeX::Easy->new( $e->{'date'} )->epoch . '000'; # ms
303                    my $author = $e->{'author'};
304    
305                    foreach my $p (@{$e->{'paths'}->{'path'}}) {
306                            my ($action,$path) = ($p->{'action'},$p->{'content'});
307                            my $weight = '';
308                            if ( my $s = $e->{diff_paths}->{$path} ) {
309    
310                                    warn $self->dump( $s );
311                                    $weight  = $s->{removed}   if defined $s->{removed};
312                                    $weight += $s->{added} * 2 if defined $s->{added};
313                                    $weight  = qq| weight="$weight" |;
314                            }
315                            $file_events .= qq|\t<event filename="$path" date="$date" author="$author"$weight/>\n|;
316                    }
317    
318            });
319    
320            return qq|<?xml version="1.0"?>
321            <!-- One commit per day for one month by a documenter and programmer. -->
322            <file_events>
323            $file_events
324            </file_events>
325            |;
326    
327    }
328    
329  1;  1;

Legend:
Removed from v.769  
changed lines
  Added in v.1070

  ViewVC Help
Powered by ViewVC 1.1.26