InDefero

Sign in or create your account | Project List | Help

InDefero Commit Details

Date:2009-07-03 10:23:49 (1 year 2 months ago)
Author:Loïc d'Anterroches
Commit:7d6cb222912cee5c7ac353efea7a55fc5a7b2d82
Message:Fixed to have a better character encoding detection of the git log.

Files: src/IDF/Commit.php (2 diffs)
src/IDF/Scm/Git.php (1 diff)
src/IDF/Tests/TestGit.php (1 diff)
src/IDF/Tests/data/git-log-iso-8859-1.txt (1 diff)

Change Details

src/IDF/Commit.php
189189     */
190190    public static function toUTF8($text)
191191    {
192        $enc = 'ASCII, UTF-8, ISO-8859-1, JIS, EUC-JP, SJIS';
192193        $ref = $text;
193194        if (is_array($text)) {
194195            $ref = $text[0];
...... 
196197        if (Pluf_Text_UTF8::check($ref)) {
197198            return $text;
198199        }
199        $encoding = mb_detect_encoding($ref, mb_detect_order(), true);
200        $encoding = mb_detect_encoding($ref, $enc, true);
200201        if ($encoding == false) {
201202            $encoding = Pluf_Text_UTF8::detect_cyr_charset($ref);
202203        }
src/IDF/Scm/Git.php
402402     * Parse the log lines of a --pretty=medium log output.
403403     *
404404     * @param array Lines.
405     * @param int Number of lines in the headers (3)
406405     * @return array Change log.
407406     */
408    public static function parseLog($lines, $hdrs=3)
407    public static function parseLog($lines)
409408    {
410409        $res = array();
411410        $c = array();
412        $hdrs += 2;
413411        $inheads = true;
414412        $next_is_title = false;
415413        foreach ($lines as $line) {
src/IDF/Tests/TestGit.php
4040
4141    }
4242
43    public function testGitCache()
43    /**
44     * parse a log encoded in iso 8859-1
45     */
46    public function testParseIsoLog()
4447    {
45        $repo = substr(dirname(__FILE__), 0, -strlen('src/IDF/Tests')).'/.git';
46        $repo = '/home/loa/Vendors/linux-git/.git';
47        $git = new IDF_Scm_Git($repo);
48        $git->buildBlobInfoCache();
49        //$git->getCachedBlobInfo(array());
48        $log_lines = preg_split("/\015\012|\015|\012/", file_get_contents(dirname(__FILE__).'/data/git-log-iso-8859-1.txt'));
49        $log = IDF_Scm_Git::parseLog($log_lines);
50        $titles = array(
51                        'Quick Profiler entfernt',
52                        'Anwendungsmenu Divider eingefügt',
53                        'Anwendungen aufäumen'
54                        );
55        foreach ($log as $change) {
56            $this->assertEqual(array_shift($titles),
57                               IDF_Commit::toUTF8($change->title));
58        }
59
5060    }
51}
61}
src/IDF/Tests/data/git-log-iso-8859-1.txt
1commit 11531a9dbc64a65150f2f38fbea7cef9d478a123
2Author: unknown <a@(none)>
3Date: Fri Jul 3 01:44:11 2009 +0200
4
5    Quick Profiler entfernt
6
7commit 11531a9dbc64a65150f2f38fbea7cef9d478a123
8Author: unknown <a@(none)>
9Date: Wed Jul 1 15:51:22 2009 +0200
10
11    Anwendungsmenu Divider eingefügt
12
13commit 11531a9dbc64a65150f2f38fbea7cef9d478a123
14Author: unknown <a@(none)>
15Date: Wed Jul 1 15:05:41 2009 +0200
16
17    Anwendungen aufäumen
18
19

Archive Download the corresponding diff file

Branches:
dev
develop
master
newdiff
svn

Tags:
v1.0