Added the latest fixes for the new backend.

master
Loic d'Anterroches 2009-05-25 14:18:48 +02:00
parent c83e2e6f30
commit d31cd2aef4
6 changed files with 53 additions and 54 deletions

View File

@ -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;
@ -187,6 +175,38 @@ class IDF_Commit extends Pluf_Model
return $commit;
}
/**
* 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.
*

View File

@ -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));

View File

@ -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);
}
/**

View File

@ -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',

View File

@ -23,9 +23,9 @@
{/block}
{block context}
<p><strong>{trans 'Branches:'}</strong><br />
{foreach $branches as $branch}
{foreach $branches as $branch => $path}
{aurl 'url', 'IDF_Views_Source::treeBase', array($project.shortname, $branch)}
<span class="label{if $commit == $branch} active{/if}"><a href="{$url}" class="label">{$branch}</a></span><br />
<span class="label{if in_array($branch, $tree_in)} active{/if}"><a href="{$url}" class="label">{$branch}</a></span><br />
{/foreach}
</p>
{/block}

View File

@ -24,9 +24,9 @@
{block context}
<p><strong>{trans 'Branches:'}</strong><br />
{foreach $branches as $branch}
{foreach $branches as $branch => $path}
{aurl 'url', 'IDF_Views_Source::treeBase', array($project.shortname, $branch)}
<span class="label{if $commit == $branch} active{/if}"><a href="{$url}" class="label">{$branch}</a></span><br />
<span class="label{if in_array($branch, $tree_in)} active{/if}"><a href="{$url}" class="label">{$branch}</a></span><br />
{/foreach}
</p>
{/block}