/[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 851 by dpavlin, Mon Dec 15 20:10:48 2008 UTC revision 1066 by dpavlin, Mon Apr 27 18:45:14 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    
18  has repository => (  has repository => (
19          is => 'rw',          is => 'rw',
# Line 20  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    has include_diff => (
37            is => 'ro',
38            isa => 'Bool',
39            default => 1,
40    );
41    
42  sub iterator {  sub iterator {
43          my ($self,$coderef) = @_;          my ($self,$coderef) = @_;
44                    
# Line 48  sub iterator { Line 61  sub iterator {
61                  return;                  return;
62          }          }
63    
64          my $path = $self->repository;          my $path = $self->repository . $self->path;
65          warn "# path $path\n";          warn "# path $path\n";
66    
67          my $cmd;          my $cmd;
68            my $svn_path = $path;
69    
70          if ($path =~ m#file://# || -e "$path/.svn") {          if ($path =~ m#file://# || -e "$path/.svn") {
71                  $cmd = "svn log -v --xml $path";                  $cmd = "svn log -v --xml $path";
72          } else {          } else {
73                  my $svn_path = sh_regex('svk info', qr#Mirrored From:\s+([^,]+)#i);                  $svn_path = sh_regex('svk info', qr#Mirrored From:\s+([^,]+)#i);
74    
75                  if (! $svn_path) {                  if (! $svn_path) {
76    
# Line 91  sub iterator { Line 106  sub iterator {
106          my $xml = XMLin($log, ForceArray => [ 'logentry', 'path' ]);          my $xml = XMLin($log, ForceArray => [ 'logentry', 'path' ]);
107    
108          foreach my $e (@{$xml->{'logentry'}}) {          foreach my $e (@{$xml->{'logentry'}}) {
109                  warn "# e = ",$self->dump( $e );                  warn "# e = ",$self->dump( $e ) if $self->debug;
110    
111                    if ( $self->include_diff ) {
112                            my $rev = $e->{'revision'};
113                            my $file = $svn_path;
114                            $file =~ s{^\w+:/+}{};
115                            my $file = "var/svn/$path.diff";
116                            my $diff = $self->load( $file );
117                            if ( ! $diff ) {
118                                    $diff = `svn diff -c $rev $svn_path`;
119                                    $self->store( $file, $diff );
120                            }
121                            $e->{diff} .= $diff;
122                    }
123    
124                  $coderef->($e);                  $coderef->($e);
125          }          }
126  }  }
# Line 108  sub as_markup { Line 137  sub as_markup {
137                  $foo =~ s/</&lt;/g;                  $foo =~ s/</&lt;/g;
138                  $foo =~ s/>/&gt;/g;                  $foo =~ s/>/&gt;/g;
139                  $foo =~ s/"/&quot;/g;                  $foo =~ s/"/&quot;/g;
140                  $foo =~ s/([\n\r][\n\r]+)/<\/p>$1<p>/gis;  #               $foo =~ s/([\n\r][\n\r]+)/$1<br\/>/gis;
141                  $foo =~ s/([\n\r]+)([\-\*]\s+)/$1<br\/>$2/gis;                  $foo =~ s/([\n\r]+)([\-\*]\s+)/$1<br\/>$2/gis;
142                  $foo =~ s/([\n\r]+)(r\d+:\s+)/$1<br\/>$2/gis;                  $foo =~ s/([\n\r]+)(r\d+:\s+)/$1<br\/>$2/gis;
143                  $foo =~ s/([\n\r]+)(\s+r\d+@)/$1<br\/>$2/gis;           # svk                  $foo =~ s/([\n\r]+)(\s+r\d+@)/$1<br\/>$2/gis;           # svk
144                  return $foo;                  return $foo;
145          }          }
146    
147          our $html = '';          my $repository = $self->repository;
148          sub html {          my $path = $self->path;
149                  $html .= join("\n", @_);  
150          }          our $html = qq|
151                    <h1><a href="?repository=$repository">$repository</a></h1>
152                    <h2>$path</h2>
153            |;
154    
155            $self->add_css(qq|
156                    .commit {
157                            clear: both;
158                            padding-top: 1em;
159                            padding-bottom: 1em;
160                            border-top: 1px dashed #ccc;
161                    }
162                    .files {
163                            color: #888;
164                            font-family: monospace;
165                            font-size: 80%;
166                            float: right;
167                            padding-bottom: 1.2em; /* fix 80% back to original 1em */
168                    }
169                    .files a {
170                            text-decoration: none;
171                            color: #888;
172                    }
173                    .date, .revision { color: #666; }
174                    .message {
175                            padding-top: 0.5em;
176                            padding-left: 2em; /* like blockquote */
177                            white-space: pre-wrap;
178                    }
179    
180                    ins { color: #8c8 }
181                    del { color: #c88 }
182            |);
183    
184            my $max_path_len = 0;
185            my $path_count;
186    
187          $self->iterator( sub {          $self->iterator( sub {
188                  my $e = shift;                  my $e = shift;
# Line 129  sub as_markup { Line 193  sub as_markup {
193                  $date =~ s/T/ /;                  $date =~ s/T/ /;
194                  $date =~ s/\.\d+Z$//;                  $date =~ s/\.\d+Z$//;
195    
196                  html '<p><tt>'.$date.'</tt> <em>',$e->{'author'},'</em> <tt style="color:#808080">r',$e->{'revision'},'</tt></p>';                  my $msg = $e->{'msg'};
197                    $msg = '' if ref($msg); # FIXME why do I need this, dammit?
198                    if ( $msg ) {
199                            $msg = encode( $msg );
200                            $msg = qq|<div class="message">$msg</div>|;
201                    }
202    
203                  my @files;                  my @files;
204    
# Line 143  sub as_markup { Line 212  sub as_markup {
212                          } else {                          } else {
213                                  push @files, $path;                                  push @files, $path;
214                          }                          }
215    
216                            $max_path_len = length $path if length $path > $max_path_len;
217                            $path_count->{$path}++;
218                  }                  }
219    
220                  my $msg = $e->{'msg'};                  my $diff = $self->html_diff( $e->{diff} ) if $e->{diff};
                 $msg = '' if ref($msg); # FIXME why do I need this, dammit?  
                 $msg = encode( $msg );  
221    
222                  html '<blockquote><p><tt style="color:#808080">',join(", ",@files),'</tt> ',$msg,'</p></blockquote>';                  $html .= qq|
223                            <div class="commit">
224                                    <span class="date">$date</span>
225                                    <em>$e->{author}</em>
226                                    <span class="revision">$e->{revision}</span>
227                                    <div class="files">\n
228                                    |
229                                    . join("<br>\n",
230                                            map {
231                                                    my $path = $_;
232                                                    $path =~ s{<[^>]+>}{}g;
233                                                    qq|<a href="?repository=$repository;path=$path" title="$path ##">$_</a>|
234                                            } @files
235                                    )
236                                    . qq|
237                                    </div>
238                                    $msg
239                                    $diff
240                            </div>
241                    |;
242    
243          });          });
244    
245            $self->add_css(qq|
246                    .files {
247                            width: ${max_path_len}ex;
248                    }
249            |);
250    
251            $html =~ s[title="(\S+) ##"]['title="' . $path_count->{$1} . '"']gse;
252    
253          return $html;          return $html;
254  }  }
255    

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

  ViewVC Help
Powered by ViewVC 1.1.26