9 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
10 |
use JSON; |
use JSON; |
11 |
use CGI; |
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 |
|
|
19 |
my $repository_dir = '/srv/svn'; |
my $hostname = `hostname -s`; |
20 |
my $svnweb = 'https://svn-strix.carnet.hr/private/svnweb/index.cgi/%s/revision?rev=%d'; |
chomp($hostname); |
21 |
my $strip_branch = s!^/(branches/)?[^/]+/!/!; |
$hostname .= '.js'; |
22 |
|
$config_path = $hostname if -e $hostname; |
23 |
# my local config for development |
|
24 |
$repository_dir = '/home/dpavlin/private/svn'; |
my $config = from_json( read_file( $config_path ) ); |
25 |
$svnweb = 'http://localhost/svnweb/index.cgi/%s/revision?rev=%d'; |
my $repository_dir = $config->{repository_dir} || die "no repository_dir in $config_path"; |
26 |
$strip_branch = s!!!; |
my $svnweb = $config->{svnweb} || die "no svnweb in $config_path"; |
27 |
|
die "no js URLs to Exhibit API and/or plugins" unless $config->{js}; |
28 |
|
|
29 |
|
my $limit = 1000; |
30 |
|
|
31 |
# for older JSON |
# for older JSON |
32 |
#sub encode_json { objToJson( @_ ) } |
#sub encode_json { objToJson( @_ ) } |
33 |
|
|
34 |
sub path_strip { |
sub path_strip { |
35 |
my $path = shift; |
my $path = shift; |
36 |
$path =~ $strip_branch; |
# $path =~ $strip_branch; |
37 |
return $path; |
return $path; |
38 |
} |
} |
39 |
|
|
43 |
|
|
44 |
our $q = CGI->new; |
our $q = CGI->new; |
45 |
my $repository = $q->param('repository'); |
my $repository = $q->param('repository'); |
46 |
$repository = (grep { m/^\Q$repository\E$/ } @repositories )[0]; |
$repository = (grep { m/^\Q$repository\E$/ } @repositories )[0] if $repository; |
47 |
|
|
48 |
|
warn "q = ",dump( $q ); |
49 |
|
warn "# limit: ", $q->param('limit'); |
50 |
|
|
51 |
sub select_repository { |
sub select_repository { |
52 |
$q->start_form( -name => 'current_repository', -id => 'current_repository' ), |
my $onChange = qq{document.getElementById('current_repository').submit();}; |
53 |
"Select repository: ", |
# we want to activete javascript magic refresh after we hit submit for the first time, and not always |
54 |
$q->popup_menu( -name => 'repository', -values => [ @repositories ], -onChange => qq{document.getElementById('current_repository').submit();} ), |
$onChange = '' unless $q->param('did_submit'); |
55 |
$q->submit, |
return ( |
56 |
$q->end_form; |
$q->start_form( -name => 'current_repository', -id => 'current_repository', -method => 'post' ), |
57 |
|
"From repository ", |
58 |
|
$q->param('did_submit') ? |
59 |
|
$q->popup_menu( -name => 'repository', -values => [ @repositories ], -onChange => $onChange ) : |
60 |
|
$q->radio_group( -name => 'repository', -values => [ @repositories ], -onChange => $onChange ), # , -linebreak => 'true' ), |
61 |
|
" show ", |
62 |
|
$q->popup_menu( -name => 'limit', -values => [ qw/100 500 1000 5000 10000/ ], -onChange => $onChange ), |
63 |
|
" revisions and ", |
64 |
|
$q->checkbox(-name=>'path', -checked=>1, -value=>'ON', -label=>'path modifications', -onChange => $onChange ), |
65 |
|
" ", |
66 |
|
$q->submit(-value=>'in Exhibit'), |
67 |
|
$q->hidden(-name=>'did_submit', -value=>1), |
68 |
|
$q->end_form |
69 |
|
); |
70 |
} |
} |
71 |
|
|
72 |
if ( ! $repository ) { |
if ( ! $repository ) { |
81 |
|
|
82 |
<link rel="exhibit/data" |
<link rel="exhibit/data" |
83 |
type="application/json" |
type="application/json" |
84 |
href="?repository=$repository&json=1" /> |
href="|, $q->url( -query => 1 ), qq|&json=1" /> |
|
|
|
|
<script |
|
|
src="http://static.simile.mit.edu/exhibit/api-2.0/exhibit-api.js" |
|
|
type="text/javascript"></script> |
|
85 |
|
|
86 |
<script |
|, join("\n", map { qq|<script src="$_" type="text/javascript"></script>| } @{ $config->{js} } ), qq| |
|
src="http://static.simile.mit.edu/exhibit/extensions-2.0/time/time-extension.js"></script> |
|
87 |
|
|
88 |
</head> |
</head> |
89 |
<body> |
<body> |
98 |
|
|
99 |
<div ex:role="facet" ex:expression=".author" ex:facetLabel="Author" |
<div ex:role="facet" ex:expression=".author" ex:facetLabel="Author" |
100 |
ex:sortMode="count"></div> |
ex:sortMode="count"></div> |
101 |
|
|, $q->param('path') ? |
102 |
|
qq| |
103 |
<div ex:role="facet" ex:expression=".action" ex:facetLabel="Action" |
<div ex:role="facet" ex:expression=".action" ex:facetLabel="Action" |
104 |
ex:sortMode="count" ex:scroll="false"></div> |
ex:sortMode="count" ex:scroll="false"></div> |
105 |
|
| : '', |
106 |
|
qq| |
107 |
<div ex:role="facet" ex:expression=".revision" ex:facetClass="NumericRange" |
<div ex:role="facet" ex:expression=".revision" ex:facetClass="NumericRange" |
108 |
ex:interval="10" ex:scroll="true"></div> |
ex:interval="20" ex:scroll="true"></div> |
109 |
|
|, $q->param('path') ? |
110 |
|
qq| |
111 |
<div ex:role="facet" ex:expression=".path" ex:facetLabel="Path by Count" |
<div ex:role="facet" ex:expression=".path" ex:facetLabel="Path by Count" |
112 |
ex:sortMode="count"></div> |
ex:sortMode="count"></div> |
113 |
|
| : '', |
114 |
|
qq| |
115 |
</td> |
</td> |
116 |
<td> |
<td> |
117 |
|
|
126 |
ex:colorKey=".author" |
ex:colorKey=".author" |
127 |
ex:topBandUnit="week" ex:topBandPixelsPerUnit="200" |
ex:topBandUnit="week" ex:topBandPixelsPerUnit="200" |
128 |
ex:bottomBandUnit="month" ex:bottomBandPixelsPerUnit="25" |
ex:bottomBandUnit="month" ex:bottomBandPixelsPerUnit="25" |
129 |
ex:timelineHeight="650" /> |
ex:timelineHeight="550" /> |
130 |
|
|
131 |
<div ex:role="view" ex:viewClass="Tabular" |
<div ex:role="view" ex:viewClass="Tabular" |
132 |
ex:columns=".revision, .author, .date, .path, .action, .copyfrom-path, .copyfrom-rev, .msg" |
ex:columns=".revision, .author, .date, .PATH, .action, .copyfrom-path, .copyfrom-rev, .msg" |
133 |
/> |
/> |
134 |
</td> |
</td> |
135 |
|
|
156 |
|
|
157 |
my $log; |
my $log; |
158 |
{ |
{ |
159 |
open( my $log_fh, '-|', "svn log --xml --stop-on-copy -v file://$repository_dir/$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"; |
160 |
|
warn "cmd: $cmd\n"; |
161 |
|
open( my $log_fh, '-|', $cmd) || die "can't read svn log: $!"; |
162 |
local $/ = undef; |
local $/ = undef; |
163 |
$log = <$log_fh>; |
$log = <$log_fh>; |
164 |
close( $log_fh ); |
close( $log_fh ); |
189 |
|
|
190 |
push @{ $json->{items} }, $item; |
push @{ $json->{items} }, $item; |
191 |
|
|
192 |
$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; |
|
193 |
} |
} |
194 |
|
|
|
last if ! $max_items; |
|
195 |
} |
} |
196 |
|
|
197 |
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 ); |