リポジトリブラウザを作ってみる 1.VersionControl_SVNを使ってみた

世間に自分が気に入るオープンソースリポジトリブラウザがない。
RedmineTracも、どっちも使いづらい。
個人的にはBacklogが使いやすいと思ってる。
日本語だし。
そんな感じで、Backlogにインスパイアされたようなリポジトリブラウザを作ってみようかと。
 

サンプルソース

そのまんまでは動かなかったので、手を加えた。
factoryの第1引数に"__ALL__"を指定する場合、クラス変数に格納されるVersionControl_SVNインスタンスの一文字目は大文字になるらしい。

<?php
require_once 'VersionControl/SVN.php';

// エラー処理を設定します -- 常にこのようにしておきましょう!
$svnstack = &PEAR_ErrorStack::singleton('VersionControl_SVN');

// 実行時オプションを設定します
$options = array(
	'fetchmode' => VERSIONCONTROL_SVN_FETCHMODE_RAW,
	'svn_path' => "/usr/bin/svn"
);

// 必要なスイッチや引数を定義します
$switches = array('username' => 'user', 'password' => 'pass');
$args = array('http://svn.example.com/project');

// 方法その 2: 使用できるすべてのコマンドを支配する
// 全サブコマンドを読み込む - オーバーヘッドが大きくなりますが、これが便利な場合もあるでしょう。
$svn = VersionControl_SVN::factory('__ALL__', $options);

// さあ、必要なコマンドはなんでも実行できます ...
echo "List :\n";
print_r($svn->List->run($args, $switches));
echo "\n\n";
echo "Info :\n";
print_r($svn->Info->run($args, $switches));
// ... などなど。

 

Subversionシンボリックリンク作成

VersionControl_SVNではデフォルトで/usr/local/bin/svnを使おうとする。
CentOSの場合、/usr/bin/svnにあるのでシンボリックリンクを貼る。
 

Apacheの設定

なぜか値が返ってこない…。
と思ったら、パスワードをどうするかで止まってた。

-----------------------------------------------------------------------
ATTENTION!  Your password for authentication realm:

   <http://svn.example.com:80> Subversion Repository

can only be stored to disk unencrypted!  You are advised to configure
your system so that Subversion can store passwords encrypted, if
possible.  See the documentation for details.

You can avoid future appearances of this warning by setting the value
of the 'store-plaintext-passwords' option to either 'yes' or 'no' in
'/var/www/.subversion/servers'.
-----------------------------------------------------------------------
Store password unencrypted (yes/no)? svn: Can't read stdin: End of file found

 
対策。
apacheに/var/wwwの書き込み権限を与えて、ApacheからPHPを実行して.subversionを作成。
パスワードをキャッシュさせないように設定。

echo "store-plaintext-passwords = no" >> /var/www/.subversion/servers

 

日本語の文字化けを直す

listとか取れたけど、文字が化ける。
$_ENV['LANG']が"C"になってた。
こんな感じにすれば化けないけど、面倒。

<?php
exec("LANG=en_US.UTF-8; $cmd 2>&1", $out, $ret_var);

 
/var/www/.bash_profileとかで出来ないものかとやってみたけど駄目だった。
どうやら環境変数は/etc/sysconfig/httpdで設定するらしい。
追記。

HTTPD_LANG=en_US.UTF-8

 
/etc/init.d/httpdでデフォルト言語が決められているようだ。

# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}

 

あとがき

VersionControl_SVNってあんまり使いやすくない。
というか、まだ作りかけ。
VersionControl_SVN_Info->parseOutputArray()のコメントに、"@todo Finish this method! : )"って書いてあって中で関数内で何もやってない。
とりあえずVersionControl_SVNのラッパーを作る所から始める。
最低限動く環境は整った。