/[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 909 by dpavlin, Fri Jan 2 16:56:42 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  sub as_markup {  has limit => (
24          my ($self) = @_;          is => 'rw',
25            isa => 'Int',
26          # extract svk revision: r113@athlon (orig r999): dpavlin | 2005-09-01 20:38:07 +0200          default => 50,
27          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;  
         }  
28    
29    sub iterator {
30            my ($self,$coderef) = @_;
31            
32          sub sh_regex($$) {          sub sh_regex($$) {
33                  my ($cmd,$regex) = @_;                  my ($cmd,$regex) = @_;
34                  open(my $sh, $cmd . ' |') || die "sh_regex failed on $cmd: $!";                  open(my $sh, $cmd . ' |') || die "sh_regex failed on $cmd: $!";
# Line 87  sub as_markup { Line 78  sub as_markup {
78                  $cmd = "svn log -v --xml $svn_path";                  $cmd = "svn log -v --xml $svn_path";
79          }          }
80    
81            $cmd .= " --limit " . $self->limit if $self->limit;
82    
83          warn "# $cmd\n";          warn "# $cmd\n";
84          open(my $fh, $cmd .' |') || die "failed $cmd: $!";          open(my $fh, $cmd .' |') || die "failed $cmd: $!";
85          my $log;          my $log;
# Line 97  sub as_markup { Line 90  sub as_markup {
90    
91          my $xml = XMLin($log, ForceArray => [ 'logentry', 'path' ]);          my $xml = XMLin($log, ForceArray => [ 'logentry', 'path' ]);
92    
93          our $html = '';          foreach my $e (@{$xml->{'logentry'}}) {
94          sub html {                  warn "# e = ",$self->dump( $e ) if $self->debug;
95                  $html .= join("\n", @_);                  $coderef->($e);
96          }          }
97    }
98    
99    sub as_markup {
100            my ($self) = @_;
101    
102            # extract svk revision: r113@athlon (orig r999): dpavlin | 2005-09-01 20:38:07 +0200
103            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*';
104    
105            sub encode {
106                    my $foo = shift;
107                    $foo =~ s/$svk_rev_re//gsm;
108                    $foo =~ s/</&lt;/g;
109                    $foo =~ s/>/&gt;/g;
110                    $foo =~ s/"/&quot;/g;
111    #               $foo =~ s/([\n\r][\n\r]+)/$1<br\/>/gis;
112                    $foo =~ s/([\n\r]+)([\-\*]\s+)/$1<br\/>$2/gis;
113                    $foo =~ s/([\n\r]+)(r\d+:\s+)/$1<br\/>$2/gis;
114                    $foo =~ s/([\n\r]+)(\s+r\d+@)/$1<br\/>$2/gis;           # svk
115                    return $foo;
116            }
117    
118            our $html = '';
119    
120            $self->add_css(qq|
121                    .commit {
122                            clear: both;
123                            padding-top: 1em;
124                            padding-bottom: 1em;
125                            border-top: 1px dashed #ccc;
126                    }
127                    .files {
128                            color: #888;
129                            font-family: monospace;
130                            font-size: 80%;
131                            float: right;
132                            padding-bottom: 1.2em; /* fix 80% back to original 1em */
133                    }
134                    .date, .revision { color: #666; }
135                    .message {
136                            padding-top: 0.5em;
137                            padding-left: 2em; /* like blockquote */
138                            white-space: pre-wrap;
139                    }
140    
141                    ins { color: #8c8 }
142                    del { color: #c88 }
143            |);
144    
145            $self->iterator( sub {
146                    my $e = shift;
147    
         foreach my $e (@{$xml->{'logentry'}}) {  
148                  my $rev = $e->{'revision'};                  my $rev = $e->{'revision'};
149                  my $date = $e->{'date'};                  my $date = $e->{'date'};
150    
151                  $date =~ s/T/ /;                  $date =~ s/T/ /;
152                  $date =~ s/\.\d+Z$//;                  $date =~ s/\.\d+Z$//;
153    
154                  html '<p><tt>'.$date.'</tt> <em>',$e->{'author'},'</em> <tt style="color:#808080">r',$e->{'revision'},'</tt></p>';                  my $msg = $e->{'msg'};
155                    $msg = '' if ref($msg); # FIXME why do I need this, dammit?
156                    if ( $msg ) {
157                            $msg = encode( $msg );
158                            $msg = qq|<div class="message">$msg</div>|;
159                    }
160    
161                  my @files;                  my @files;
162    
# Line 120  sub as_markup { Line 167  sub as_markup {
167                                  push @files, "<ins>$path</ins>";                                  push @files, "<ins>$path</ins>";
168                          } elsif ($action eq "D") {                          } elsif ($action eq "D") {
169                                  push @files, "<del>$path</del>";                                  push @files, "<del>$path</del>";
170                          } else{                          } else {
171                                  push @files, $path;                                  push @files, $path;
172                          }                          }
173                  }                  }
174    
175                  html '<blockquote><p><tt style="color:#808080">',join(", ",@files),':</tt> ',encode($e->{'msg'}),'</p></blockquote>';                  $html .= qq|
176                            <div class="commit">
177                            <span class="date">$date</span>
178                            <em>$e->{author}</em>
179                            <span class="revision">$e->{revision}</span>
180                            <div class="files">\n| . join("<br>\n",@files) . qq|\n</div>
181                            $msg
182                            </div>
183                    |;
184    
185          }          });
186    
187          return $html;          return $html;
188  }  }
189    
190    sub codeswarm_as_markup {
191            my ($self) = @_;
192    
193            $self->content_type('text/xml');
194    
195            my $file_events = '';
196    
197            $self->iterator( sub {
198                    my $e = shift;
199                    
200                    my $rev = $e->{'revision'};
201                    my $date = DateTimeX::Easy->new( $e->{'date'} )->epoch . '000'; # ms
202                    my $author = $e->{'author'};
203    
204                    foreach my $p (@{$e->{'paths'}->{'path'}}) {
205                            my ($action,$path) = ($p->{'action'},$p->{'content'});
206                            $file_events .= qq|\t<event filename="$path" date="$date" author="$author" />\n|;
207                    }
208    
209            });
210    
211            return qq|<?xml version="1.0"?>
212            <!-- One commit per day for one month by a documenter and programmer. -->
213            <file_events>
214            $file_events
215            </file_events>
216            |;
217    
218    }
219    
220  1;  1;

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

  ViewVC Help
Powered by ViewVC 1.1.26