WebSVNの文字化け対策

WebSVNの文字化け対策は検索すれば結構出てくるけど、対象とするWebSVNのバージョンが古いのか辻褄の合わないところがあったので改めてメモ。

WebSVNは2.0で、そのほかの環境はこんな感じ。

# echo $LANG
ja_JP.UTF-8
# httpd -v
Server version: Apache/2.2.6 (Unix)
Server built:   Sep 18 2007 03:54:41
# svn --version --quiet
1.4.4

コミットログの文字化け

コミットログは何もしなくても文字化けしなかった

ファイル名の文字化け

include/config.phpのどこかに追記。

putenv('LANG=ja_JP.UTF-8');

ソースの文字化け

include/config.phpの「LANGUAGE SETUP ---」のところで、次のようにエンコーディングを設定する。

$config->setInputEncoding('UTF-8');
$config->setContentEncoding('UTF-8');

include/svnlook.phpを書き換えて「/usr/bin/nkf -w」を追加していく。

SVNRepository::getFileContents内:

if ($l == "php")
{
    // Output the file to the filename
    $path = encodepath($this->repConfig->path.$path);
    $cmd = quoteCommand($config->svn." cat ".$this->repConfig->svnParams().quote($path)."@$rev"." | /usr/bin/nkf -w"." > $filename"); // " | /usr/bin/nkf -w" を追加
    
    ...
}
else
{
    if ($config->useEnscript)
    {
        // Get the files, feed it through enscript, then remove the enscript headers using sed
        //
        // Note that the sec command returns only the part of the file between <PRE> and </PRE>.
        // It's complicated because it's designed not to return those lines themselves.
        
        $path = encodepath($this->repConfig->path.$path);
        $cmd = quoteCommand($config->svn." cat ".$this->repConfig->svnParams().quote($path)."@$rev"." | ".
                            "/usr/bin/nkf -w | ". // 追加
                            $config->enscript." --language=html ".
                            ($l ? "--color --pretty-print=$l" : "")." -o - | ".
                            $config->sed." -n ".$config->quote."1,/^<PRE.$/!{/^<\\/PRE.$/,/^<PRE.$/!p;}".$config->quote." > $filename");

SVNRepository::listFileContents内:

if ($l == "php")
{
    $tmp = tempnam("temp", "wsvn");

    // Output the file to a temporary file
    $path = encodepath($this->repConfig->path.$path);
    $cmd = quoteCommand($config->svn." cat ".$this->repConfig->svnParams().quote($path)."@$rev"." | /usr/bin/nkf -w"." > $tmp"); // " | /usr/bin/nkf -w" を追加
    
    ...
}
else
{
    if ($config->useEnscript)
    {
        $path = encodepath($this->repConfig->path.$path);
        $cmd = quoteCommand($config->svn." cat ".$this->repConfig->svnParams().quote($path)."@$rev"." | ".
                            "/usr/bin/nkf -w | ". // 追加
                            $config->enscript." --language=html ".
                            ($l ? "--color --pretty-print=$l" : "")." -o - | ".
                            $config->sed." -n ".$config->quote."/^<PRE.$/,/^<\\/PRE.$/p".$config->quote);                                  

とりあえずこれで文字化けしなくなった。