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

  ViewVC Help
Powered by ViewVC 1.1.26