--- svn/svn2js.cgi 2008/10/05 18:45:10 14 +++ svn/index.cgi 2008/10/06 17:09:17 16 @@ -8,13 +8,119 @@ use XML::Simple; use Data::Dump qw/dump/; use JSON; +use CGI; my $debug = 0; my $max_items = 500; -my $repository = 'file:///home/dpavlin/.svk/strix4/'; -my $svnweb = 'http://localhost/svnweb/svk/index.cgi/strix4/revision?rev='; +my $repository_dir = '/srv/svn'; +my $svnweb = 'https://svn-strix.carnet.hr/private/svnweb/index.cgi/%s/revision?rev=%d'; +my $strip_branch = s!^/(branches/)?[^/]+/!/!; + +# my local config for development +$repository_dir = '/home/dpavlin/private/svn'; +$svnweb = 'http://localhost/svnweb/index.cgi/%s/revision?rev=%d'; +$strip_branch = s!!!; + +# for older JSON +#sub encode_json { objToJson( @_ ) } + +sub path_strip { + my $path = shift; + $path =~ $strip_branch; + return $path; +} + +opendir(my $dir, $repository_dir) || die "can't open $repository_dir: $!"; +my @repositories = sort grep { -f "$repository_dir/$_/format" } readdir($dir); +closedir($dir); + +our $q = CGI->new; +my $repository = $q->param('repository'); +$repository = (grep { m/^\Q$repository\E$/ } @repositories )[0]; + +sub select_repository { + $q->start_form( -name => 'current_repository', -id => 'current_repository' ), + "Select repository: ", + $q->popup_menu( -name => 'repository', -values => [ @repositories ], -onChange => qq{document.getElementById('current_repository').submit();} ), + $q->submit, + $q->end_form; +} + +if ( ! $repository ) { + print $q->header,$q->start_html("Select repository"), select_repository; + exit; +} elsif ( ! $q->param('json') ) { + $repository ||= 'Select repository'; + print $q->header, qq| + + +$repository -- Exhibit SVN exhibit facet browsing + + + + + + + + + +
+based on, +exhibit
+|, select_repository, qq| + + + + + + + + + +
+
+ +
+ +
+ +
+ +
+ +
+ +
+
+ +
+ +
+
+ + + + |; + exit; +} my $json = { properties => { @@ -30,7 +136,7 @@ my $log; { - open( my $log_fh, '-|', "svn log --xml --stop-on-copy -v $repository" ) || die "can't read svn log: $!"; + open( my $log_fh, '-|', "svn log --xml --stop-on-copy -v file://$repository_dir/$repository" ) || die "can't read svn log: $!"; local $/ = undef; $log = <$log_fh>; close( $log_fh ); @@ -43,19 +149,19 @@ foreach my $e (@{$xml->{'logentry'}}) { foreach my $p (@{$e->{'paths'}->{'path'}}) { - my $label = $e->{'revision'} . ' - ' . $p->{'content'}; + my $path = delete( $p->{'content'} ); + my $label = $e->{'revision'} . ' - ' . path_strip( $path ); my $item = { type => 'Item', id => $label, label => $label, - uri => $svnweb . $e->{'revision'}, - path => delete( $p->{'content'} ), + uri => sprintf($svnweb, $repository, $e->{'revision'}), + path_full => $path, + path => path_strip( $path ), }; - $item->{$_} = $p->{$_} foreach keys %$p; - $item->{$_} = $e->{$_} foreach grep { ! /^(paths)$/ } keys %$e; - - $item->{'path'} =~ s!^/[^/]+/[^/]+/!/!; + $item->{$_} = $p->{$_} foreach grep { ! defined $item->{$_} } keys %$p; + $item->{$_} = $e->{$_} foreach grep { ! defined $item->{$_} && ! /^(paths)$/ } keys %$e; warn dump( $item ) if $debug;