/** * 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); } }
/** * 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(); } } }
/** * Create a commit from a simple class commit info of a changelog. * * @param stdClass Commit info * @param IDF_Project Current project * @return IDF_Commit */ public static function getOrAdd($change, $project) { $sql = new Pluf_SQL('project=%s AND scm_id=%s', array($project->id, $change->commit)); $r = Pluf::factory('IDF_Commit')->getList(array('filter' => $sql->gen())); if ($r->count() > 0) { return $r[0]; } if (!isset($change->full_message)) { $change->full_message = ''; } $scm = IDF_Scm::get($project); $commit = new IDF_Commit(); $commit->project = $project; $commit->scm_id = $change->commit; $commit->summary = self::toUTF8($change->title); $commit->fullmessage = self::toUTF8($change->full_message); $commit->author = $scm->findAuthor($change->author); $commit->origauthor = $change->author; $commit->creation_dtime = $change->date; $commit->create(); $commit->notify($project->getConf()); return $commit; }
/** * 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; }
public function commit($request, $match) { $scm = IDF_Scm::get($request->project); $commit = $match[2]; if (!$scm->isValidRevision($commit)) { // Redirect to the first branch $url = Pluf_HTTP_URL_urlForView('IDF_Views_Source::treeBase', array($request->project->shortname, $scm->getMainBranch())); return new Pluf_HTTP_Response_Redirect($url); } $large = $scm->isCommitLarge($commit); $cobject = $scm->getCommit($commit, !$large); if (!$cobject) { // Redirect to the first branch $url = Pluf_HTTP_URL_urlForView('IDF_Views_Source::treeBase', array($request->project->shortname, $scm->getMainBranch())); return new Pluf_HTTP_Response_Redirect($url); } $title = sprintf(__('%s Commit Details'), (string) $request->project); $page_title = sprintf(__('%s Commit Details - %s'), (string) $request->project, $commit); $rcommit = IDF_Commit::getOrAdd($cobject, $request->project); $diff = new IDF_Diff($cobject->changes); $diff->parse(); $scmConf = $request->conf->getVal('scm', 'git'); $branches = $scm->getBranches(); $in_branches = $scm->inBranches($cobject->commit, ''); $tags = $scm->getTags(); $in_tags = $scm->inTags($cobject->commit, ''); return Pluf_Shortcuts_RenderToResponse('idf/source/commit.html', array('page_title' => $page_title, 'title' => $title, 'diff' => $diff, 'cobject' => $cobject, 'commit' => $commit, 'branches' => $branches, 'tree_in' => $in_branches, 'tags' => $tags, 'tags_in' => $in_tags, 'scm' => $scmConf, 'rcommit' => $rcommit, 'large_commit' => $large), $request); }
/** * Create a commit from a simple class commit info of a changelog. * * @param stdClass Commit info * @param IDF_Project Current project * @return IDF_Commit */ public static function getOrAdd($change, $project) { $sql = new Pluf_SQL('project=%s AND scm_id=%s', array($project->id, $change->commit)); $r = Pluf::factory('IDF_Commit')->getList(array('filter' => $sql->gen())); if ($r->count() > 0) { $r[0]->extra = new IDF_Gconf(); $r[0]->extra->serialize = true; $r[0]->extra->setModel($r[0]); $r[0]->extra->initCache(); return $r[0]; } if (!isset($change->full_message)) { $change->full_message = ''; } $scm = IDF_Scm::get($project); $commit = new IDF_Commit(); $commit->project = $project; $commit->scm_id = $change->commit; $commit->summary = self::toUTF8($change->title); $commit->fullmessage = self::toUTF8($change->full_message); $commit->author = $scm->findAuthor($change->author); $commit->origauthor = self::toUTF8($change->author); $commit->creation_dtime = $change->date; $commit->create(); $extra = $scm->getExtraProperties($change); $commit->extra = new IDF_Gconf(); $commit->extra->serialize = true; // As we can store arrays $commit->extra->setModel($commit); foreach ($extra as $key => $val) { $commit->extra->setVal($key, $val); } $commit->notify($project->getConf()); return $commit; }
/** * Based on the given string, try to find the matching commit. * * If no user found, simply returns null. * * @param string Commit * @return IDF_Commit or null */ public static function findCommit($string) { $string = trim($string); if (strlen($string) == 0) { return null; } $gc = new IDF_Commit(); $sql = new Pluf_SQL('scm_id=%s', array($string)); $gcs = $gc->getList(array('filter' => $sql->gen())); if ($gcs->count() > 0) { return $gcs[0]; } return null; }
public function commit($request, $match) { $scm = IDF_Scm::get($request->project); $commit = $match[2]; $large = $scm->isCommitLarge($commit); $cobject = $scm->getCommit($commit, !$large); if (!$cobject) { throw new Exception('could not retrieve commit object for ' . $commit); } $title = sprintf(__('%s Commit Details'), (string) $request->project); $page_title = sprintf(__('%s Commit Details - %s'), (string) $request->project, $commit); $rcommit = IDF_Commit::getOrAdd($cobject, $request->project); $diff = new IDF_Diff($cobject->diff); $diff->parse(); $scmConf = $request->conf->getVal('scm', 'git'); try { $changes = $scm->getChanges($commit); } catch (Exception $e) { // getChanges is not yes supported by this backend. $changes = array(); } $branches = $scm->getBranches(); $in_branches = $scm->inBranches($cobject->commit, ''); $tags = $scm->getTags(); $in_tags = $scm->inTags($cobject->commit, ''); return Pluf_Shortcuts_RenderToResponse('idf/source/' . $scmConf . '/commit.html', array('page_title' => $page_title, 'title' => $title, 'diff' => $diff, 'cobject' => $cobject, 'commit' => $commit, 'changes' => $changes, 'branches' => $branches, 'tree_in' => $in_branches, 'tags' => $tags, 'tags_in' => $in_tags, 'scm' => $scmConf, 'rcommit' => $rcommit, 'large_commit' => $large), $request); }
/** * Sync the changes in the repository with the timeline. * */ public static function syncTimeline($project, $force = false) { $cache = Pluf_Cache::factory(); $key = 'IDF_Scm:' . $project->shortname . ':lastsync'; if ($force or null === ($res = $cache->get($key))) { $scm = IDF_Scm::get($project); if ($scm->isAvailable()) { foreach ($scm->getChangeLog($scm->getMainBranch(), 25) as $change) { IDF_Commit::getOrAdd($change, $project); } $cache->set($key, true, (int) (Pluf::f('cache_timeout', 300) / 2)); } } }