Fixed issue 93 by preventing the display of a large commit diff.

Still needs to implement the equivalent for subversion and mercurial,
maybe with a simple command $scm->isCommitLarge($commit).
This commit is contained in:
Loic d'Anterroches 2009-01-17 18:46:26 +01:00
parent 61bc7a70b6
commit 835eab9c24
5 changed files with 66 additions and 2 deletions

View File

@ -286,6 +286,39 @@ class IDF_Scm_Git
return $out[0];
}
/**
* Get commit size.
*
* Get the sum of all the added/removed lines and the number of
* affected files.
*
* @param string Commit ('HEAD')
* @return array array(added, removed, affected)
*/
public function getCommitSize($commit='HEAD')
{
$cmd = sprintf('GIT_DIR=%s git log --numstat -1 --pretty=format:%s %s',
escapeshellarg($this->repo),
"'commit %H%n'",
escapeshellarg($commit));
$out = array();
IDF_Scm::exec($cmd, $out);
$affected = count($out) - 2;
$added = 0;
$removed = 0;
$c=0;
foreach ($out as $line) {
$c++;
if ($c < 3) {
continue;
}
list($a, $r, $f) = preg_split("/[\s]+/", $line, 3, PREG_SPLIT_NO_EMPTY);
$added+=$a;
$removed+=$r;
}
return array($added, $removed, $affected);
}
/**
* Get latest changes.
*

View File

@ -302,6 +302,19 @@ class IDF_Scm_Mercurial
return $out[0];
}
/**
* Get commit size.
*
* Get the sum of all the added/removed lines and the number of
* affected files.
*
* @param string Commit ('HEAD')
* @return array array(added, removed, affected)
*/
public function getCommitSize($commit='HEAD')
{
return array(0, 0, 0);
}
/**
* Get latest changes.

View File

@ -291,6 +291,20 @@ class IDF_Scm_Svn
return (object) $res;
}
/**
* Get commit size.
*
* Get the sum of all the added/removed lines and the number of
* affected files.
*
* @param string Commit ('HEAD')
* @return array array(added, removed, affected)
*/
public function getCommitSize($commit='HEAD')
{
return array(0, 0, 0);
}
private function getDiff($rev='HEAD')
{
$res = array();

View File

@ -216,7 +216,9 @@ class IDF_Views_Source
}
$title = sprintf(__('%s Commit Details'), (string) $request->project);
$page_title = sprintf(__('%s Commit Details - %s'), (string) $request->project, $commit);
$cobject = $scm->getCommit($commit, true);
$size = $scm->getCommitSize($commit);
$large = ($size[2] > 100 or ($size[0] + $size[1]) > 20000);
$cobject = $scm->getCommit($commit, !$large);
$rcommit = IDF_Commit::getOrAdd($cobject, $request->project);
$diff = new IDF_Diff($cobject->changes);
$diff->parse();
@ -231,6 +233,7 @@ class IDF_Views_Source
'branches' => $branches,
'scm' => $scmConf,
'rcommit' => $rcommit,
'large_commit' => $large,
),
$request);
}

View File

@ -31,10 +31,11 @@
<h2>{trans 'Change Details'}</h2>
{$diff.as_html()}
{/if}{if count($diff.files) or $large_commit}
{aurl 'url', 'IDF_Views_Source::downloadDiff', array($project.shortname, $commit)}
<p class="right soft"><a href="{$url}"><img style="vertical-align: text-bottom;" src="{media '/idf/img/package-grey.png'}" alt="{trans 'Archive'}" align="bottom" /></a> <a href="{$url}">{trans 'Download the corresponding diff file'}</a></p>
{/if}
{/block}
{block context}
{if $scm == 'git'}