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
19 * along with FusionForge; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24 class HgPlugin extends SCMPlugin {
25 function HgPlugin () {
28 $this->name = 'scmhg';
29 $this->text = 'Mercurial';
30 $this->hooks[] = 'scm_generate_snapshots' ;
32 require_once $gfconfig.'plugins/scmhg/config.php' ;
34 $this->default_hg_server = $default_hg_server ;
35 if (isset ($hg_root)) {
36 $this->hg_root = $hg_root;
38 $this->hg_root = forge_get_config('chroot').'/scmrepos/hg' ;
44 function getDefaultServer() {
45 return $this->default_hg_server ;
48 function getBlurb () {
49 return _('<p>This Mercurial plugin is not completed yet.</p>') ;
52 function getInstructionsForAnon ($project) {
53 $b = _('<p><b>Anonymous Mercurial Access</b></p><p>This project\'s Mercurial repository can be checked out through anonymous access with the following command.</p>');
55 $b .= '<tt>hg clone '.util_make_url ('/anonscm/hg/'.$project->getUnixName().'/').'</tt><br />';
60 function getInstructionsForRW ($project) {
61 if (session_loggedin()) {
62 $u =& user_get_object(user_getid()) ;
63 $d = $u->getUnixName() ;
64 $b = _('<p><b>Developer Mercurial Access via SSH</b></p><p>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.</p>');
65 $b .= '<p><tt>hg clone ssh://'.$d.'@' . $project->getSCMBox() . $this->hg_root .'/'. $project->getUnixName().'/ .</tt></p>' ;
67 $d = '<i>developername</i>';
68 $b = _('<p><b>Developer Mercurial Access via SSH</b></p><p>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.</p>');
69 $b .= '<p><tt>hg clone ssh://'.$d.'@' . $project->getSCMBox() . $this->hg_root .'/'. $project->getUnixName().'/ .</tt></p>' ;
74 function getSnapshotPara ($project) {
78 function getBrowserLinkBlock ($project) {
82 function getStatsBlock ($project) {
86 function createOrUpdateRepo ($params) {
87 $project = $this->checkParams ($params) ;
92 if (! $project->usesPlugin ($this->name)) {
96 $repo = $this->hg_root . '/' . $project->getUnixName() ;
97 $unix_group = 'scm_' . $project->getUnixName() ;
99 system ("mkdir -p $repo") ;
100 if (!is_dir ("$repo/.hg")) {
101 system ("hg init $repo") ;
102 system ("find $repo -type d | xargs chmod g+s") ;
105 system ("chgrp -R $unix_group $repo") ;
106 if ($project->enableAnonSCM()) {
107 system ("chmod -R g+wX,o+rX-w $repo") ;
109 system ("chmod -R g+wX,o-rwx $repo") ;
113 function generateSnapshots ($params) {
116 $project = $this->checkParams ($params) ;
121 $group_name = $project->getUnixName() ;
123 $tarball = forge_get_config('scm_tarballs_path').'/'.$group_name.'-scmroot.tar.gz';
125 if (! $project->usesPlugin ($this->name)) {
129 if (! $project->enableAnonSCM()) {
134 $toprepo = $this->hg_root ;
135 $repo = $toprepo . '/' . $project->getUnixName() ;
137 if (!is_dir ($repo)) {
142 $tmp = trim (`mktemp -d`) ;
146 system ("tar czCf $toprepo $tmp/tarball.tar.gz " . $project->getUnixName()) ;
147 chmod ("$tmp/tarball.tar.gz", 0644) ;
148 copy ("$tmp/tarball.tar.gz", $tarball) ;
149 unlink ("$tmp/tarball.tar.gz") ;
150 system ("rm -rf $tmp") ;
156 // c-file-style: "bsd"