/[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

Diff of /svn/index.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

svn/svn2js.cgi revision 14 by dpavlin, Sun Oct 5 18:45:10 2008 UTC svn/index.cgi revision 49 by dpavlin, Tue Oct 28 19:10:16 2008 UTC
# Line 8  use strict; Line 8  use strict;
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    
19  my $repository = 'file:///home/dpavlin/.svk/strix4/';  my $hostname = `hostname -s`;
20  my $svnweb = 'http://localhost/svnweb/svk/index.cgi/strix4/revision?rev=';  chomp($hostname);
21    $hostname .= '.js';
22    $config_path = $hostname if -e $hostname;
23    
24    my $config = from_json( read_file( $config_path ) );
25    my $repository_dir = $config->{repository_dir} || die "no repository_dir in $config_path";
26    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
32    #sub encode_json { objToJson( @_ ) }
33    
34    sub path_strip {
35            my $path = shift;
36    #       $path =~ $strip_branch;
37            return $path;
38    }
39    
40    opendir(my $dir, $repository_dir) || die "can't open $repository_dir: $!";
41    my @repositories = sort grep { -f "$repository_dir/$_/format" } readdir($dir);
42    closedir($dir);
43    
44    our $q = CGI->new;
45    my $repository = $q->param('repository');
46    $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 {
52            my $onChange = qq{document.getElementById('current_repository').submit();};
53            # we want to activete javascript magic refresh after we hit submit for the first time, and not always
54            $onChange = '' unless $q->param('did_submit');
55            my $first_letter = substr($repositories[0],0,1);
56            return (
57                    $q->start_form( -name => 'current_repository', -id => 'current_repository', -method => 'post' ),
58                    "From repository ",
59                    $q->param('did_submit') ?
60                            $q->popup_menu( -name => 'repository', -values => [ @repositories ], -onChange => $onChange ) :
61                            "<table><tr><th>$first_letter</th><td>" . join( '', map {
62                                    my $delimiter = '';
63                                    if ( substr($_,0,1) ne $first_letter ) {
64                                            $first_letter = substr($_,0,1);
65                                            $delimiter = "</td></tr>\n<tr><th>$first_letter</th><td>";
66                                    }
67                                    $delimiter . $q->radio_group( -name => 'repository', -values => [ $_ ] )
68                            } @repositories ) . "<td></tr></table>",
69                            #$q->radio_group( -name => 'repository', -values => [ map { "$_, " } @repositories ], -onChange => $onChange ), # , -linebreak => 'true' ),
70                    " show ",
71                    $q->popup_menu( -name => 'limit', -values => [ qw/100 500 1000 5000 10000/ ], -onChange => $onChange ),
72                    " revisions and ",
73                    $q->checkbox(-name=>'path', -checked=>1, -value=>'ON', -label=>'path modifications', -onChange => $onChange ),
74                    " ",
75                    $q->submit(-value=>'in Exhibit'),
76                    $q->hidden(-name=>'did_submit', -value=>1),
77                    $q->end_form
78            );
79    }
80    
81    if ( ! $repository ) {
82            print $q->header,$q->start_html("Select repository"), select_repository;
83            exit;
84    } elsif ( ! $q->param('json') ) {
85            $repository ||= 'Select repository';
86            print $q->header, qq|
87    <html>
88    <head>
89    <title>$repository -- Exhibit SVN exhibit facet browsing</title>
90    
91               <link rel="exhibit/data"
92        type="application/json"
93        href="|, $q->url( -query => 1 ), qq|&json=1" />
94    
95    |, join("\n", map { qq|<script src="$_" type="text/javascript"></script>| } @{ $config->{js} } ), qq|
96    
97    </head>
98    <body>
99    <div style="float: right">
100    <a href="http://stud05.technikum-wien.at/~tw05n126/exhibit/log/log.html">based on</a>,
101    <a href="http://simile.mit.edu/exhibit/">exhibit</a></div>
102    |, select_repository, qq|
103    <table width="100%" style="font-size: 0.8em">
104        <tr valign="top">
105            <td rowspan="2" width="25%">
106              <div ex:role="facet" ex:facetClass="TextSearch" ex:facetLabel="Search"></div>
107            
108                <div ex:role="facet" ex:expression=".author" ex:facetLabel="Author"
109                    ex:sortMode="count"></div>
110    |, $q->param('path') ?
111    qq|
112                <div ex:role="facet" ex:expression=".action" ex:facetLabel="Action"
113                    ex:sortMode="count" ex:scroll="false"></div>
114    | : '',
115    qq|
116                <div ex:role="facet" ex:expression=".revision" ex:facetClass="NumericRange"
117                    ex:interval="20" ex:scroll="true"></div>
118    |, $q->param('path') ?
119    qq|
120                <div ex:role="facet" ex:expression=".path" ex:facetLabel="Path by Count"
121                    ex:sortMode="count"></div>
122    | : '',
123    qq|
124            </td>
125            <td>
126            
127                <div ex:role="facet" ex:expression=".path" ex:facetLabel="Path by Name"
128                    ex:sortMode="value"></div>
129            </td>
130        </tr>
131        <tr valign="top">
132            <td ex:role="viewPanel">
133    
134                <div ex:role="view" ex:viewClass="Timeline" ex:start=".date"
135                    ex:colorKey=".author"
136                    ex:topBandUnit="week" ex:topBandPixelsPerUnit="200"
137                    ex:bottomBandUnit="month" ex:bottomBandPixelsPerUnit="25"
138                    ex:timelineHeight="550" />
139                
140                <div ex:role="view" ex:viewClass="Tabular"
141                    ex:columns=".revision, .author, .date, .PATH, .action, .copyfrom-path, .copyfrom-rev, .msg"
142                    />
143            </td>
144    
145        </tr>
146    </table>
147    
148    </body>
149    </html>
150            |;
151            exit;
152    }
153    
154  my $json = {  my $json = {
155          properties => {          properties => {
# Line 30  my $json = { Line 165  my $json = {
165    
166  my $log;  my $log;
167  {  {
168          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";
169            warn "cmd: $cmd\n";
170            open( my $log_fh, '-|', $cmd) || die "can't read svn log: $!";
171          local $/ = undef;          local $/ = undef;
172          $log = <$log_fh>;          $log = <$log_fh>;
173          close( $log_fh );          close( $log_fh );
# Line 43  warn dump( $xml ) if $debug; Line 180  warn dump( $xml ) if $debug;
180  foreach my $e (@{$xml->{'logentry'}}) {  foreach my $e (@{$xml->{'logentry'}}) {
181    
182          foreach my $p (@{$e->{'paths'}->{'path'}}) {          foreach my $p (@{$e->{'paths'}->{'path'}}) {
183                  my $label = $e->{'revision'} . ' - ' . $p->{'content'};                  my $path = delete( $p->{'content'} );
184                    my $label = $e->{'revision'} . ' - ' . path_strip( $path );
185                  my $item = {                  my $item = {
186                          type => 'Item',                          type => 'Item',
187                          id => $label,                          id => $label,
188                          label => $label,                          label => $label,
189                          uri => $svnweb . $e->{'revision'},                          uri => sprintf($svnweb, $repository, $e->{'revision'}),
190                          path => delete( $p->{'content'} ),                          path_full => $path,
191                            path => path_strip( $path ),
192                  };                  };
193    
194                  $item->{$_} = $p->{$_} foreach keys %$p;                  $item->{$_} = $p->{$_} foreach grep { ! defined $item->{$_} } keys %$p;
195                  $item->{$_} = $e->{$_} foreach grep { ! /^(paths)$/ } keys %$e;                  $item->{$_} = $e->{$_} foreach grep { ! defined $item->{$_} && ! /^(paths)$/ } keys %$e;
   
                 $item->{'path'} =~ s!^/[^/]+/[^/]+/!/!;  
196    
197                  warn dump( $item ) if $debug;                  warn dump( $item ) if $debug;
198    
199                  push @{ $json->{items} }, $item;                  push @{ $json->{items} }, $item;
200    
201                  $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;  
202          }          }
203    
         last if ! $max_items;  
204  }  }
205    
206  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 );

Legend:
Removed from v.14  
changed lines
  Added in v.49

  ViewVC Help
Powered by ViewVC 1.1.26