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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26