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

Annotation of /svn/index.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 15 - (hide annotations)
Mon Oct 6 09:41:28 2008 UTC (15 years, 6 months ago) by dpavlin
Original Path: svn/svn2js.cgi
File size: 1945 byte(s)
- strip trunk or branches/foobar from paths
- workaround for older JSON 1.x module
1 dpavlin 14 #!/usr/bin/perl -w
2    
3     # svn2js.pl
4     #
5     # 10/05/08 16:15:38 CEST Dobrica Pavlinusic <dpavlin@rot13.org>
6    
7     use strict;
8     use XML::Simple;
9     use Data::Dump qw/dump/;
10     use JSON;
11    
12     my $debug = 0;
13    
14     my $max_items = 500;
15    
16 dpavlin 15 my $repository = 'file:///srv/svn/strix/';
17     my $svnweb = 'https://svn-strix.carnet.hr/private/svnweb/index.cgi/strix/revision?rev=';
18 dpavlin 14
19 dpavlin 15 # for older JSON
20     sub encode_json { objToJson( @_ ) }
21    
22     sub path_strip {
23     my $path = shift;
24     # $path =~ s!^/[^/]+/[^/]+/!/!;
25     $path =~ s!^/(branches/)?[^/]+/!/!;
26     return $path;
27     }
28    
29 dpavlin 14 my $json = {
30     properties => {
31     revision => {
32     valueType => "number",
33     },
34     'google-code-svn-link' => {
35     valueType => "url"
36     }
37     },
38     items => [],
39     };
40    
41     my $log;
42     {
43     open( my $log_fh, '-|', "svn log --xml --stop-on-copy -v $repository" ) || die "can't read svn log: $!";
44     local $/ = undef;
45     $log = <$log_fh>;
46     close( $log_fh );
47     }
48    
49     my $xml = XMLin($log, ForceArray => [ 'logentry', 'path' ]);
50    
51     warn dump( $xml ) if $debug;
52    
53     foreach my $e (@{$xml->{'logentry'}}) {
54    
55     foreach my $p (@{$e->{'paths'}->{'path'}}) {
56 dpavlin 15 my $path = delete( $p->{'content'} );
57     my $label = $e->{'revision'} . ' - ' . path_strip( $path );
58 dpavlin 14 my $item = {
59     type => 'Item',
60     id => $label,
61     label => $label,
62     uri => $svnweb . $e->{'revision'},
63 dpavlin 15 path_full => $path,
64     path => path_strip( $path ),
65 dpavlin 14 };
66    
67 dpavlin 15 $item->{$_} = $p->{$_} foreach grep { ! defined $item->{$_} } keys %$p;
68     $item->{$_} = $e->{$_} foreach grep { ! defined $item->{$_} && ! /^(paths)$/ } keys %$e;
69 dpavlin 14
70     warn dump( $item ) if $debug;
71    
72     push @{ $json->{items} }, $item;
73    
74     $max_items--;
75     # we skip all other items in commits with more than 10 files as they are too chatty
76     last if $#{ $e->{'paths'}->{'path'} } > 10;
77     # last; # FIXME record just single item for each commit!
78     # we also break out when $max_items is reached to keep browser (somewhat) alive
79     last if ! $max_items;
80     }
81    
82     last if ! $max_items;
83     }
84    
85     print qq|Content-type: application/json\n\r\n\r|, encode_json( $json );
86    

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26