/[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 770 by dpavlin, Tue Dec 9 20:31:31 2008 UTC revision 987 by dpavlin, Sat Jan 10 21:42:00 2009 UTC
# Line 11  with 'Frey::Web'; Line 11  with 'Frey::Web';
11  #with 'Frey::Storage';  #with 'Frey::Storage';
12    
13  use XML::Simple;  use XML::Simple;
14    use DateTimeX::Easy;
15    
16  has repository => (  has repository => (
17          is => 'rw',          is => 'rw',
# Line 19  has repository => ( Line 20  has repository => (
20          default => 'file:///home/dpavlin/private/svn/Frey',          default => 'file:///home/dpavlin/private/svn/Frey',
21  );  );
22    
23    has path => (
24            is => 'rw',
25            isa => 'Str'
26    );
27    
28  has limit => (  has limit => (
29          is => 'rw',          is => 'rw',
30          isa => 'Int',          isa => 'Int',
31          default => 50,          default => 50,
32  );  );
33    
34  sub as_markup {  sub iterator {
35          my ($self) = @_;          my ($self,$coderef) = @_;
36            
         # extract svk revision: r113@athlon (orig r999): dpavlin | 2005-09-01 20:38:07 +0200  
         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*';  
   
         sub encode {  
                 my $foo = shift;  
                 $foo =~ s/$svk_rev_re//gsm;  
                 $foo =~ s/</&lt;/g;  
                 $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;  
         }  
   
37          sub sh_regex($$) {          sub sh_regex($$) {
38                  my ($cmd,$regex) = @_;                  my ($cmd,$regex) = @_;
39                  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 53  sub as_markup {
53                  return;                  return;
54          }          }
55    
56          my $path = $self->repository;          my $path = $self->repository . $self->path;
57          warn "# path $path\n";          warn "# path $path\n";
58    
59          my $cmd;          my $cmd;
# Line 105  sub as_markup { Line 95  sub as_markup {
95    
96          my $xml = XMLin($log, ForceArray => [ 'logentry', 'path' ]);          my $xml = XMLin($log, ForceArray => [ 'logentry', 'path' ]);
97    
98          our $html = '';          foreach my $e (@{$xml->{'logentry'}}) {
99          sub html {                  warn "# e = ",$self->dump( $e ) if $self->debug;
100                  $html .= join("\n", @_);                  $coderef->($e);
101          }          }
102    }
103    
104    sub as_markup {
105            my ($self) = @_;
106    
107            # extract svk revision: r113@athlon (orig r999): dpavlin | 2005-09-01 20:38:07 +0200
108            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*';
109    
110            sub encode {
111                    my $foo = shift;
112                    $foo =~ s/$svk_rev_re//gsm;
113                    $foo =~ s/</&lt;/g;
114                    $foo =~ s/>/&gt;/g;
115                    $foo =~ s/"/&quot;/g;
116    #               $foo =~ s/([\n\r][\n\r]+)/$1<br\/>/gis;
117                    $foo =~ s/([\n\r]+)([\-\*]\s+)/$1<br\/>$2/gis;
118                    $foo =~ s/([\n\r]+)(r\d+:\s+)/$1<br\/>$2/gis;
119                    $foo =~ s/([\n\r]+)(\s+r\d+@)/$1<br\/>$2/gis;           # svk
120                    return $foo;
121            }
122    
123            my $repository = $self->repository;
124            my $path = $self->path;
125    
126            our $html = qq|
127                    <h1><a href="?repository=$repository">$repository</a></h1>
128                    <h2>$path</h2>
129            |;
130    
131            $self->add_css(qq|
132                    .commit {
133                            clear: both;
134                            padding-top: 1em;
135                            padding-bottom: 1em;
136                            border-top: 1px dashed #ccc;
137                    }
138                    .files {
139                            color: #888;
140                            font-family: monospace;
141                            font-size: 80%;
142                            float: right;
143                            padding-bottom: 1.2em; /* fix 80% back to original 1em */
144                    }
145                    .files a {
146                            text-decoration: none;
147                            color: #888;
148                    }
149                    .date, .revision { color: #666; }
150                    .message {
151                            padding-top: 0.5em;
152                            padding-left: 2em; /* like blockquote */
153                            white-space: pre-wrap;
154                    }
155    
156                    ins { color: #8c8 }
157                    del { color: #c88 }
158            |);
159    
160            $self->iterator( sub {
161                    my $e = shift;
162    
         foreach my $e (@{$xml->{'logentry'}}) {  
163                  my $rev = $e->{'revision'};                  my $rev = $e->{'revision'};
164                  my $date = $e->{'date'};                  my $date = $e->{'date'};
165    
166                  $date =~ s/T/ /;                  $date =~ s/T/ /;
167                  $date =~ s/\.\d+Z$//;                  $date =~ s/\.\d+Z$//;
168    
169                  html '<p><tt>'.$date.'</tt> <em>',$e->{'author'},'</em> <tt style="color:#808080">r',$e->{'revision'},'</tt></p>';                  my $msg = $e->{'msg'};
170                    $msg = '' if ref($msg); # FIXME why do I need this, dammit?
171                    if ( $msg ) {
172                            $msg = encode( $msg );
173                            $msg = qq|<div class="message">$msg</div>|;
174                    }
175    
176                  my @files;                  my @files;
177    
# Line 128  sub as_markup { Line 182  sub as_markup {
182                                  push @files, "<ins>$path</ins>";                                  push @files, "<ins>$path</ins>";
183                          } elsif ($action eq "D") {                          } elsif ($action eq "D") {
184                                  push @files, "<del>$path</del>";                                  push @files, "<del>$path</del>";
185                          } else{                          } else {
186                                  push @files, $path;                                  push @files, $path;
187                          }                          }
188                  }                  }
189    
190                  html '<blockquote><p><tt style="color:#808080">',join(", ",@files),':</tt> ',encode($e->{'msg'}),'</p></blockquote>';                  $html .= qq|
191                            <div class="commit">
192                                    <span class="date">$date</span>
193                                    <em>$e->{author}</em>
194                                    <span class="revision">$e->{revision}</span>
195                                    <div class="files">\n
196                                    |
197                                    . join("<br>\n",
198                                            map {
199                                                    qq|<a href="?repository=$repository;path=$_">$_</a>|
200                                            } @files
201                                    )
202                                    . qq|
203                                    </div>
204                                    $msg
205                            </div>
206                    |;
207    
208          }          });
209    
210          return $html;          return $html;
211  }  }
212    
213    sub codeswarm_as_markup {
214            my ($self) = @_;
215    
216            $self->content_type('text/xml');
217    
218            my $file_events = '';
219    
220            $self->iterator( sub {
221                    my $e = shift;
222                    
223                    my $rev = $e->{'revision'};
224                    my $date = DateTimeX::Easy->new( $e->{'date'} )->epoch . '000'; # ms
225                    my $author = $e->{'author'};
226    
227                    foreach my $p (@{$e->{'paths'}->{'path'}}) {
228                            my ($action,$path) = ($p->{'action'},$p->{'content'});
229                            $file_events .= qq|\t<event filename="$path" date="$date" author="$author" />\n|;
230                    }
231    
232            });
233    
234            return qq|<?xml version="1.0"?>
235            <!-- One commit per day for one month by a documenter and programmer. -->
236            <file_events>
237            $file_events
238            </file_events>
239            |;
240    
241    }
242    
243  1;  1;

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

  ViewVC Help
Powered by ViewVC 1.1.26