From 0a02916e812c8c76f12f330f01db3676c40fe3c8 Mon Sep 17 00:00:00 2001 From: Loic d'Anterroches Date: Tue, 23 Dec 2008 22:29:11 +0100 Subject: [PATCH] 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). --- src/IDF/Scm/Git.php | 29 +++++++++++++--------- src/IDF/templates/idf/source/git/tree.html | 2 +- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/IDF/Scm/Git.php b/src/IDF/Scm/Git.php index 993d5f8..74fffba 100644 --- a/src/IDF/Scm/Git.php +++ b/src/IDF/Scm/Git.php @@ -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; } diff --git a/src/IDF/templates/idf/source/git/tree.html b/src/IDF/templates/idf/source/git/tree.html index e6b71fa..ec9fb21 100644 --- a/src/IDF/templates/idf/source/git/tree.html +++ b/src/IDF/templates/idf/source/git/tree.html @@ -33,7 +33,7 @@ {$file.type} {$file.file} {if $file.type == 'blob'} -{if isset($file.date)} +{if isset($file.date) and $file.log != '----'} {$file.date|dateago:"wihtout"} {$file.author|strip_tags|trim}{trans ':'} {issuetext $file.log, $request, true, false} {else}{/if}