use strict; use SVN::SVNLook 0.02; use XML::RSS; use Jcode; # ActivePerl de install ## ppm ## ppm> install XML-RSS ## ppm> install Jcode ## ppm> e # ================================= # 設定 # ================================= my $encode = 'utf8' ; # RSS出力エンコード(sjis/euc/utf8) my $host_encode = 'sjis' ; # PCのエンコード(sjis/euc/utf8) svn は内部でUTF8を使うのでそれにあわせると良いかも # encode map( Jcode と LANG をマッピング ) my %lang_map = ( 'sjis' => 'sjis', 'euc' => 'ujis', 'utf8' => 'utf8' ) ; # encode map( Jcode と RSSのcharset をマッピング ) my %enc_map = ( 'sjis' => 'Shift_JIS', 'euc' => 'EUC-JP', 'utf8' => 'UTF-8' ) ; my $repo = $ARGV[0]; my $revision = $ARGV[1]; my $title = $ARGV[2]; my $url = $ARGV[3]; my $num_rev = $ARGV[4]; my $output = $ARGV[5]; # 環境変数 LANG を強制指定(svn の文字コードを固定する) $ENV{'LANG'} = "ja_JP.$lang_map{$host_encode}" ; # init SVNLook my $svnlook = SVN::SVNLook->new( repo => $repo, cmd => 'svnlook' ); # init RSS my $rss = new XML::RSS( version => '1.0', encoding => $enc_map{$encode} # 'Shift_JIS' ); Jcode::convert(\$title, $encode, $host_encode ) if ($encode ne $host_encode); # 目的の文字コードへ変換 $rss->channel( title => $title, link => $url ); for (my $i = $revision; $i > 0 && $i > $revision - $num_rev; $i--) { my ($author, $date, $logmessage) = $svnlook->info($i); my ($adds, $dels, $mods) = $svnlook->fileschanged($i); my $rssdate = &svndate_to_dcdate($date); # log はエンコードされている(LANGに依存) # my $logmessage = '?\229?\191?\152?\227?\130?\140?\227?\129?\166?\227?\129?\132?\227?\129?\159?\227?\128?\130' ; $logmessage =~ s/\?\\([0-9]..)/pack('C', $1)/eg ; # "?\000" のエンコードを 戻す # unix # Jcode::convert(\$logmessage, $encode, $host_encode ) if ($encode ne $host_encode); # 目的の文字コードへ変換 # windows ? 内部で特殊な変換がかかっているぽい Jcode::convert(\$logmessage, $encode, 'utf8' ) if ($encode ne 'utf8'); # 目的の文字コードへ変換 &add_svnitem($rss, $i, $author, $rssdate, $logmessage, "Added", @{$adds}); &add_svnitem($rss, $i, $author, $rssdate, $logmessage, "Deleted", @{$dels}); &add_svnitem($rss, $i, $author, $rssdate, $logmessage, "Modified", @{$mods}); } sub add_svnitem { my ($rss, $revision, $author, $rssdate, $logmessage, $prefix, @changes) = @_; $prefix = "$author $prefix" if ($author ne ''); foreach my $path (@changes) { $rss->add_item( title => "$prefix \@$revision: $path", link => "$url!svn/bc/$revision/$path", description => "$logmessage", dc => { date => $rssdate, }, ); } } open(FH, ">$output") or die; print FH $rss->as_string; close(FH); sub svndate_to_dcdate { my ($date) = @_; $date =~ /^(\d\d\d\d-\d\d-\d\d) (\d\d:\d\d:\d\d) ([+-]\d\d)(\d\d)/; "$1T$2$3:$4" }