* idf.php-dist: improve the document of the various mtn-related configure options; introduce an option to configure the protocole - separate from the url option, which we now name mtn_remote_host

* IDF_Project: optionally give getSourceAccessUrl() a commit argument, so a particular VCS module can determine a subset of revisions to pull for the specific revision which is browsed
* IDF_Scm_*: add the argument null'd for all VCS; implement a branch lookup for monotone
* tree.html: display the correct branch to clone under each revision tree
This commit is contained in:
Thomas Keller 2010-05-02 00:56:04 +02:00
parent 3b53ceedcd
commit 59ad0f5b11
7 changed files with 176 additions and 107 deletions

View File

@ -381,15 +381,16 @@ class IDF_Project extends Pluf_Model
* This will return the right url based on the user. * This will return the right url based on the user.
* *
* @param Pluf_User The user (null) * @param Pluf_User The user (null)
* @param string A specific commit to access
*/ */
public function getSourceAccessUrl($user=null) public function getSourceAccessUrl($user=null, $commit=null)
{ {
$right = $this->getConf()->getVal('source_access_rights', 'all'); $right = $this->getConf()->getVal('source_access_rights', 'all');
if (($user == null or $user->isAnonymous()) if (($user == null or $user->isAnonymous())
and $right == 'all' and !$this->private) { and $right == 'all' and !$this->private) {
return $this->getRemoteAccessUrl(); return $this->getRemoteAccessUrl($commit);
} }
return $this->getWriteRemoteAccessUrl($user); return $this->getWriteRemoteAccessUrl($user, $commit);
} }
@ -397,15 +398,17 @@ class IDF_Project extends Pluf_Model
* Get the remote access url to the repository. * Get the remote access url to the repository.
* *
* This will always return the anonymous access url. * This will always return the anonymous access url.
*
* @param string A specific commit to access
*/ */
public function getRemoteAccessUrl() public function getRemoteAccessUrl($commit=null)
{ {
$conf = $this->getConf(); $conf = $this->getConf();
$scm = $conf->getVal('scm', 'git'); $scm = $conf->getVal('scm', 'git');
$scms = Pluf::f('allowed_scm'); $scms = Pluf::f('allowed_scm');
Pluf::loadClass($scms[$scm]); Pluf::loadClass($scms[$scm]);
return call_user_func(array($scms[$scm], 'getAnonymousAccessUrl'), return call_user_func(array($scms[$scm], 'getAnonymousAccessUrl'),
$this); $this, $commit);
} }
/** /**
@ -414,14 +417,16 @@ class IDF_Project extends Pluf_Model
* Some SCM have a remote access URL to write which is not the * Some SCM have a remote access URL to write which is not the
* same as the one to read. For example, you do a checkout with * same as the one to read. For example, you do a checkout with
* git-daemon and push with SSH. * git-daemon and push with SSH.
*
* @param string A specific commit to access
*/ */
public function getWriteRemoteAccessUrl($user) public function getWriteRemoteAccessUrl($user,$commit=null)
{ {
$conf = $this->getConf(); $conf = $this->getConf();
$scm = $conf->getVal('scm', 'git'); $scm = $conf->getVal('scm', 'git');
$scms = Pluf::f('allowed_scm'); $scms = Pluf::f('allowed_scm');
return call_user_func(array($scms[$scm], 'getAuthAccessUrl'), return call_user_func(array($scms[$scm], 'getAuthAccessUrl'),
$this, $user); $this, $user, $commit);
} }
/** /**

View File

@ -270,12 +270,12 @@ class IDF_Scm_Git extends IDF_Scm
return null; return null;
} }
public static function getAnonymousAccessUrl($project) public static function getAnonymousAccessUrl($project, $commit=null)
{ {
return sprintf(Pluf::f('git_remote_url'), $project->shortname); return sprintf(Pluf::f('git_remote_url'), $project->shortname);
} }
public static function getAuthAccessUrl($project, $user) public static function getAuthAccessUrl($project, $user, $commit=null)
{ {
return sprintf(Pluf::f('git_write_remote_url'), $project->shortname); return sprintf(Pluf::f('git_write_remote_url'), $project->shortname);
} }

View File

@ -77,12 +77,12 @@ class IDF_Scm_Mercurial extends IDF_Scm
return 'tip'; return 'tip';
} }
public static function getAnonymousAccessUrl($project) public static function getAnonymousAccessUrl($project, $commit=null)
{ {
return sprintf(Pluf::f('mercurial_remote_url'), $project->shortname); return sprintf(Pluf::f('mercurial_remote_url'), $project->shortname);
} }
public static function getAuthAccessUrl($project, $user) public static function getAuthAccessUrl($project, $user, $commit=null)
{ {
return sprintf(Pluf::f('mercurial_remote_url'), $project->shortname); return sprintf(Pluf::f('mercurial_remote_url'), $project->shortname);
} }

View File

@ -61,7 +61,6 @@ class IDF_Scm_Monotone_Stdio
$descriptors = array( $descriptors = array(
0 => array("pipe", "r"), 0 => array("pipe", "r"),
1 => array("pipe", "w"), 1 => array("pipe", "w"),
2 => array("pipe", "r")
); );
$this->proc = proc_open($cmd, $descriptors, $this->pipes); $this->proc = proc_open($cmd, $descriptors, $this->pipes);
@ -83,14 +82,43 @@ class IDF_Scm_Monotone_Stdio
fclose($this->pipes[0]); fclose($this->pipes[0]);
fclose($this->pipes[1]); fclose($this->pipes[1]);
fclose($this->pipes[2]);
proc_close($this->proc); proc_close($this->proc);
$this->proc = null; $this->proc = null;
} }
private function _waitForReadyRead()
{
if (!is_resource($this->pipes[1]))
return false;
$read = array($this->pipes[1]);
$write = null;
$except = null;
$streamsChanged = stream_select(
$read, $write, $except, 0, 20000
);
if ($streamsChanged === false)
{
throw new IDF_Scm_Exception(
"Could not select() on read pipe"
);
}
if ($streamsChanged == 0)
{
return false;
}
return true;
}
private function _checkVersion() private function _checkVersion()
{ {
$this->_waitForReadyRead();
$version = fgets($this->pipes[1]); $version = fgets($this->pipes[1]);
if (!preg_match('/^format-version: (\d+)$/', $version, $m) || if (!preg_match('/^format-version: (\d+)$/', $version, $m) ||
$m[1] != self::$SUPPORTED_STDIO_VERSION) $m[1] != self::$SUPPORTED_STDIO_VERSION)
@ -100,6 +128,7 @@ class IDF_Scm_Monotone_Stdio
self::$SUPPORTED_STDIO_VERSION."', got '".@$m[1]."'" self::$SUPPORTED_STDIO_VERSION."', got '".@$m[1]."'"
); );
} }
fgets($this->pipes[1]); fgets($this->pipes[1]);
} }
@ -151,25 +180,8 @@ class IDF_Scm_Monotone_Stdio
while (true) while (true)
{ {
$read = array($this->pipes[1]); if (!$this->_waitForReadyRead())
$write = null;
$except = null;
$streamsChanged = stream_select(
$read, $write, $except, 0, 20000
);
if ($streamsChanged === false)
{
throw new IDF_Scm_Exception(
"Could not select() on read pipe"
);
}
if ($streamsChanged == 0)
{
continue; continue;
}
$data = array(0,"",0); $data = array(0,"",0);
$idx = 0; $idx = 0;
@ -669,18 +681,50 @@ class IDF_Scm_Monotone extends IDF_Scm
return $branch; return $branch;
} }
public static function getAnonymousAccessUrl($project) public static function getAnonymousAccessUrl($project, $commit = null)
{ {
$branch = self::_getMasterBranch($project);
if (!empty($commit))
{
$scm = IDF_Scm::get($project);
$revs = $scm->_resolveSelector($commit);
if (count($revs) > 0)
{
$certs = $scm->_getCerts($revs[0]);
// for the very seldom case that a revision
// has no branch certificate
if (count($certs['branch']) == 0)
{
$branch = "*";
}
else
{
$branch = $certs['branch'][0];
}
}
}
$protocol = Pluf::f('mtn_remote_protocol', 'netsync');
if ($protocol == "ssh")
{
// ssh is protocol + host + db-path + branch
return "ssh://" .
sprintf(Pluf::f('mtn_remote_host'), $project->shortname) .
sprintf(Pluf::f('mtn_repositories'), $project->shortname) .
" " . $branch;
}
// netsync is the default
return sprintf( return sprintf(
Pluf::f('mtn_remote_url'), Pluf::f('mtn_remote_host'),
$project->shortname, $project->shortname
self::_getMasterBranch($project) )." ".$branch;
);
} }
public static function getAuthAccessUrl($project, $user) public static function getAuthAccessUrl($project, $user, $commit = null)
{ {
return self::getAnonymousAccessUrl($project); return self::getAnonymousAccessUrl($project, $commit);
} }
/** /**

View File

@ -80,9 +80,10 @@ class IDF_Scm_Svn extends IDF_Scm
* Returns the URL of the subversion repository. * Returns the URL of the subversion repository.
* *
* @param IDF_Project * @param IDF_Project
* @param string
* @return string URL * @return string URL
*/ */
public static function getAnonymousAccessUrl($project) public static function getAnonymousAccessUrl($project,$commit=null)
{ {
$conf = $project->getConf(); $conf = $project->getConf();
if (false !== ($url=$conf->getVal('svn_remote_url', false)) if (false !== ($url=$conf->getVal('svn_remote_url', false))
@ -97,9 +98,10 @@ class IDF_Scm_Svn extends IDF_Scm
* Returns the URL of the subversion repository. * Returns the URL of the subversion repository.
* *
* @param IDF_Project * @param IDF_Project
* @param string
* @return string URL * @return string URL
*/ */
public static function getAuthAccessUrl($project, $user) public static function getAuthAccessUrl($project, $user, $commit=null)
{ {
$conf = $project->getConf(); $conf = $project->getConf();
if (false !== ($url=$conf->getVal('svn_remote_url', false)) if (false !== ($url=$conf->getVal('svn_remote_url', false))

View File

@ -73,11 +73,29 @@ $cfg['git_write_remote_url'] = 'git@localhost:%s.git';
$cfg['svn_repositories'] = 'file:///home/svn/repositories/%s'; $cfg['svn_repositories'] = 'file:///home/svn/repositories/%s';
$cfg['svn_remote_url'] = 'http://localhost/svn/%s'; $cfg['svn_remote_url'] = 'http://localhost/svn/%s';
# Same as for git, you can have multiple repositories, one for each # Path to the monotone binary
# project or a single one for all the projects.
$cfg['mtn_path'] = 'mtn'; $cfg['mtn_path'] = 'mtn';
# Same as for git, you can have multiple repositories, one for each
# project or a single one for all the projects. Beware though that
# if you want to setup separate write access for the projects, you
# you have to setup different databases for each one.
#
# To access an mtn repository remotely you have two possibilities,
# via ssh and monotone's own netsync protocol. Usually each repository
# has to serve its contents in a separate process, but there exists a tool,
# called "usher", which acts as single entry point and distributes incoming
# requests further, based either on a particular branch pattern or configured
# host name (similar to SNI, the Server Name Indication, of TLS).
#
# A full HOWTO set this up is beyond this scope, please refer to the
# documentation of monotone and / or ask on their mailing list / IRC channel
# (irc.oftc.net/#monotone)
$cfg['mtn_repositories'] = '/home/mtn/repositories/%s.mtn'; $cfg['mtn_repositories'] = '/home/mtn/repositories/%s.mtn';
$cfg['mtn_remote_url'] = 'mtn://localhost/~%s/%s'; # The preferred URL with which people can access this service. The placeholder
# denotes the unique project name which could be used as distinguishable SNI.
$cfg['mtn_remote_host'] = '%s.my.host.com';
# Possible values 'ssh' and 'netsync'
$cfg['mtn_remote_protocol'] = 'netsync';
# Mercurial repositories path # Mercurial repositories path
#$cfg['mercurial_repositories'] = '/home/mercurial/repositories/%s'; #$cfg['mercurial_repositories'] = '/home/mercurial/repositories/%s';

View File

@ -49,7 +49,7 @@
{aurl 'url', 'IDF_Views_Source::download', array($project.shortname, $commit)} {aurl 'url', 'IDF_Views_Source::download', array($project.shortname, $commit)}
<p class="right soft"> <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'} *} {* <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>mtn clone {$project.getSourceAccessUrl($user)}</kbd> <a href="{url 'IDF_Views_Source::help', array($project.shortname)}"><img style="vertical-align: text-bottom;" src="{media '/idf/img/help.png'}" alt="{trans 'Help'}" /></a> <kbd>mtn clone {$project.getSourceAccessUrl($user, $commit)}</kbd> <a href="{url 'IDF_Views_Source::help', array($project.shortname)}"><img style="vertical-align: text-bottom;" src="{media '/idf/img/help.png'}" alt="{trans 'Help'}" /></a>
</p> </p>