Added a partial fix of issue 93 to limit memory exhaustion.

This is not perfect because it means that we cannot get the
corresponding commit message and author for each file in the tree view.
This is just a work around that will not affect most of the repositories
but the biggest ones with files not changes for a long time.

To fully fix this problem, one needs to build at each commit time a
cache table with the data of each commit (including the hash of each
file at each commit).
This commit is contained in:
Loic d'Anterroches 2008-12-23 22:29:11 +01:00
parent 4f682c2e93
commit 0a02916e81
2 changed files with 18 additions and 13 deletions

View File

@ -132,7 +132,7 @@ class IDF_Scm_Git
// get the raw log corresponding to this commit to find the
// origin of each file.
$rawlog = array();
$cmd = sprintf('GIT_DIR=%s git log --raw --abbrev=40 --pretty=oneline %s',
$cmd = sprintf('GIT_DIR=%s git log --raw --abbrev=40 --pretty=oneline -5000 %s',
escapeshellarg($this->repo), escapeshellarg($commit));
IDF_Scm::exec($cmd, $rawlog);
// We reverse the log to be able to use a fixed efficient
@ -150,8 +150,8 @@ class IDF_Scm_Git
$file->author = $fc->author;
} else if ($file->type == 'blob') {
$file->date = $co->date;
$file->log = $co->title;
$file->author = $co->author; // May be wrong in some cases.
$file->log = '----';
$file->author = 'Unknown';
}
$file->fullpath = ($folder) ? $folder.'/'.$file->file : $file->file;
$res[] = $file;
@ -309,27 +309,29 @@ class IDF_Scm_Git
{
$res = array();
$c = array();
$i = 0;
$hdrs += 2;
$inheads = true;
$next_is_title = false;
foreach ($lines as $line) {
$i++;
if (0 === strpos($line, 'commit')) {
if (preg_match('/^commit (\w{40})$/', $line)) {
if (count($c) > 0) {
$c['full_message'] = trim($c['full_message']);
$res[] = (object) $c;
}
$c = array();
$c['commit'] = trim(substr($line, 7));
$c['commit'] = trim(substr($line, 7, 40));
$c['full_message'] = '';
$i=1;
$inheads = true;
$next_is_title = false;
continue;
}
if ($i == $hdrs) {
if ($next_is_title) {
$c['title'] = trim($line);
$next_is_title = false;
continue;
}
$match = array();
if (preg_match('/(\S+)\s*:\s*(.*)/', $line, $match)) {
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') {
@ -337,13 +339,16 @@ class IDF_Scm_Git
}
continue;
}
if ($i > ($hdrs+1)) {
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'] = trim($c['full_message']);
$res[] = (object) $c;
return $res;
}

View File

@ -33,7 +33,7 @@
<td class="fileicon"><img src="{media '/idf/img/'~$file.type~'.png'}" alt="{$file.type}" /></td>
<td{if $file.type != 'blob'} colspan="4"{/if}><a href="{$url}">{$file.file}</a></td>
{if $file.type == 'blob'}
{if isset($file.date)}
{if isset($file.date) and $file.log != '----'}
<td><span class="smaller">{$file.date|dateago:"wihtout"}</span></td>
<td><span class="smaller">{$file.author|strip_tags|trim}{trans ':'} {issuetext $file.log, $request, true, false}</span></td>
{else}<td colspan="2"></td>{/if}