예제 #1
0
 /**
  * parse a log encoded in iso 8859-2
  */
 public function testParseIsoLog2()
 {
     $log_lines = preg_split("/\r\n|\r|\n/", file_get_contents(dirname(__FILE__) . '/data/git-log-iso-8859-2.txt'));
     $log = IDF_Scm_Git::parseLog($log_lines);
     $titles = array(array('Doda³em model', 'ISO-8859-1'), array('Doda³em model', 'ISO-8859-1'));
     foreach ($log as $change) {
         list($title, $senc) = array_shift($titles);
         list($conv, $encoding) = IDF_Commit::toUTF8($change->title, true);
         $this->assertEqual($title, $conv);
         $this->assertEqual($senc, $encoding);
     }
 }
예제 #2
0
파일: Git.php 프로젝트: burbuja/indefero
 /**
  * Store in the cache blob infos.
  *
  * The info is an array of stdClasses, with hash, date, title and
  * author properties.
  *
  * @param array Blob infos
  */
 public function store($infos)
 {
     foreach ($infos as $blob) {
         $cache = new IDF_Scm_Cache_Git();
         $cache->project = $this->_project;
         $cache->githash = $blob->hash;
         $blob->title = IDF_Commit::toUTF8($blob->title);
         $cache->content = IDF_Commit::toUTF8($blob->date) . chr(31) . IDF_Commit::toUTF8($blob->author) . chr(31) . IDF_Commit::toUTF8($blob->title);
         $sql = new Pluf_SQL('project=%s AND githash=%s', array($this->_project->id, $blob->hash));
         if (0 == Pluf::factory(__CLASS__)->getCount(array('filter' => $sql->gen()))) {
             $cache->create();
         }
     }
 }
예제 #3
0
파일: Git.php 프로젝트: burbuja/indefero
 /**
  * Parse the log lines of a --pretty=medium log output.
  *
  * @param array Lines.
  * @return array Change log.
  */
 public static function parseLog($lines)
 {
     $res = array();
     $c = array();
     $inheads = true;
     $next_is_title = false;
     foreach ($lines as $line) {
         if (preg_match('/^commit (\\w{40})$/', $line)) {
             if (count($c) > 0) {
                 $c['full_message'] = trim($c['full_message']);
                 $c['full_message'] = IDF_Commit::toUTF8($c['full_message']);
                 $c['title'] = IDF_Commit::toUTF8($c['title']);
                 if (isset($c['parents'])) {
                     $c['parents'] = explode(' ', trim($c['parents']));
                 }
                 $res[] = (object) $c;
             }
             $c = array();
             $c['commit'] = trim(substr($line, 7, 40));
             $c['full_message'] = '';
             $inheads = true;
             $next_is_title = false;
             continue;
         }
         if ($next_is_title) {
             $c['title'] = trim($line);
             $next_is_title = false;
             continue;
         }
         $match = array();
         if ($inheads and preg_match('/(\\S+)\\s*:\\s*(.*)/', $line, $match)) {
             $match[1] = strtolower($match[1]);
             $c[$match[1]] = trim($match[2]);
             if ($match[1] == 'date') {
                 $c['date'] = gmdate('Y-m-d H:i:s', strtotime($match[2]));
             }
             continue;
         }
         if ($inheads and !$next_is_title and $line == '') {
             $next_is_title = true;
             $inheads = false;
         }
         if (!$inheads) {
             $c['full_message'] .= trim($line) . "\n";
             continue;
         }
     }
     $c['full_message'] = !empty($c['full_message']) ? trim($c['full_message']) : '';
     $c['full_message'] = IDF_Commit::toUTF8($c['full_message']);
     $c['title'] = IDF_Commit::toUTF8($c['title']);
     if (isset($c['parents'])) {
         $c['parents'] = explode(' ', trim($c['parents']));
     }
     $res[] = (object) $c;
     return $res;
 }