/[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 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;
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  sub as_markup {  has path => (
26          my ($self) = @_;          is => 'rw',
27            isa => 'Str'
28    );
29    
30          # extract svk revision: r113@athlon (orig r999): dpavlin | 2005-09-01 20:38:07 +0200  has limit => (
31          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',
32            isa => 'Int',
33            default => 50,
34    );
35    
36          sub encode {  has include_diff => (
37                  my $foo = shift;          is => 'ro',
38                  $foo =~ s/$svk_rev_re//gsm;          isa => 'Bool',
39                  $foo =~ s/</&lt;/g;          default => 1,
40                  $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;  
         }  
41    
42    sub iterator {
43            my ($self,$coderef) = @_;
44            
45          sub sh_regex($$) {          sub sh_regex($$) {
46                  my ($cmd,$regex) = @_;                  my ($cmd,$regex) = @_;
47                  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 61  sub as_markup {
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 87  sub as_markup { Line 93  sub as_markup {
93                  $cmd = "svn log -v --xml $svn_path";                  $cmd = "svn log -v --xml $svn_path";
94          }          }
95    
96            $cmd .= " --limit " . $self->limit if $self->limit;
97    
98          warn "# $cmd\n";          warn "# $cmd\n";
99          open(my $fh, $cmd .' |') || die "failed $cmd: $!";          open(my $fh, $cmd .' |') || die "failed $cmd: $!";
100          my $log;          my $log;
# Line 97  sub as_markup { Line 105  sub as_markup {
105    
106          my $xml = XMLin($log, ForceArray => [ 'logentry', 'path' ]);          my $xml = XMLin($log, ForceArray => [ 'logentry', 'path' ]);
107    
108          our $html = '';          foreach my $e (@{$xml->{'logentry'}}) {
109          sub html {                  warn "# e = ",$self->dump( $e ) if $self->debug;
110                  $html .= join("\n", @_);  
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);
125          }          }
126    }
127    
128    sub as_markup {
129            my ($self) = @_;
130    
131            # extract svk revision: r113@athlon (orig r999): dpavlin | 2005-09-01 20:38:07 +0200
132            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*';
133    
134            sub encode {
135                    my $foo = shift;
136                    $foo =~ s/$svk_rev_re//gsm;
137                    $foo =~ s/</&lt;/g;
138                    $foo =~ s/>/&gt;/g;
139                    $foo =~ s/"/&quot;/g;
140    #               $foo =~ s/([\n\r][\n\r]+)/$1<br\/>/gis;
141                    $foo =~ s/([\n\r]+)([\-\*]\s+)/$1<br\/>$2/gis;
142                    $foo =~ s/([\n\r]+)(r\d+:\s+)/$1<br\/>$2/gis;
143                    $foo =~ s/([\n\r]+)(\s+r\d+@)/$1<br\/>$2/gis;           # svk
144                    return $foo;
145            }
146    
147            my $repository = $self->repository;
148            my $path = $self->path;
149    
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 {
188                    my $e = shift;
189    
         foreach my $e (@{$xml->{'logentry'}}) {  
190                  my $rev = $e->{'revision'};                  my $rev = $e->{'revision'};
191                  my $date = $e->{'date'};                  my $date = $e->{'date'};
192    
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 120  sub as_markup { Line 209  sub as_markup {
209                                  push @files, "<ins>$path</ins>";                                  push @files, "<ins>$path</ins>";
210                          } elsif ($action eq "D") {                          } elsif ($action eq "D") {
211                                  push @files, "<del>$path</del>";                                  push @files, "<del>$path</del>";
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                  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};
221    
222          }                  $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    
256    sub codeswarm_as_markup {
257            my ($self) = @_;
258    
259            $self->content_type('text/xml');
260    
261            my $file_events = '';
262    
263            $self->iterator( sub {
264                    my $e = shift;
265                    
266                    my $rev = $e->{'revision'};
267                    my $date = DateTimeX::Easy->new( $e->{'date'} )->epoch . '000'; # ms
268                    my $author = $e->{'author'};
269    
270                    foreach my $p (@{$e->{'paths'}->{'path'}}) {
271                            my ($action,$path) = ($p->{'action'},$p->{'content'});
272                            $file_events .= qq|\t<event filename="$path" date="$date" author="$author" />\n|;
273                    }
274    
275            });
276    
277            return qq|<?xml version="1.0"?>
278            <!-- One commit per day for one month by a documenter and programmer. -->
279            <file_events>
280            $file_events
281            </file_events>
282            |;
283    
284    }
285    
286  1;  1;

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

  ViewVC Help
Powered by ViewVC 1.1.26