/[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 770 - (hide annotations)
Tue Dec 9 20:31:31 2008 UTC (15 years, 5 months ago) by dpavlin
File size: 3144 byte(s)
 r3629@llin (orig r748):  dpavlin | 2008-12-08 18:38:22 +0100
 import old script svn2html.pl

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 769 sub as_markup {
29     my ($self) = @_;
30    
31     # extract svk revision: r113@athlon (orig r999): dpavlin | 2005-09-01 20:38:07 +0200
32     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*';
33    
34     sub encode {
35     my $foo = shift;
36     $foo =~ s/$svk_rev_re//gsm;
37     $foo =~ s/</&lt;/g;
38     $foo =~ s/>/&gt;/g;
39     $foo =~ s/"/&quot;/g;
40     $foo =~ s/([\n\r][\n\r]+)/<\/p>$1<p>/gis;
41     $foo =~ s/([\n\r]+)([\-\*]\s+)/$1<br\/>$2/gis;
42     $foo =~ s/([\n\r]+)(r\d+:\s+)/$1<br\/>$2/gis;
43     $foo =~ s/([\n\r]+)(\s+r\d+@)/$1<br\/>$2/gis; # svk
44     return $foo;
45     }
46    
47     sub sh_regex($$) {
48     my ($cmd,$regex) = @_;
49     open(my $sh, $cmd . ' |') || die "sh_regex failed on $cmd: $!";
50     while(my $l = <$sh>) {
51     chomp($l);
52     if ($l =~ $regex) {
53     if ($1 && $2) {
54     return ($1,$2);
55     } elsif ($1) {
56     return $1;
57     } else {
58     return $l;
59     }
60     }
61     }
62     #warn "can't find $regex in output of $cmd\n";
63     return;
64     }
65    
66     my $path = $self->repository;
67     warn "# path $path\n";
68    
69     my $cmd;
70     if ($path =~ m#file://# || -e "$path/.svn") {
71     $cmd = "svn log -v --xml $path";
72     } else {
73     my $svn_path = sh_regex('svk info', qr#Mirrored From:\s+([^,]+)#i);
74    
75     if (! $svn_path) {
76    
77     my $svk_depot = sh_regex('svk info', qr#Depot Path: (/.+)#i);
78    
79     my $depot = $svk_depot;
80     my $rel_path;
81    
82     my $path = sh_regex('svk depot --list', qr/^$depot\s+(\S+)/i);
83    
84     while (! $path && $depot =~ s{^(/.*/)([^/]+)/?$}{$1} ) {
85     $rel_path = "$2/$rel_path";
86     $path = sh_regex('svk depot --list', qr/^$depot\s+(\S+)/i);
87     }
88    
89     die "can't find depot path '$svk_depot' in svk depot --list\n" unless ($path);
90     $svn_path = "file:///$path/$rel_path";
91     }
92    
93     $cmd = "svn log -v --xml $svn_path";
94     }
95    
96 dpavlin 770 $cmd .= " --limit " . $self->limit if $self->limit;
97    
98 dpavlin 769 warn "# $cmd\n";
99     open(my $fh, $cmd .' |') || die "failed $cmd: $!";
100     my $log;
101     while(<$fh>) {
102     $log .= $_;
103     }
104     close($fh);
105    
106     my $xml = XMLin($log, ForceArray => [ 'logentry', 'path' ]);
107    
108     our $html = '';
109     sub html {
110     $html .= join("\n", @_);
111     }
112    
113     foreach my $e (@{$xml->{'logentry'}}) {
114     my $rev = $e->{'revision'};
115     my $date = $e->{'date'};
116    
117     $date =~ s/T/ /;
118     $date =~ s/\.\d+Z$//;
119    
120     html '<p><tt>'.$date.'</tt> <em>',$e->{'author'},'</em> <tt style="color:#808080">r',$e->{'revision'},'</tt></p>';
121    
122     my @files;
123    
124     foreach my $p (@{$e->{'paths'}->{'path'}}) {
125     my ($action,$path) = ($p->{'action'},$p->{'content'});
126    
127     if ($action eq "A") {
128     push @files, "<ins>$path</ins>";
129     } elsif ($action eq "D") {
130     push @files, "<del>$path</del>";
131     } else{
132     push @files, $path;
133     }
134     }
135    
136     html '<blockquote><p><tt style="color:#808080">',join(", ",@files),':</tt> ',encode($e->{'msg'}),'</p></blockquote>';
137    
138     }
139    
140     return $html;
141     }
142    
143     1;

  ViewVC Help
Powered by ViewVC 1.1.26