8 |
use XML::Simple; |
use XML::Simple; |
9 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
10 |
use JSON; |
use JSON; |
11 |
|
use CGI; |
12 |
|
use File::Slurp; |
13 |
|
|
14 |
my $debug = 0; |
my $debug = $ENV{'DEBUG'} || 0; |
15 |
|
|
16 |
my $max_items = 500; |
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 $repository = 'file:///srv/svn/strix/'; |
my $limit = 1000; |
|
my $svnweb = 'https://svn-strix.carnet.hr/private/svnweb/index.cgi/strix/revision?rev='; |
|
23 |
|
|
24 |
# for older JSON |
# for older JSON |
25 |
sub encode_json { objToJson( @_ ) } |
#sub encode_json { objToJson( @_ ) } |
26 |
|
|
27 |
sub path_strip { |
sub path_strip { |
28 |
my $path = shift; |
my $path = shift; |
29 |
# $path =~ s!^/[^/]+/[^/]+/!/!; |
# $path =~ $strip_branch; |
|
$path =~ s!^/(branches/)?[^/]+/!/!; |
|
30 |
return $path; |
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 = { |
my $json = { |
147 |
properties => { |
properties => { |
148 |
revision => { |
revision => { |
157 |
|
|
158 |
my $log; |
my $log; |
159 |
{ |
{ |
160 |
open( my $log_fh, '-|', "svn log --xml --stop-on-copy -v $repository" ) || die "can't read svn log: $!"; |
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; |
local $/ = undef; |
164 |
$log = <$log_fh>; |
$log = <$log_fh>; |
165 |
close( $log_fh ); |
close( $log_fh ); |
178 |
type => 'Item', |
type => 'Item', |
179 |
id => $label, |
id => $label, |
180 |
label => $label, |
label => $label, |
181 |
uri => $svnweb . $e->{'revision'}, |
uri => sprintf($svnweb, $repository, $e->{'revision'}), |
182 |
path_full => $path, |
path_full => $path, |
183 |
path => path_strip( $path ), |
path => path_strip( $path ), |
184 |
}; |
}; |
190 |
|
|
191 |
push @{ $json->{items} }, $item; |
push @{ $json->{items} }, $item; |
192 |
|
|
193 |
$max_items--; |
last if ! $q->param('path'); |
|
# we skip all other items in commits with more than 10 files as they are too chatty |
|
|
last if $#{ $e->{'paths'}->{'path'} } > 10; |
|
|
# last; # FIXME record just single item for each commit! |
|
|
# we also break out when $max_items is reached to keep browser (somewhat) alive |
|
|
last if ! $max_items; |
|
194 |
} |
} |
195 |
|
|
|
last if ! $max_items; |
|
196 |
} |
} |
197 |
|
|
198 |
print qq|Content-type: application/json\n\r\n\r|, encode_json( $json ); |
print qq|Content-type: application/json\n\r\n\r|, encode_json( $json ); |