/[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 48 by dpavlin, Mon Oct 27 22:03:31 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            return (
56                    $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 ) {
73            print $q->header,$q->start_html("Select repository"), select_repository;
74            exit;
75    } elsif ( ! $q->param('json') ) {
76            $repository ||= 'Select repository';
77            print $q->header, qq|
78    <html>
79    <head>
80    <title>$repository -- Exhibit SVN exhibit facet browsing</title>
81    
82               <link rel="exhibit/data"
83        type="application/json"
84        href="|, $q->url( -query => 1 ), qq|&json=1" />
85    
86    |, join("\n", map { qq|<script src="$_" type="text/javascript"></script>| } @{ $config->{js} } ), qq|
87    
88    </head>
89    <body>
90    <div style="float: right">
91    <a href="http://stud05.technikum-wien.at/~tw05n126/exhibit/log/log.html">based on</a>,
92    <a href="http://simile.mit.edu/exhibit/">exhibit</a></div>
93    |, select_repository, qq|
94    <table width="100%" style="font-size: 0.8em">
95        <tr valign="top">
96            <td rowspan="2" width="25%">
97              <div ex:role="facet" ex:facetClass="TextSearch" ex:facetLabel="Search"></div>
98            
99                <div ex:role="facet" ex:expression=".author" ex:facetLabel="Author"
100                    ex:sortMode="count"></div>
101    |, $q->param('path') ?
102    qq|
103                <div ex:role="facet" ex:expression=".action" ex:facetLabel="Action"
104                    ex:sortMode="count" ex:scroll="false"></div>
105    | : '',
106    qq|
107                <div ex:role="facet" ex:expression=".revision" ex:facetClass="NumericRange"
108                    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"
112                    ex:sortMode="count"></div>
113    | : '',
114    qq|
115            </td>
116            <td>
117            
118                <div ex:role="facet" ex:expression=".path" ex:facetLabel="Path by Name"
119                    ex:sortMode="value"></div>
120            </td>
121        </tr>
122        <tr valign="top">
123            <td ex:role="viewPanel">
124    
125                <div ex:role="view" ex:viewClass="Timeline" ex:start=".date"
126                    ex:colorKey=".author"
127                    ex:topBandUnit="week" ex:topBandPixelsPerUnit="200"
128                    ex:bottomBandUnit="month" ex:bottomBandPixelsPerUnit="25"
129                    ex:timelineHeight="550" />
130                
131                <div ex:role="view" ex:viewClass="Tabular"
132                    ex:columns=".revision, .author, .date, .PATH, .action, .copyfrom-path, .copyfrom-rev, .msg"
133                    />
134            </td>
135    
136        </tr>
137    </table>
138    
139    </body>
140    </html>
141            |;
142            exit;
143    }
144    
145  my $json = {  my $json = {
146          properties => {          properties => {
# Line 30  my $json = { Line 156  my $json = {
156    
157  my $log;  my $log;
158  {  {
159          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";
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 );
# Line 43  warn dump( $xml ) if $debug; Line 171  warn dump( $xml ) if $debug;
171  foreach my $e (@{$xml->{'logentry'}}) {  foreach my $e (@{$xml->{'logentry'}}) {
172    
173          foreach my $p (@{$e->{'paths'}->{'path'}}) {          foreach my $p (@{$e->{'paths'}->{'path'}}) {
174                  my $label = $e->{'revision'} . ' - ' . $p->{'content'};                  my $path = delete( $p->{'content'} );
175                    my $label = $e->{'revision'} . ' - ' . path_strip( $path );
176                  my $item = {                  my $item = {
177                          type => 'Item',                          type => 'Item',
178                          id => $label,                          id => $label,
179                          label => $label,                          label => $label,
180                          uri => $svnweb . $e->{'revision'},                          uri => sprintf($svnweb, $repository, $e->{'revision'}),
181                          path => delete( $p->{'content'} ),                          path_full => $path,
182                            path => path_strip( $path ),
183                  };                  };
184    
185                  $item->{$_} = $p->{$_} foreach keys %$p;                  $item->{$_} = $p->{$_} foreach grep { ! defined $item->{$_} } keys %$p;
186                  $item->{$_} = $e->{$_} foreach grep { ! /^(paths)$/ } keys %$e;                  $item->{$_} = $e->{$_} foreach grep { ! defined $item->{$_} && ! /^(paths)$/ } keys %$e;
   
                 $item->{'path'} =~ s!^/[^/]+/[^/]+/!/!;  
187    
188                  warn dump( $item ) if $debug;                  warn dump( $item ) if $debug;
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 );

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

  ViewVC Help
Powered by ViewVC 1.1.26