diff --git a/src/IDF/Commit.php b/src/IDF/Commit.php index 0c83053..9059650 100644 --- a/src/IDF/Commit.php +++ b/src/IDF/Commit.php @@ -148,19 +148,7 @@ class IDF_Commit extends Pluf_Model $commit = new IDF_Commit(); $commit->project = $project; $commit->scm_id = $change->commit; - if (Pluf_Text_UTF8::check($change->title)) { - $commit->summary = $change->title; - $commit->fullmessage = $change->full_message; - } else { - // Not in utf8, so we try to detect the encoding and - // convert accordingly. - $encoding = mb_detect_encoding($change->title, mb_detect_order(), true); - if ($encoding == false) { - $encoding = Pluf_Text_UTF8::detect_cyr_charset($change->title); - } - $commit->summary = mb_convert_encoding($change->title, 'UTF-8', $encoding); - $commit->fullmessage = mb_convert_encoding($change->full_message, 'UTF-8', $encoding); - } + list($commit->summary, $commit->fullmessage) = self::toUTF8(array($change->title, $change->full_message)); $commit->author = $scm->findAuthor($change->author); $commit->origauthor = $change->author; $commit->creation_dtime = $change->date; @@ -188,6 +176,38 @@ class IDF_Commit extends Pluf_Model } /** + * Convert encoding to UTF8. + * + * If an array is given, the encoding is detected only on the + * first value and then used to convert all the strings. + * + * @param mixed String or array of string to be converted + * @return mixed String or array of string + */ + public static function toUTF8($text) + { + $ref = $text; + if (is_array($text)) { + $ref = $text[0]; + } + if (Pluf_Text_UTF8::check($ref)) { + return $text; + } + $encoding = mb_detect_encoding($ref, mb_detect_order(), true); + if ($encoding == false) { + $encoding = Pluf_Text_UTF8::detect_cyr_charset($ref); + } + if (is_array($text)) { + foreach ($text as $t) { + $res[] = mb_convert_encoding($t, 'UTF-8', $encoding); + } + return $res; + } else { + return mb_convert_encoding($text, 'UTF-8', $encoding); + } + } + + /** * Returns the timeline fragment for the commit. * * diff --git a/src/IDF/Scm/Cache/Git.php b/src/IDF/Scm/Cache/Git.php index 84a1a50..2eebc2a 100644 --- a/src/IDF/Scm/Cache/Git.php +++ b/src/IDF/Scm/Cache/Git.php @@ -54,6 +54,7 @@ class IDF_Scm_Cache_Git extends Pluf_Model $cache = new IDF_Scm_Cache_Git(); $cache->project = $this->_project; $cache->githash = $blob->hash; + $blob->title = IDF_Commit::toUTF8($blob->title); $cache->content = $blob->date.chr(31).$blob->author.chr(31).$blob->title; $sql = new Pluf_SQL('project=%s AND githash=%s', array($this->_project->id, $blob->hash)); diff --git a/src/IDF/Scm/Mercurial.php b/src/IDF/Scm/Mercurial.php index d63262f..a0371f7 100644 --- a/src/IDF/Scm/Mercurial.php +++ b/src/IDF/Scm/Mercurial.php @@ -207,17 +207,6 @@ class IDF_Scm_Mercurial extends IDF_Scm } else { $type = 'blob'; } - if (!$root and !$folder and preg_match('/^.*\/.*$/', $file)) { - continue; - } - if ($folder) { - preg_match('|^'.$folder.'[/]?([^/]+)?$|', $file,$match); - if (count($match) > 1) { - $file = $match[1]; - } else { - continue; - } - } if ($totest == $file) { return (object) array('perm' => $perm, 'type' => $type, 'hash' => $hash, @@ -229,19 +218,13 @@ class IDF_Scm_Mercurial extends IDF_Scm return false; } - /** - * Get a blob. - * - * @param string request_file_info - * @param null to be svn client compatible - * @return string Raw blob - */ - public function getBlob($request_file_info, $dummy=null) + public function getFile($def, $cmd_only=false) { - return shell_exec(sprintf(Pluf::f('hg_path', 'hg').' cat -R %s -r %s %s', - escapeshellarg($this->repo), - $dummy, - escapeshellarg($this->repo . '/' . $request_file_info->file))); + $cmd = sprintf(Pluf::f('hg_path', 'hg').' cat -R %s -r %s %s', + escapeshellarg($this->repo), + escapeshellarg($def->commit), + escapeshellarg($this->repo.'/'.$def->file)); + return ($cmd_only) ? $cmd : shell_exec($cmd); } /** diff --git a/src/IDF/Views/Source.php b/src/IDF/Views/Source.php index 4e631dc..ac0f5ad 100644 --- a/src/IDF/Views/Source.php +++ b/src/IDF/Views/Source.php @@ -204,17 +204,12 @@ class IDF_Views_Source $page_title = $bc.' - '.$title; $cobject = $scm->getCommit($commit); $in_branches = $scm->inBranches($commit, $request_file); - try { - $cache = Pluf_Cache::factory(); - $key = sprintf('Project:%s::IDF_Views_Source::tree:%s::%s', - $request->project->id, $commit, $request_file); - if (null === ($res=$cache->get($key))) { - $res = new Pluf_Template_ContextVars($scm->getTree($commit, $request_file)); - $cache->set($key, $res); - } - - } catch (Exception $e) { - throw $e; + $cache = Pluf_Cache::factory(); + $key = sprintf('Project:%s::IDF_Views_Source::tree:%s::%s', + $request->project->id, $commit, $request_file); + if (null === ($res=$cache->get($key))) { + $res = new Pluf_Template_ContextVars($scm->getTree($commit, $request_file)); + $cache->set($key, $res); } // try to find the previous level if it exists. $prev = split('/', $request_file); @@ -326,7 +321,7 @@ class IDF_Views_Source $bc = self::makeBreadCrumb($request->project, $commit, $request_file_info->file); $page_title = $bc.' - '.$title; $cobject = $scm->getCommit($commit); - $tree_in = in_array($commit, $branches); + $in_branches = $scm->inBranches($commit, $request_file); // try to find the previous level if it exists. $prev = split('/', $request_file); $l = array_pop($prev); @@ -345,7 +340,7 @@ class IDF_Views_Source 'fullpath' => $request_file, 'base' => $request_file_info->file, 'prev' => $previous, - 'tree_in' => $tree_in, + 'tree_in' => $in_branches, 'branches' => $branches, 'props' => $props, ), @@ -437,7 +432,7 @@ class IDF_Views_Source * @param string File content * @return array Mime type found or 'application/octet-stream', basename, extension */ - public static function getMimeTypeFromContent($file, &$filedata) + public static function getMimeTypeFromContent($file, $filedata) { $info = pathinfo($file); $res = array('application/octet-stream', diff --git a/src/IDF/templates/idf/source/git/file.html b/src/IDF/templates/idf/source/git/file.html index c6ae174..d2343bf 100644 --- a/src/IDF/templates/idf/source/git/file.html +++ b/src/IDF/templates/idf/source/git/file.html @@ -23,9 +23,9 @@ {/block} {block context}
{trans 'Branches:'}
-{foreach $branches as $branch}
+{foreach $branches as $branch => $path}
{aurl 'url', 'IDF_Views_Source::treeBase', array($project.shortname, $branch)}
-{$branch}
+{$branch}
{/foreach}
{trans 'Branches:'}
-{foreach $branches as $branch}
+{foreach $branches as $branch => $path}
{aurl 'url', 'IDF_Views_Source::treeBase', array($project.shortname, $branch)}
-{$branch}
+{$branch}
{/foreach}