Fixed to have a better character encoding detection of the git log.

master
Loic d'Anterroches 2009-07-03 10:23:49 +02:00
parent 32507085b4
commit 7d6cb22291
4 changed files with 39 additions and 11 deletions

View File

@ -189,6 +189,7 @@ class IDF_Commit extends Pluf_Model
*/
public static function toUTF8($text)
{
$enc = 'ASCII, UTF-8, ISO-8859-1, JIS, EUC-JP, SJIS';
$ref = $text;
if (is_array($text)) {
$ref = $text[0];
@ -196,7 +197,7 @@ class IDF_Commit extends Pluf_Model
if (Pluf_Text_UTF8::check($ref)) {
return $text;
}
$encoding = mb_detect_encoding($ref, mb_detect_order(), true);
$encoding = mb_detect_encoding($ref, $enc, true);
if ($encoding == false) {
$encoding = Pluf_Text_UTF8::detect_cyr_charset($ref);
}

View File

@ -402,14 +402,12 @@ class IDF_Scm_Git extends IDF_Scm
* Parse the log lines of a --pretty=medium log output.
*
* @param array Lines.
* @param int Number of lines in the headers (3)
* @return array Change log.
*/
public static function parseLog($lines, $hdrs=3)
public static function parseLog($lines)
{
$res = array();
$c = array();
$hdrs += 2;
$inheads = true;
$next_is_title = false;
foreach ($lines as $line) {

View File

@ -40,12 +40,22 @@ class IDF_Tests_TestGit extends UnitTestCase
}
public function testGitCache()
/**
* parse a log encoded in iso 8859-1
*/
public function testParseIsoLog()
{
$repo = substr(dirname(__FILE__), 0, -strlen('src/IDF/Tests')).'/.git';
$repo = '/home/loa/Vendors/linux-git/.git';
$git = new IDF_Scm_Git($repo);
$git->buildBlobInfoCache();
//$git->getCachedBlobInfo(array());
$log_lines = preg_split("/\015\012|\015|\012/", file_get_contents(dirname(__FILE__).'/data/git-log-iso-8859-1.txt'));
$log = IDF_Scm_Git::parseLog($log_lines);
$titles = array(
'Quick Profiler entfernt',
'Anwendungsmenu Divider eingefügt',
'Anwendungen aufäumen'
);
foreach ($log as $change) {
$this->assertEqual(array_shift($titles),
IDF_Commit::toUTF8($change->title));
}
}
}
}

View File

@ -0,0 +1,19 @@
commit 11531a9dbc64a65150f2f38fbea7cef9d478a123
Author: unknown <a@(none)>
Date: Fri Jul 3 01:44:11 2009 +0200
Quick Profiler entfernt
commit 11531a9dbc64a65150f2f38fbea7cef9d478a123
Author: unknown <a@(none)>
Date: Wed Jul 1 15:51:22 2009 +0200
Anwendungsmenu Divider eingefügt
commit 11531a9dbc64a65150f2f38fbea7cef9d478a123
Author: unknown <a@(none)>
Date: Wed Jul 1 15:05:41 2009 +0200
Anwendungen aufäumen