/[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 770 by dpavlin, Tue Dec 9 20:31:31 2008 UTC revision 1067 by dpavlin, Mon Apr 27 19:55: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;
16    use Text::Diff::Parser;
17    
18  has repository => (  has repository => (
19          is => 'rw',          is => 'rw',
# Line 19  has repository => ( Line 22  has repository => (
22          default => 'file:///home/dpavlin/private/svn/Frey',          default => 'file:///home/dpavlin/private/svn/Frey',
23  );  );
24    
25    has path => (
26            is => 'rw',
27            isa => 'Str'
28    );
29    
30  has limit => (  has limit => (
31          is => 'rw',          is => 'rw',
32          isa => 'Int',          isa => 'Int',
33          default => 50,          default => 50,
34  );  );
35    
36  sub as_markup {  has include_diff => (
37          my ($self) = @_;          is => 'ro',
38            isa => 'Bool',
39          # extract svk revision: r113@athlon (orig r999): dpavlin | 2005-09-01 20:38:07 +0200          default => 1,
40          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*';  );
41    
42          sub encode {  has file_stats => (
43                  my $foo = shift;          is => 'ro',
44                  $foo =~ s/$svk_rev_re//gsm;          isa => 'Bool',
45                  $foo =~ s/</&lt;/g;          default => 1,
46                  $foo =~ s/>/&gt;/g;  );
                 $foo =~ s/"/&quot;/g;  
                 $foo =~ s/([\n\r][\n\r]+)/<\/p>$1<p>/gis;  
                 $foo =~ s/([\n\r]+)([\-\*]\s+)/$1<br\/>$2/gis;  
                 $foo =~ s/([\n\r]+)(r\d+:\s+)/$1<br\/>$2/gis;  
                 $foo =~ s/([\n\r]+)(\s+r\d+@)/$1<br\/>$2/gis;           # svk  
                 return $foo;  
         }  
47    
48    sub iterator {
49            my ($self,$coderef) = @_;
50            
51          sub sh_regex($$) {          sub sh_regex($$) {
52                  my ($cmd,$regex) = @_;                  my ($cmd,$regex) = @_;
53                  open(my $sh, $cmd . ' |') || die "sh_regex failed on $cmd: $!";                  open(my $sh, $cmd . ' |') || die "sh_regex failed on $cmd: $!";
# Line 63  sub as_markup { Line 67  sub as_markup {
67                  return;                  return;
68          }          }
69    
70          my $path = $self->repository;          my $path = $self->repository . $self->path;
71          warn "# path $path\n";          warn "# path $path\n";
72    
73          my $cmd;          my $cmd;
74            my $svn_path = $path;
75    
76          if ($path =~ m#file://# || -e "$path/.svn") {          if ($path =~ m#file://# || -e "$path/.svn") {
77                  $cmd = "svn log -v --xml $path";                  $cmd = "svn log -v --xml $path";
78          } else {          } else {
79                  my $svn_path = sh_regex('svk info', qr#Mirrored From:\s+([^,]+)#i);                  $svn_path = sh_regex('svk info', qr#Mirrored From:\s+([^,]+)#i);
80    
81                  if (! $svn_path) {                  if (! $svn_path) {
82    
# Line 105  sub as_markup { Line 111  sub as_markup {
111    
112          my $xml = XMLin($log, ForceArray => [ 'logentry', 'path' ]);          my $xml = XMLin($log, ForceArray => [ 'logentry', 'path' ]);
113    
114          our $html = '';          foreach my $e (@{$xml->{'logentry'}}) {
115          sub html {                  warn "# e = ",$self->dump( $e ) if $self->debug;
116                  $html .= join("\n", @_);  
117                    if ( $self->include_diff || $self->file_stats ) {
118                            my $rev = $e->{'revision'};
119                            my $file = $svn_path;
120                            $file =~ s{^\w+:/+}{};
121                            my $file = "var/svn/$file/$rev.diff";
122                            my $diff = $self->load( $file );
123                            if ( ! $diff ) {
124                                    $diff = `svn diff -c $rev $svn_path`;
125                                    $self->store( $file, $diff );
126                            }
127    
128                            $e->{diff} .= $diff if $self->include_diff;
129    
130                            $e->{diff_paths}->{rev} = $rev; # XXX debug
131    
132                            my $diff_path;
133                            foreach my $line ( split(/[\n\r]/, $diff ) ) {
134                                    if ( $line =~ m{^\+\+\+ (\S+)} ) {
135                                            $diff_path = "/$1"; # subversion paths start with /
136                                    } elsif ( $line =~ m{^\+} ) {
137                                            $e->{diff_paths}->{$diff_path}->{added}++;
138                                    } elsif ( $line =~ m{^-} ) {
139                                            $e->{diff_paths}->{$diff_path}->{removed}++;
140                                    }
141                            }
142                    }
143    
144                    $coderef->($e);
145          }          }
146    }
147    
148    sub as_markup {
149            my ($self) = @_;
150    
151            # extract svk revision: r113@athlon (orig r999): dpavlin | 2005-09-01 20:38:07 +0200
152            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*';
153    
154            sub encode {
155                    my $foo = shift;
156                    $foo =~ s/$svk_rev_re//gsm;
157                    $foo =~ s/</&lt;/g;
158                    $foo =~ s/>/&gt;/g;
159                    $foo =~ s/"/&quot;/g;
160    #               $foo =~ s/([\n\r][\n\r]+)/$1<br\/>/gis;
161                    $foo =~ s/([\n\r]+)([\-\*]\s+)/$1<br\/>$2/gis;
162                    $foo =~ s/([\n\r]+)(r\d+:\s+)/$1<br\/>$2/gis;
163                    $foo =~ s/([\n\r]+)(\s+r\d+@)/$1<br\/>$2/gis;           # svk
164                    return $foo;
165            }
166    
167            my $repository = $self->repository;
168            my $path = $self->path;
169    
170            our $html = qq|
171                    <h1><a href="?repository=$repository">$repository</a></h1>
172                    <h2>$path</h2>
173            |;
174    
175            $self->add_css(qq|
176                    .commit {
177                            clear: both;
178                            padding-top: 1em;
179                            padding-bottom: 1em;
180                            border-top: 1px dashed #ccc;
181                    }
182                    .files {
183                            color: #888;
184                            font-family: monospace;
185                            font-size: 80%;
186                            float: right;
187                            padding-bottom: 1.2em; /* fix 80% back to original 1em */
188                    }
189                    .files a {
190                            text-decoration: none;
191                            color: #888;
192                    }
193                    .date, .revision { color: #666; }
194                    .message {
195                            padding-top: 0.5em;
196                            padding-left: 2em; /* like blockquote */
197                            white-space: pre-wrap;
198                    }
199    
200                    ins { color: #8c8 }
201                    del { color: #c88 }
202            |);
203    
204            my $max_path_len = 0;
205            my $path_count;
206    
207            $self->iterator( sub {
208                    my $e = shift;
209    
         foreach my $e (@{$xml->{'logentry'}}) {  
210                  my $rev = $e->{'revision'};                  my $rev = $e->{'revision'};
211                  my $date = $e->{'date'};                  my $date = $e->{'date'};
212    
213                  $date =~ s/T/ /;                  $date =~ s/T/ /;
214                  $date =~ s/\.\d+Z$//;                  $date =~ s/\.\d+Z$//;
215    
216                  html '<p><tt>'.$date.'</tt> <em>',$e->{'author'},'</em> <tt style="color:#808080">r',$e->{'revision'},'</tt></p>';                  my $msg = $e->{'msg'};
217                    $msg = '' if ref($msg); # FIXME why do I need this, dammit?
218                    if ( $msg ) {
219                            $msg = encode( $msg );
220                            $msg = qq|<div class="message">$msg</div>|;
221                    }
222    
223                  my @files;                  my @files;
224    
# Line 128  sub as_markup { Line 229  sub as_markup {
229                                  push @files, "<ins>$path</ins>";                                  push @files, "<ins>$path</ins>";
230                          } elsif ($action eq "D") {                          } elsif ($action eq "D") {
231                                  push @files, "<del>$path</del>";                                  push @files, "<del>$path</del>";
232                          } else{                          } else {
233                                  push @files, $path;                                  push @files, $path;
234                          }                          }
235    
236                            $max_path_len = length $path if length $path > $max_path_len;
237                            $path_count->{$path}++;
238                  }                  }
239    
240                  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};
241    
242          }                  $html .= $self->dump( $e->{diff_paths} );
243    
244                    $html .= qq|
245                            <div class="commit">
246                                    <span class="date">$date</span>
247                                    <em>$e->{author}</em>
248                                    <span class="revision">$e->{revision}</span>
249                                    <div class="files">\n
250                                    |
251                                    . join("<br>\n",
252                                            map {
253                                                    my $path = $_;
254                                                    $path =~ s{<[^>]+>}{}g;
255                                                    qq|<a href="?repository=$repository;path=$path" title="$path ##">$_</a>|
256                                            } @files
257                                    )
258                                    . qq|
259                                    </div>
260                                    $msg
261                                    $diff
262                            </div>
263                    |;
264    
265            });
266    
267            $self->add_css(qq|
268                    .files {
269                            width: ${max_path_len}ex;
270                    }
271            |);
272    
273            $html =~ s[title="(\S+) ##"]['title="' . $path_count->{$1} . '"']gse;
274    
275          return $html;          return $html;
276  }  }
277    
278    sub codeswarm_as_markup {
279            my ($self) = @_;
280    
281            $self->content_type('text/xml');
282    
283            my $file_events = '';
284    
285            $self->iterator( sub {
286                    my $e = shift;
287                    
288                    my $rev = $e->{'revision'};
289                    my $date = DateTimeX::Easy->new( $e->{'date'} )->epoch . '000'; # ms
290                    my $author = $e->{'author'};
291    
292                    foreach my $p (@{$e->{'paths'}->{'path'}}) {
293                            my ($action,$path) = ($p->{'action'},$p->{'content'});
294                            my $weight = '';
295                            if ( defined   $e->{diff_paths}->{$path} ) {
296                                    $weight  = $e->{diff_paths}->{$path}->{removed};
297                                    $weight += $e->{diff_paths}->{$path}->{added} * 2;
298                                    $weight  = qq| weight="$weight" |;
299                            }
300                            $file_events .= qq|\t<event filename="$path" date="$date" author="$author"$weight/>\n|;
301                    }
302    
303            });
304    
305            return qq|<?xml version="1.0"?>
306            <!-- One commit per day for one month by a documenter and programmer. -->
307            <file_events>
308            $file_events
309            </file_events>
310            |;
311    
312    }
313    
314  1;  1;

Legend:
Removed from v.770  
changed lines
  Added in v.1067

  ViewVC Help
Powered by ViewVC 1.1.26