/[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

Annotation of /trunk/lib/Frey/SVN.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 805 - (hide annotations)
Wed Dec 10 23:03:04 2008 UTC (15 years, 5 months ago) by dpavlin
File size: 3891 byte(s)
added codeswarm xml output
1 dpavlin 769 package Frey::SVN;
2     use Moose;
3    
4     # Convert output from svn log to html page (with some formatting of
5     # commit messages)
6     #
7     # 2004-04-28 Dobrica Pavlinusic <dpavlin@rot13.org>
8    
9     extends 'Frey';
10     with 'Frey::Web';
11     #with 'Frey::Storage';
12    
13     use XML::Simple;
14    
15     has repository => (
16     is => 'rw',
17     isa => 'Str',
18     required => 1,
19     default => 'file:///home/dpavlin/private/svn/Frey',
20     );
21    
22 dpavlin 770 has limit => (
23     is => 'rw',
24     isa => 'Int',
25     default => 50,
26     );
27    
28 dpavlin 804 sub iterator {
29     my ($self,$coderef) = @_;
30    
31 dpavlin 769 sub sh_regex($$) {
32     my ($cmd,$regex) = @_;
33     open(my $sh, $cmd . ' |') || die "sh_regex failed on $cmd: $!";
34     while(my $l = <$sh>) {
35     chomp($l);
36     if ($l =~ $regex) {
37     if ($1 && $2) {
38     return ($1,$2);
39     } elsif ($1) {
40     return $1;
41     } else {
42     return $l;
43     }
44     }
45     }
46     #warn "can't find $regex in output of $cmd\n";
47     return;
48     }
49    
50     my $path = $self->repository;
51     warn "# path $path\n";
52    
53     my $cmd;
54     if ($path =~ m#file://# || -e "$path/.svn") {
55     $cmd = "svn log -v --xml $path";
56     } else {
57     my $svn_path = sh_regex('svk info', qr#Mirrored From:\s+([^,]+)#i);
58    
59     if (! $svn_path) {
60    
61     my $svk_depot = sh_regex('svk info', qr#Depot Path: (/.+)#i);
62    
63     my $depot = $svk_depot;
64     my $rel_path;
65    
66     my $path = sh_regex('svk depot --list', qr/^$depot\s+(\S+)/i);
67    
68     while (! $path && $depot =~ s{^(/.*/)([^/]+)/?$}{$1} ) {
69     $rel_path = "$2/$rel_path";
70     $path = sh_regex('svk depot --list', qr/^$depot\s+(\S+)/i);
71     }
72    
73     die "can't find depot path '$svk_depot' in svk depot --list\n" unless ($path);
74     $svn_path = "file:///$path/$rel_path";
75     }
76    
77     $cmd = "svn log -v --xml $svn_path";
78     }
79    
80 dpavlin 770 $cmd .= " --limit " . $self->limit if $self->limit;
81    
82 dpavlin 769 warn "# $cmd\n";
83     open(my $fh, $cmd .' |') || die "failed $cmd: $!";
84     my $log;
85     while(<$fh>) {
86     $log .= $_;
87     }
88     close($fh);
89    
90     my $xml = XMLin($log, ForceArray => [ 'logentry', 'path' ]);
91    
92 dpavlin 804 foreach my $e (@{$xml->{'logentry'}}) {
93     warn "# e = ",$self->dump( $e );
94     $coderef->($e);
95     }
96     }
97    
98     sub as_markup {
99     my ($self) = @_;
100    
101     # extract svk revision: r113@athlon (orig r999): dpavlin | 2005-09-01 20:38:07 +0200
102     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*';
103    
104     sub encode {
105     my $foo = shift;
106     $foo =~ s/$svk_rev_re//gsm;
107     $foo =~ s/</&lt;/g;
108     $foo =~ s/>/&gt;/g;
109     $foo =~ s/"/&quot;/g;
110     $foo =~ s/([\n\r][\n\r]+)/<\/p>$1<p>/gis;
111     $foo =~ s/([\n\r]+)([\-\*]\s+)/$1<br\/>$2/gis;
112     $foo =~ s/([\n\r]+)(r\d+:\s+)/$1<br\/>$2/gis;
113     $foo =~ s/([\n\r]+)(\s+r\d+@)/$1<br\/>$2/gis; # svk
114     return $foo;
115     }
116    
117 dpavlin 769 our $html = '';
118     sub html {
119     $html .= join("\n", @_);
120     }
121    
122 dpavlin 804 $self->iterator( sub {
123     my $e = shift;
124    
125 dpavlin 769 my $rev = $e->{'revision'};
126     my $date = $e->{'date'};
127    
128     $date =~ s/T/ /;
129     $date =~ s/\.\d+Z$//;
130    
131     html '<p><tt>'.$date.'</tt> <em>',$e->{'author'},'</em> <tt style="color:#808080">r',$e->{'revision'},'</tt></p>';
132    
133     my @files;
134    
135     foreach my $p (@{$e->{'paths'}->{'path'}}) {
136     my ($action,$path) = ($p->{'action'},$p->{'content'});
137    
138     if ($action eq "A") {
139     push @files, "<ins>$path</ins>";
140     } elsif ($action eq "D") {
141     push @files, "<del>$path</del>";
142     } else{
143     push @files, $path;
144     }
145     }
146    
147     html '<blockquote><p><tt style="color:#808080">',join(", ",@files),':</tt> ',encode($e->{'msg'}),'</p></blockquote>';
148    
149 dpavlin 804 });
150 dpavlin 769
151     return $html;
152     }
153    
154 dpavlin 805 sub codeswarm_as_markup {
155     my ($self) = @_;
156    
157     $self->content_type('text/xml');
158    
159     my $file_events = '';
160    
161     $self->iterator( sub {
162     my $e = shift;
163    
164     my $rev = $e->{'revision'};
165     my $date = $e->{'date'};
166     my $author = $e->{'author'};
167    
168     foreach my $p (@{$e->{'paths'}->{'path'}}) {
169     my ($action,$path) = ($p->{'action'},$p->{'content'});
170     $file_events .= qq|\t<event filename="$path" date="$date" author="$author" />\n|;
171     }
172    
173     });
174    
175     return qq|<?xml version="1.0"?>
176     <!-- One commit per day for one month by a documenter and programmer. -->
177     <file_events>
178     $file_events
179     </file_events>
180     |;
181    
182     }
183    
184 dpavlin 769 1;

  ViewVC Help
Powered by ViewVC 1.1.26