diff --git a/src/IDF/Project.php b/src/IDF/Project.php index 17887d9..515e8ae 100644 --- a/src/IDF/Project.php +++ b/src/IDF/Project.php @@ -31,9 +31,11 @@ class IDF_Project extends Pluf_Model { public $_model = __CLASS__; public $_extra_cache = array(); + protected $_pconf = null; function init() { + $this->_pconf = null; $this->_extra_cache = array(); $this->_a['table'] = 'idf_projects'; $this->_a['model'] = __CLASS__; @@ -89,7 +91,7 @@ class IDF_Project extends Pluf_Model return ''; } - + function preSave($create=false) { if ($this->id == '') { @@ -191,8 +193,7 @@ class IDF_Project extends Pluf_Model */ public function getTagsFromConfig($cfg_key, $default, $dclass='Other') { - $conf = new IDF_Conf(); - $conf->setProject($this); + $conf = $this->getConf(); $tags = array(); foreach (preg_split("/\015\012|\015|\012/", $conf->getVal($cfg_key, $default), -1, PREG_SPLIT_NO_EMPTY) as $s) { $_s = split('=', $s, 2); @@ -304,51 +305,18 @@ class IDF_Project extends Pluf_Model } /** - * Get the path to the git repository. + * Get the remote access url to the repository. * - * @return string Path to the git repository */ - public function getGitRepository() + public function getRemoteAccessUrl() { - $gitrep = Pluf::f('git_repository'); - if (substr($gitrep, -4) == '.git') { - return $gitrep; - } - // here we consider that the git_repository is a folder - // containing a series of git repositories - return $gitrep.'/'.$this->shortname.'.git'; + $conf = $this->getConf(); + $scm = $conf->getVal('scm', 'git'); + $scms = Pluf::f('allowed_scm'); + return call_user_func(array($scms[$scm], 'getRemoteAccessUrl'), + $this); } - /** - * Get the url to the repository through git daemon. - * - * @return string Path to the git daemon. - */ - public function getGitDaemonUrl() - { - $gitrep = Pluf::f('git_daemon_url'); - if (substr($gitrep, -4) == '.git') { - return $gitrep; - } - // here we consider that the git_repository is a folder - // containing a series of git repositories - return $gitrep.'/'.$this->shortname.'.git'; - } - - /** - * Get the path to the git repository. - * - * @return string Path to the git repository - */ - public function getSvnDaemonUrl() - { - $conf = new IDF_Conf(); - $conf->setProject($this); - - return $conf->getVal('svn_daemon_url'); - } - - /** * Get the root name of the project scm * @@ -356,9 +324,8 @@ class IDF_Project extends Pluf_Model */ public function getScmRoot() { + $conf = $this->getConf(); $roots = array('git' => 'master', 'svn' => 'HEAD'); - $conf = new IDF_Conf(); - $conf->setProject($this); $scm = $conf->getVal('scm', 'git'); return $roots[$scm]; } @@ -378,4 +345,19 @@ class IDF_Project extends Pluf_Model throw new Pluf_HTTP_Error404(); } } + + /** + * Utility function to get a configuration object. + * + * @return IDF_Conf + */ + public function getConf() + { + if ($this->_pconf == null) { + $this->_pconf = new IDF_Conf(); + $this->_pconf->setProject($this); + } + return $this->_pconf; + } + } \ No newline at end of file diff --git a/src/IDF/Scm.php b/src/IDF/Scm.php index 5889579..c104651 100644 --- a/src/IDF/Scm.php +++ b/src/IDF/Scm.php @@ -35,15 +35,10 @@ class IDF_Scm public static function get($request=null) { // Get scm type from project conf ; defaults to git - switch ($request->conf->getVal('scm', 'git')) { - case 'svn': - return new IDF_Scm_Svn($request->conf->getVal('svn_repository'), - $request->conf->getVal('svn_username'), - $request->conf->getVal('svn_password')); - case 'git': - default: - return new IDF_Scm_Git($request->project->getGitRepository()); - } + $scm = $request->conf->getVal('scm', 'git'); + $scms = Pluf::f('allowed_scm'); + return call_user_func(array($scms[$scm], 'factory'), + $request->project); } } diff --git a/src/IDF/Scm/Git.php b/src/IDF/Scm/Git.php index 09fb0f9..3f75b95 100644 --- a/src/IDF/Scm/Git.php +++ b/src/IDF/Scm/Git.php @@ -35,6 +35,35 @@ class IDF_Scm_Git $this->repo = $repo; } + /** + * Returns the URL of the git daemon. + * + * @param IDF_Project + * @return string URL + */ + public static function getRemoteAccessUrl($project) + { + $url = Pluf::f('git_remote_url'); + if (Pluf::f('git_repositories_unique', true)) { + return $url; + } + return $url.'/'.$project->shortname.'.git'; + } + + /** + * Returns this object correctly initialized for the project. + * + * @param IDF_Project + * @return IDF_Scm_Git + */ + public static function factory($project) + { + $rep = Pluf::f('git_repositories'); + if (false == Pluf::f('git_repositories_unique', false)) { + $rep = $rep.'/'.$project->shortname.'.git'; + } + return new IDF_Scm_Git($rep); + } /** * Test a given object hash. diff --git a/src/IDF/Scm/Svn.php b/src/IDF/Scm/Svn.php index e094d88..371834f 100644 --- a/src/IDF/Scm/Svn.php +++ b/src/IDF/Scm/Svn.php @@ -41,6 +41,49 @@ class IDF_Scm_Svn $this->password = $password; } + /** + * Returns the URL of the subversion repository. + * + * @param IDF_Project + * @return string URL + */ + public static function getRemoteAccessUrl($project) + { + $conf = $project->getConf(); + if (false !== ($url=$conf->getVal('svn_remote_url', false))) { + // Remote repository + return $url; + } + $url = Pluf::f('svn_remote_url'); + if (Pluf::f('svn_repositories_unique', true)) { + return $url; + } + return $url.'/'.$project->shortname; + } + + /** + * Returns this object correctly initialized for the project. + * + * @param IDF_Project + * @return IDF_Scm_Svn + */ + public static function factory($project) + { + $conf = $project->getConf(); + // Find the repository + if (false !== ($rep=$conf->getVal('svn_remote_url', false))) { + // Remote repository + return new IDF_Scm_Svn($rep, + $conf->getVal('svn_username'), + $conf->getVal('svn_password')); + } else { + $rep = Pluf::f('svn_repositories'); + if (false == Pluf::f('svn_repositories_unique', false)) { + $rep = $rep.'/'.$project->shortname; + } + return new IDF_Scm_Svn($rep); + } + } /** * Test a given object hash. diff --git a/src/IDF/conf/idf.php-dist b/src/IDF/conf/idf.php-dist index 35ae1fa..c268d22 100644 --- a/src/IDF/conf/idf.php-dist +++ b/src/IDF/conf/idf.php-dist @@ -29,19 +29,33 @@ $cfg['debug'] = false; // available languages $cfg['languages'] = array('en', 'fr'); +# SCM base configuration +$cfg['allowed_scm'] = array('git' => 'IDF_Scm_Git', + 'svn' => 'IDF_Scm_Svn', + ); + // if you have a single git repository, just put the full path to it // without trailing slash. // If within a folder you have a series of git repository, just put // the folder without a trailing slash. // InDefero will automatically append a slash, the project shortname // and .git to create the name of the repository. -// $cfg['git_repository'] = '/home/git/repositories'; -$cfg['git_repository'] = '/home/git/repositories/indefero.git'; +$cfg['git_repositories'] = '/home/git/repositories/indefero.git'; +$cfg['git_repositories_unique'] = true; +$cfg['git_remote_url'] = 'git://projects.ceondo.com/indefero.git'; + +// One git repository per project. "/".$project->shortname.".git" +// is automatically added to the end of the path/url. +//$cfg['git_repositories'] = '/home/git/repositories'; +//$cfg['git_repositories_unique'] = false; +//$cfg['git_remote_url'] = 'git://projects.ceondo.com'; + +// Same as for git, you can have multiple repositories, one for each +// project or a single one for all the projects. +$cfg['svn_repositories'] = 'file:///home/svn/repositories/indefero'; +$cfg['svn_repositories_unique'] = true; +$cfg['svn_remote_url'] = 'http://projects.ceondo.com/svn/indefero'; -// As for the 'git_repository' case, you can either have it ending -// with .git in the case of a single repository or let it append -// '/'.$project_shortname.'.git' to make the path. -$cfg['git_daemon_url'] = 'git://projects.ceondo.com/indefero.git'; // admins will get an email in case of errors in the system in non // debug mode. diff --git a/src/IDF/templates/source/git/tree.html b/src/IDF/templates/source/git/tree.html index a14dd66..f1235da 100644 --- a/src/IDF/templates/source/git/tree.html +++ b/src/IDF/templates/source/git/tree.html @@ -43,7 +43,7 @@ {aurl 'url', 'IDF_Views_Source::download', array($project.shortname, $commit)} -

{trans 'Archive'} {trans 'Download this version'} {trans 'or'} git clone {$project.getGitDaemonUrl()}

+

{trans 'Archive'} {trans 'Download this version'} {trans 'or'} git clone {$project.getRemoteAccessUrl()}

{/block} diff --git a/src/IDF/templates/source/svn/tree.html b/src/IDF/templates/source/svn/tree.html index b038287..5b25437 100644 --- a/src/IDF/templates/source/svn/tree.html +++ b/src/IDF/templates/source/svn/tree.html @@ -56,7 +56,7 @@ {/foreach} -

{trans 'Archive'} svn checkout {$project.getSvnDaemonUrl()}@{$commit}

+

svn co -r {$commit} {$project.getRemoteAccessUrl()}

{/block}