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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26