Restructured one more time to be as SCM independent as possible.
The work is delegated as much as possible to the IDF_Scm_* classes.
This commit is contained in:
parent
57a5b4738a
commit
2d271f6b69
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
|
@ -43,7 +43,7 @@
|
||||
</tbody>
|
||||
</table>
|
||||
{aurl 'url', 'IDF_Views_Source::download', 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 this version'}</a> {trans 'or'} <kbd>git clone {$project.getGitDaemonUrl()}</kbd></p>
|
||||
<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 this version'}</a> {trans 'or'} <kbd>git clone {$project.getRemoteAccessUrl()}</kbd></p>
|
||||
|
||||
|
||||
{/block}
|
||||
|
@ -56,7 +56,7 @@
|
||||
{/foreach}
|
||||
</tbody>
|
||||
</table>
|
||||
<p class="right soft"><img style="vertical-align: text-bottom;" src="{media '/idf/img/package-grey.png'}" alt="{trans 'Archive'}" align="bottom" /> <kbd>svn checkout {$project.getSvnDaemonUrl()}@{$commit}</kbd></p>
|
||||
<p class="right soft"><kbd>svn co -r {$commit} {$project.getRemoteAccessUrl()}</kbd></p>
|
||||
|
||||
|
||||
{/block}
|
||||
|
Loading…
Reference in New Issue
Block a user