/[simile]/svn/index.cgi
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /svn/index.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 48 - (show annotations)
Mon Oct 27 22:03:31 2008 UTC (15 years, 5 months ago) by dpavlin
File size: 5781 byte(s)
use `hostname -s`.js as config file if it exists
1 #!/usr/bin/perl -w
2
3 # svn2js.pl
4 #
5 # 10/05/08 16:15:38 CEST Dobrica Pavlinusic <dpavlin@rot13.org>
6
7 use strict;
8 use XML::Simple;
9 use Data::Dump qw/dump/;
10 use JSON;
11 use CGI;
12 use File::Slurp;
13
14 my $debug = $ENV{'DEBUG'} || 0;
15
16 my $config_path = $0;
17 $config_path =~ s/.cgi/.js/;
18
19 my $hostname = `hostname -s`;
20 chomp($hostname);
21 $hostname .= '.js';
22 $config_path = $hostname if -e $hostname;
23
24 my $config = from_json( read_file( $config_path ) );
25 my $repository_dir = $config->{repository_dir} || die "no repository_dir in $config_path";
26 my $svnweb = $config->{svnweb} || die "no svnweb in $config_path";
27 die "no js URLs to Exhibit API and/or plugins" unless $config->{js};
28
29 my $limit = 1000;
30
31 # for older JSON
32 #sub encode_json { objToJson( @_ ) }
33
34 sub path_strip {
35 my $path = shift;
36 # $path =~ $strip_branch;
37 return $path;
38 }
39
40 opendir(my $dir, $repository_dir) || die "can't open $repository_dir: $!";
41 my @repositories = sort grep { -f "$repository_dir/$_/format" } readdir($dir);
42 closedir($dir);
43
44 our $q = CGI->new;
45 my $repository = $q->param('repository');
46 $repository = (grep { m/^\Q$repository\E$/ } @repositories )[0] if $repository;
47
48 warn "q = ",dump( $q );
49 warn "# limit: ", $q->param('limit');
50
51 sub select_repository {
52 my $onChange = qq{document.getElementById('current_repository').submit();};
53 # we want to activete javascript magic refresh after we hit submit for the first time, and not always
54 $onChange = '' unless $q->param('did_submit');
55 return (
56 $q->start_form( -name => 'current_repository', -id => 'current_repository', -method => 'post' ),
57 "From repository ",
58 $q->param('did_submit') ?
59 $q->popup_menu( -name => 'repository', -values => [ @repositories ], -onChange => $onChange ) :
60 $q->radio_group( -name => 'repository', -values => [ @repositories ], -onChange => $onChange ), # , -linebreak => 'true' ),
61 " show ",
62 $q->popup_menu( -name => 'limit', -values => [ qw/100 500 1000 5000 10000/ ], -onChange => $onChange ),
63 " revisions and ",
64 $q->checkbox(-name=>'path', -checked=>1, -value=>'ON', -label=>'path modifications', -onChange => $onChange ),
65 " ",
66 $q->submit(-value=>'in Exhibit'),
67 $q->hidden(-name=>'did_submit', -value=>1),
68 $q->end_form
69 );
70 }
71
72 if ( ! $repository ) {
73 print $q->header,$q->start_html("Select repository"), select_repository;
74 exit;
75 } elsif ( ! $q->param('json') ) {
76 $repository ||= 'Select repository';
77 print $q->header, qq|
78 <html>
79 <head>
80 <title>$repository -- Exhibit SVN exhibit facet browsing</title>
81
82 <link rel="exhibit/data"
83 type="application/json"
84 href="|, $q->url( -query => 1 ), qq|&json=1" />
85
86 |, join("\n", map { qq|<script src="$_" type="text/javascript"></script>| } @{ $config->{js} } ), qq|
87
88 </head>
89 <body>
90 <div style="float: right">
91 <a href="http://stud05.technikum-wien.at/~tw05n126/exhibit/log/log.html">based on</a>,
92 <a href="http://simile.mit.edu/exhibit/">exhibit</a></div>
93 |, select_repository, qq|
94 <table width="100%" style="font-size: 0.8em">
95 <tr valign="top">
96 <td rowspan="2" width="25%">
97 <div ex:role="facet" ex:facetClass="TextSearch" ex:facetLabel="Search"></div>
98
99 <div ex:role="facet" ex:expression=".author" ex:facetLabel="Author"
100 ex:sortMode="count"></div>
101 |, $q->param('path') ?
102 qq|
103 <div ex:role="facet" ex:expression=".action" ex:facetLabel="Action"
104 ex:sortMode="count" ex:scroll="false"></div>
105 | : '',
106 qq|
107 <div ex:role="facet" ex:expression=".revision" ex:facetClass="NumericRange"
108 ex:interval="20" ex:scroll="true"></div>
109 |, $q->param('path') ?
110 qq|
111 <div ex:role="facet" ex:expression=".path" ex:facetLabel="Path by Count"
112 ex:sortMode="count"></div>
113 | : '',
114 qq|
115 </td>
116 <td>
117
118 <div ex:role="facet" ex:expression=".path" ex:facetLabel="Path by Name"
119 ex:sortMode="value"></div>
120 </td>
121 </tr>
122 <tr valign="top">
123 <td ex:role="viewPanel">
124
125 <div ex:role="view" ex:viewClass="Timeline" ex:start=".date"
126 ex:colorKey=".author"
127 ex:topBandUnit="week" ex:topBandPixelsPerUnit="200"
128 ex:bottomBandUnit="month" ex:bottomBandPixelsPerUnit="25"
129 ex:timelineHeight="550" />
130
131 <div ex:role="view" ex:viewClass="Tabular"
132 ex:columns=".revision, .author, .date, .PATH, .action, .copyfrom-path, .copyfrom-rev, .msg"
133 />
134 </td>
135
136 </tr>
137 </table>
138
139 </body>
140 </html>
141 |;
142 exit;
143 }
144
145 my $json = {
146 properties => {
147 revision => {
148 valueType => "number",
149 },
150 'google-code-svn-link' => {
151 valueType => "url"
152 }
153 },
154 items => [],
155 };
156
157 my $log;
158 {
159 my $cmd = "svn log --xml --stop-on-copy -v --limit " . ( $q->param('limit') || $limit ) . " file://$repository_dir/$repository";
160 warn "cmd: $cmd\n";
161 open( my $log_fh, '-|', $cmd) || die "can't read svn log: $!";
162 local $/ = undef;
163 $log = <$log_fh>;
164 close( $log_fh );
165 }
166
167 my $xml = XMLin($log, ForceArray => [ 'logentry', 'path' ]);
168
169 warn dump( $xml ) if $debug;
170
171 foreach my $e (@{$xml->{'logentry'}}) {
172
173 foreach my $p (@{$e->{'paths'}->{'path'}}) {
174 my $path = delete( $p->{'content'} );
175 my $label = $e->{'revision'} . ' - ' . path_strip( $path );
176 my $item = {
177 type => 'Item',
178 id => $label,
179 label => $label,
180 uri => sprintf($svnweb, $repository, $e->{'revision'}),
181 path_full => $path,
182 path => path_strip( $path ),
183 };
184
185 $item->{$_} = $p->{$_} foreach grep { ! defined $item->{$_} } keys %$p;
186 $item->{$_} = $e->{$_} foreach grep { ! defined $item->{$_} && ! /^(paths)$/ } keys %$e;
187
188 warn dump( $item ) if $debug;
189
190 push @{ $json->{items} }, $item;
191
192 last if ! $q->param('path');
193 }
194
195 }
196
197 print qq|Content-type: application/json\n\r\n\r|, encode_json( $json );
198

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26