svn log の結果を各エントリ1行で出すスクリプト

svn log って下みたいな感じで出力されるけど、こうやって複数行で出されると grep とか sed とかしにくいのよね。

------------------------------------------------------------------------
r9547 | ebihara | 2008-12-12 16:40:57 +0900 (金, 12 12 2008) | 2 lines

#3211:added no_image.gif

------------------------------------------------------------------------

ということでこいつを1行で出すPHPスクリプトをつくった。

<?php
$contents = file_get_contents('php://stdin');
$xml = simplexml_load_string($contents);

foreach ($xml->logentry as $entry)
{
    $attributes = $entry->attributes();
    echo 'r' . trim((string)$attributes['revision']) . ' : ' . trim((string)$entry->msg) . PHP_EOL;
}

以下みたいに使うよ。

svn log --xml | php ~/Documents/misc/svnLogFormatter.php | grep "#3211"