diff --git a/src/IDF/Scm/Git.php b/src/IDF/Scm/Git.php index ebe0530..3ddaf5b 100644 --- a/src/IDF/Scm/Git.php +++ b/src/IDF/Scm/Git.php @@ -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. * diff --git a/src/IDF/Scm/Mercurial.php b/src/IDF/Scm/Mercurial.php index 24b0cf1..499f2ee 100644 --- a/src/IDF/Scm/Mercurial.php +++ b/src/IDF/Scm/Mercurial.php @@ -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. diff --git a/src/IDF/Scm/Svn.php b/src/IDF/Scm/Svn.php index 677e81a..02ee6a4 100644 --- a/src/IDF/Scm/Svn.php +++ b/src/IDF/Scm/Svn.php @@ -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(); diff --git a/src/IDF/Views/Source.php b/src/IDF/Views/Source.php index e5b4f1b..b2c9d92 100644 --- a/src/IDF/Views/Source.php +++ b/src/IDF/Views/Source.php @@ -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); } diff --git a/src/IDF/templates/idf/source/commit.html b/src/IDF/templates/idf/source/commit.html index 5e40c03..6e0eb6b 100644 --- a/src/IDF/templates/idf/source/commit.html +++ b/src/IDF/templates/idf/source/commit.html @@ -31,10 +31,11 @@

{trans 'Change Details'}

{$diff.as_html()} +{/if}{if count($diff.files) or $large_commit} {aurl 'url', 'IDF_Views_Source::downloadDiff', array($project.shortname, $commit)}

{trans 'Archive'} {trans 'Download the corresponding diff file'}

- {/if} + {/block} {block context} {if $scm == 'git'}