diff --git a/src/IDF/Project.php b/src/IDF/Project.php index 7c0f37b..1c5b1ef 100644 --- a/src/IDF/Project.php +++ b/src/IDF/Project.php @@ -350,6 +350,24 @@ class IDF_Project extends Pluf_Model } /** + * Get the repository size. + * + * @param bool Force to skip the cache (false) + * @return int Size in byte or -1 if not available + */ + public function getRepositorySize($force=false) + { + $last_eval = $this->getConf()->getVal('repository_size_check_date', 0); + if (!$force and $last_eval > time()-86400) { + return $this->getConf()->getVal('repository_size', -1); + } + $scm = IDF_Scm::get($this); + $this->getConf()->setVal('repository_size', $scm->getRepositorySize()); + $this->getConf()->setVal('repository_size_check_date', time()); + return $this->getConf()->getVal('repository_size', -1); + } + + /** * Get the access url to the repository. * * This will return the right url based on the user. diff --git a/src/IDF/Scm.php b/src/IDF/Scm.php index c027fbc..9a8cbac 100644 --- a/src/IDF/Scm.php +++ b/src/IDF/Scm.php @@ -88,6 +88,16 @@ class IDF_Scm } /** + * Return the size of the repository in bytes. + * + * @return int Size in byte, -1 if the size cannot be evaluated. + */ + public function getRepositorySize() + { + return -1; + } + + /** * Returns the URL of the git daemon. * * @param IDF_Project diff --git a/src/IDF/Scm/Git.php b/src/IDF/Scm/Git.php index 71a4714..58792cc 100644 --- a/src/IDF/Scm/Git.php +++ b/src/IDF/Scm/Git.php @@ -41,6 +41,14 @@ class IDF_Scm_Git extends IDF_Scm $this->project = $project; } + public function getRepositorySize() + { + $cmd = Pluf::f('idf_exec_cmd_prefix', '').'du -bs ' + .escapeshellarg($this->repo); + $out = split(' ', shell_exec($cmd), 2); + return (int) $out[0]; + } + public function isAvailable() { try { diff --git a/src/IDF/Scm/Mercurial.php b/src/IDF/Scm/Mercurial.php index 5861e97..998e909 100644 --- a/src/IDF/Scm/Mercurial.php +++ b/src/IDF/Scm/Mercurial.php @@ -33,6 +33,14 @@ class IDF_Scm_Mercurial extends IDF_Scm $this->project = $project; } + public function getRepositorySize() + { + $cmd = Pluf::f('idf_exec_cmd_prefix', '').'du -bs ' + .escapeshellarg($this->repo); + $out = split(' ', shell_exec($cmd), 2); + return (int) $out[0]; + } + public static function factory($project) { $rep = sprintf(Pluf::f('mercurial_repositories'), $project->shortname); diff --git a/src/IDF/Scm/Svn.php b/src/IDF/Scm/Svn.php index c9e1737..00ab6d2 100644 --- a/src/IDF/Scm/Svn.php +++ b/src/IDF/Scm/Svn.php @@ -51,6 +51,17 @@ class IDF_Scm_Svn extends IDF_Scm return true; } + public function getRepositorySize() + { + if (strpos($this->repo, 'file://') !== 0) { + return -1; + } + $cmd = Pluf::f('idf_exec_cmd_prefix', '').'du -bs ' + .escapeshellarg(substr($this->repo, 7)); + $out = split(' ', shell_exec($cmd), 2); + return (int) $out[0]; + } + /** * Given the string describing the author from the log find the * author in the database. diff --git a/src/IDF/Views/Project.php b/src/IDF/Views/Project.php index 409faf5..60710d5 100644 --- a/src/IDF/Views/Project.php +++ b/src/IDF/Views/Project.php @@ -510,6 +510,7 @@ class IDF_Views_Project 'remote_svn' => $remote_svn, 'repository_access' => $prj->getRemoteAccessUrl(), 'repository_type' => $repository_type, + 'repository_size' => $prj->getRepositorySize(), 'page_title' => $title, 'form' => $form, ), diff --git a/src/IDF/templates/idf/admin/source.html b/src/IDF/templates/idf/admin/source.html index 27612ab..5fba9ef 100644 --- a/src/IDF/templates/idf/admin/source.html +++ b/src/IDF/templates/idf/admin/source.html @@ -20,7 +20,12 @@ {trans 'Repository access:'} {$repository_access} -{if $remote_svn} +{if $repository_size != -1} + +{trans 'Repository size:'} +{$repository_size|size} + +{/if}{if $remote_svn} {$form.f.svn_username.labelTag}: {if $form.f.svn_username.errors}{$form.f.svn_username.fieldErrors}{/if}