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 |
|
|
13 |
my $debug = 0; |
my $debug = $ENV{'DEBUG'} || 0; |
14 |
|
|
15 |
my $max_items = 500; |
my $limit = 1000; |
16 |
|
|
17 |
my $repository = 'file:///home/dpavlin/.svk/strix4/'; |
my $repository_dir = '/srv/svn'; |
18 |
my $svnweb = 'http://localhost/svnweb/svk/index.cgi/strix4/revision?rev='; |
my $svnweb = 'https://svn-strix.carnet.hr/private/svnweb/index.cgi/%s/revision?rev=%d'; |
19 |
|
|
20 |
|
# my local config for development |
21 |
|
$repository_dir = '/home/dpavlin/private/svn'; |
22 |
|
$svnweb = 'http://localhost/svnweb/index.cgi/%s/revision?rev=%d'; |
23 |
|
# my local svk mirrors |
24 |
|
$repository_dir = '/home/dpavlin/.svk'; |
25 |
|
$svnweb = 'http://localhost/svnweb/svk/index.cgi/%s/revision?rev=%d'; |
26 |
|
|
27 |
|
# for older JSON |
28 |
|
#sub encode_json { objToJson( @_ ) } |
29 |
|
|
30 |
|
sub path_strip { |
31 |
|
my $path = shift; |
32 |
|
# $path =~ $strip_branch; |
33 |
|
return $path; |
34 |
|
} |
35 |
|
|
36 |
|
opendir(my $dir, $repository_dir) || die "can't open $repository_dir: $!"; |
37 |
|
my @repositories = sort grep { -f "$repository_dir/$_/format" } readdir($dir); |
38 |
|
closedir($dir); |
39 |
|
|
40 |
|
our $q = CGI->new; |
41 |
|
my $repository = $q->param('repository'); |
42 |
|
$repository = (grep { m/^\Q$repository\E$/ } @repositories )[0] if $repository; |
43 |
|
|
44 |
|
warn "q = ",dump( $q ); |
45 |
|
warn "# limit: ", $q->param('limit'); |
46 |
|
|
47 |
|
sub select_repository { |
48 |
|
my $onChange = qq{document.getElementById('current_repository').submit();}; |
49 |
|
return ( |
50 |
|
$q->start_form( -name => 'current_repository', -id => 'current_repository', -method => 'post' ), |
51 |
|
"From repository ", |
52 |
|
$q->popup_menu( -name => 'repository', -values => [ @repositories ], -onChange => $onChange ), |
53 |
|
" show ", |
54 |
|
$q->popup_menu( -name => 'limit', -values => [ qw/100 500 1000 5000 10000/ ], -onChange => $onChange ), |
55 |
|
" revisions with ", |
56 |
|
$q->checkbox(-name=>'path', -checked=>1, -value=>'ON', -label=>'path modifications', -onChange => $onChange ), |
57 |
|
$q->submit, |
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 = { |
my $json = { |
150 |
properties => { |
properties => { |
160 |
|
|
161 |
my $log; |
my $log; |
162 |
{ |
{ |
163 |
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"; |
164 |
|
warn "cmd: $cmd\n"; |
165 |
|
open( my $log_fh, '-|', $cmd) || die "can't read svn log: $!"; |
166 |
local $/ = undef; |
local $/ = undef; |
167 |
$log = <$log_fh>; |
$log = <$log_fh>; |
168 |
close( $log_fh ); |
close( $log_fh ); |
175 |
foreach my $e (@{$xml->{'logentry'}}) { |
foreach my $e (@{$xml->{'logentry'}}) { |
176 |
|
|
177 |
foreach my $p (@{$e->{'paths'}->{'path'}}) { |
foreach my $p (@{$e->{'paths'}->{'path'}}) { |
178 |
my $label = $e->{'revision'} . ' - ' . $p->{'content'}; |
my $path = delete( $p->{'content'} ); |
179 |
|
my $label = $e->{'revision'} . ' - ' . path_strip( $path ); |
180 |
my $item = { |
my $item = { |
181 |
type => 'Item', |
type => 'Item', |
182 |
id => $label, |
id => $label, |
183 |
label => $label, |
label => $label, |
184 |
uri => $svnweb . $e->{'revision'}, |
uri => sprintf($svnweb, $repository, $e->{'revision'}), |
185 |
path => delete( $p->{'content'} ), |
path_full => $path, |
186 |
|
path => path_strip( $path ), |
187 |
}; |
}; |
188 |
|
|
189 |
$item->{$_} = $p->{$_} foreach keys %$p; |
$item->{$_} = $p->{$_} foreach grep { ! defined $item->{$_} } keys %$p; |
190 |
$item->{$_} = $e->{$_} foreach grep { ! /^(paths)$/ } keys %$e; |
$item->{$_} = $e->{$_} foreach grep { ! defined $item->{$_} && ! /^(paths)$/ } keys %$e; |
|
|
|
|
$item->{'path'} =~ s!^/[^/]+/[^/]+/!/!; |
|
191 |
|
|
192 |
warn dump( $item ) if $debug; |
warn dump( $item ) if $debug; |
193 |
|
|
194 |
push @{ $json->{items} }, $item; |
push @{ $json->{items} }, $item; |
195 |
|
|
196 |
$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; |
|
197 |
} |
} |
198 |
|
|
|
last if ! $max_items; |
|
199 |
} |
} |
200 |
|
|
201 |
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 ); |