2 /** FusionForge Mercurial (Hg) plugin
4 * Copyright 2009, Roland Mas
6 * This file is part of FusionForge.
8 * FusionForge is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published
10 * by the Free Software Foundation; either version 2 of the License,
11 * or (at your option) any later version.
13 * FusionForge is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 forge_define_config_item ('default_server', 'scmhg', forge_get_config ('web_host')) ;
24 forge_define_config_item ('repos_path', 'scmhg', forge_get_config('chroot').'/scmrepos/hg') ;
26 class HgPlugin extends SCMPlugin {
27 function HgPlugin () {
30 $this->name = 'scmhg';
31 $this->text = 'Mercurial';
32 $this->hooks[] = 'scm_generate_snapshots' ;
37 function getDefaultServer() {
38 return forge_get_config('default_server', 'scmhg') ;
41 function getBlurb () {
42 return '<p>' . _('This Mercurial plugin is not completed yet.') . '</p>';
45 function getInstructionsForAnon ($project) {
47 $b .= _('Anonymous Mercurial Access');
50 $b .= 'This project\'s Mercurial repository can be checked out through anonymous access with the following command.';
53 $b .= '<tt>hg clone '.util_make_url ('/anonscm/hg/'.$project->getUnixName().'/').'</tt><br />';
58 function getInstructionsForRW ($project) {
59 if (session_loggedin()) {
60 $u =& user_get_object(user_getid()) ;
61 $d = $u->getUnixName() ;
63 $b .= _('Developer Mercurial Access via SSH');
66 $b .= _('Only project developers can access the Mercurial tree via this method. SSH must be installed on your client machine. Enter your site password when prompted.');
68 $b .= '<p><tt>hg clone ssh://'.$d.'@' . $this->getBoxForProject($project) .'/'. forge_get_config('repos_path', 'scmhg') .'/'. $project->getUnixName().'/ .</tt></p>' ;
70 $d = '<i>developername</i>';
72 $b .= _('Developer Mercurial Access via SSH');
75 $b .= _('Only project developers can access the Mercurial tree via this method. SSH must be installed on your client machine. Substitute <i>developername</i> with the proper value. Enter your site password when prompted.');
77 $b .= '<p><tt>hg clone ssh://'.$d.'@' . $this->getBoxForProject($project) .'/'. forge_get_config('repos_path', 'scmhg') .'/'. $project->getUnixName().'/ .</tt></p>' ;
82 function getSnapshotPara ($project) {
86 function getBrowserLinkBlock ($project) {
90 function getStatsBlock ($project) {
94 function createOrUpdateRepo ($params) {
95 $project = $this->checkParams ($params) ;
100 if (! $project->usesPlugin ($this->name)) {
104 $repo = forge_get_config('repos_path', 'scmhg') . '/' . $project->getUnixName() ;
105 $unix_group = 'scm_' . $project->getUnixName() ;
107 system ("mkdir -p $repo") ;
108 if (!is_dir ("$repo/.hg")) {
109 system ("hg init $repo") ;
110 system ("find $repo -type d | xargs chmod g+s") ;
113 system ("chgrp -R $unix_group $repo") ;
114 if ($project->enableAnonSCM()) {
115 system ("chmod -R g+wX,o+rX-w $repo") ;
117 system ("chmod -R g+wX,o-rwx $repo") ;
121 function generateSnapshots ($params) {
123 $project = $this->checkParams ($params) ;
128 $group_name = $project->getUnixName() ;
130 $tarball = forge_get_config('scm_tarballs_path').'/'.$group_name.'-scmroot.tar'.util_get_compressed_file_extension();
132 if (! $project->usesPlugin ($this->name)) {
136 if (! $project->enableAnonSCM()) {
141 $toprepo = forge_get_config('repos_path', 'scmhg') ;
142 $repo = $toprepo . '/' . $project->getUnixName() ;
144 if (!is_dir ($repo)) {
149 $tmp = trim (`mktemp -d`) ;
153 system ("tar cCf $toprepo - ".$project->getUnixName() ."|".forge_get_config('compression_method')."> $tmp/tarball") ;
154 chmod ("$tmp/tarball", 0644) ;
155 copy ("$tmp/tarball", $tarball) ;
156 unlink ("$tmp/tarball") ;
157 system ("rm -rf $tmp") ;
163 // c-file-style: "bsd"