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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26