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

This commit is contained in:
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) public static function toUTF8($text)
{ {
$enc = 'ASCII, UTF-8, ISO-8859-1, JIS, EUC-JP, SJIS';
$ref = $text; $ref = $text;
if (is_array($text)) { if (is_array($text)) {
$ref = $text[0]; $ref = $text[0];
@ -196,7 +197,7 @@ class IDF_Commit extends Pluf_Model
if (Pluf_Text_UTF8::check($ref)) { if (Pluf_Text_UTF8::check($ref)) {
return $text; return $text;
} }
$encoding = mb_detect_encoding($ref, mb_detect_order(), true); $encoding = mb_detect_encoding($ref, $enc, true);
if ($encoding == false) { if ($encoding == false) {
$encoding = Pluf_Text_UTF8::detect_cyr_charset($ref); $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. * Parse the log lines of a --pretty=medium log output.
* *
* @param array Lines. * @param array Lines.
* @param int Number of lines in the headers (3)
* @return array Change log. * @return array Change log.
*/ */
public static function parseLog($lines, $hdrs=3) public static function parseLog($lines)
{ {
$res = array(); $res = array();
$c = array(); $c = array();
$hdrs += 2;
$inheads = true; $inheads = true;
$next_is_title = false; $next_is_title = false;
foreach ($lines as $line) { 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'; $log_lines = preg_split("/\015\012|\015|\012/", file_get_contents(dirname(__FILE__).'/data/git-log-iso-8859-1.txt'));
$repo = '/home/loa/Vendors/linux-git/.git'; $log = IDF_Scm_Git::parseLog($log_lines);
$git = new IDF_Scm_Git($repo); $titles = array(
$git->buildBlobInfoCache(); 'Quick Profiler entfernt',
//$git->getCachedBlobInfo(array()); '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