/** FusionForge Git plugin
*
* Copyright 2009, Roland Mas
+ * Copyright 2009, Mehdi Dogguy <mehdi@debian.org>
*
* This file is part of FusionForge.
*
function getInstructionsForAnon ($project) {
$b = _('<p><b>Anonymous Git Access</b></p><p>This project\'s Git repository can be checked out through anonymous access with the following command.</p>');
$b .= '<p>' ;
- $b .= '<tt>git clone '.util_make_url ('/anonscm/git/'.$project->getUnixName()).'</tt><br />';
+ $b .= '<tt>git clone '.util_make_url ('/anonscm/git/'.$project->getUnixName().'/'.$project->getUnixName().'.git').'</tt><br />';
$b .= '</p>';
+
+ $result = db_query_params ('SELECT u.user_id, u.user_name, u.realname FROM plugin_scmgit_personal_repos p, users u WHERE p.group_id=$1 AND u.user_id=p.user_id AND u.unix_status=$2',
+ array ($project->getID(),
+ 'A')) ;
+ $rows = db_numrows ($result) ;
+
+ if ($rows > 0) {
+ $b .= ngettext ('<p><b>Developer\'s repository</b></p><p>One of this project\'s members also has a personal Git repository that can be checked out anonymously.</p>',
+ '<p><b>Developers\' repositories</b></p><p>Some of this project\'s members also have personal Git repositories that can be checked out anonymously.</p>',
+ $rows);
+ $b .= '<p>' ;
+ for ($i=0; $i<$rows; $i++) {
+ $user_id = db_result($result,$i,'user_id');
+ $user_name = db_result($result,$i,'user_name');
+ $real_name = db_result($result,$i,'realname');
+ $b .= '<tt>git clone '.util_make_url ('/anonscm/git/'.$project->getUnixName().'/users/'.$user_name.'.git').'</tt> ('.util_make_link_u ($user_name, $user_id, $real_name).')<br />';
+ }
+ $b .= '</p>';
+ }
+
return $b ;
}
function getInstructionsForRW ($project) {
- $b = _('<p><b>Developer GIT Access via SSH</b></p><p>Only project developers can access the GIT tree via this method. SSH must be installed on your client machine. Substitute <i>developername</i> with the proper values. Enter your site password when prompted.</p>');
- $b .= '<p><tt>git clone git+ssh://<i>'._('developername').'</i>@' . $project->getSCMBox() . $this->git_root .'/'. $project->getUnixName().'</tt></p>' ;
+ if (session_loggedin()) {
+ $u =& user_get_object(user_getid()) ;
+ $d = $u->getUnixName() ;
+ $b = _('<p><b>Developer GIT Access via SSH</b></p><p>Only project developers can access the GIT tree via this method. SSH must be installed on your client machine. Enter your site password when prompted.</p>');
+ $b .= '<p><tt>git clone git+ssh://'.$d.'@' . $project->getSCMBox() . $this->git_root .'/'. $project->getUnixName() .'/'. $project->getUnixName() .'.git</tt></p>' ;
+ } else {
+ $b = _('<p><b>Developer GIT Access via SSH</b></p><p>Only project developers can access the GIT 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>');
+ $b .= '<p><tt>git clone git+ssh://<i>'._('developername').'</i>@' . $project->getSCMBox() . $this->git_root .'/'. $project->getUnixName() .'/'. $project->getUnixName() .'.git</tt></p>' ;
+
+ if (session_loggedin()) {
+ $u =& user_get_object(user_getid()) ;
+ if ($u->getUnixStatus() == 'A') {
+ $result = db_query_params ('SELECT * FROM plugin_scmgit_personal_repos p WHERE p.group_id=$1 AND p.user_id=$2',
+ array ($project->getID(),
+ $u->getID())) ;
+ if ($result && db_numrows ($result) > 0) {
+ $b .= _('<p><b>Access to your personal repository</b></p><p>You have a personal repository for this project, accessible through SSH with the following method. Enter your site password when prompted.</p>');
+ $b .= '<p><tt>git clone git+ssh://'.$u->getUnixName().'@' . $project->getSCMBox() . $this->git_root .'/'. $project->getUnixName() .'/users/'. $u->getUnixName() .'.git</tt></p>' ;
+ } else {
+ $glist = $u->getGroups();
+ foreach ($glist as $g) {
+ if ($g->getID() == $project->getID()) {
+ $b .= sprintf (_('<p><b>Request a personal repository</b></p><p>You can clone the project repository into a personal one into which you alone will be able to write. Other members of the project will only have read access. Access for non-members will follow the same rules as for the project\'s main repository. Note that the personal repository may take some time before it is created (less than an hour in most situations).</p><p><a href="$s">Request a personal repository</a>.</p>'),
+ util_make_url ('/plugins/scmgit/index.php?func=request-personal-repo&group_id='.$project->getID()));
+ }
+ }
+ }
+ }
+ }
+
return $b ;
}
// '<td width="25%" align="right"><strong>'.$total['commits'].'</strong></td>';
// $b .= '</tr>';
// $b .= $HTML->listTableBottom();
-// $b .= '<hr size="1" />';
// }
// return $b ;
$project_name = $project->getUnixName() ;
$root = $this->git_root . '/' . $project_name ;
- $repo = $root . '/' . $project_name . '.git' ;
$unix_group = 'scm_' . $project_name ;
-
- system ("mkdir -p $repo") ;
- if (!is_file ("$repo/HEAD") && !is_dir("$repo/objects") && !is_dir("$repo/refs")) {
- system ("GIT_DIR=\"$repo\" git init --bare --shared=group") ;
- system ("GIT_DIR=\"$repo\" git update-server-info") ;
- if (is_file ("$repo/hooks/post-update.sample")) {
- rename ("$repo/hooks/post-update.sample",
- "$repo/hooks/post-update") ;
+ system ("mkdir -p $root") ;
+
+ $main_repo = $root . '/' . $project_name . '.git' ;
+ if (!is_file ("$main_repo/HEAD") && !is_dir("$main_repo/objects") && !is_dir("$main_repo/refs")) {
+ system ("GIT_DIR=\"$main_repo\" git init --bare --shared=group") ;
+ system ("GIT_DIR=\"$main_repo\" git update-server-info") ;
+ if (is_file ("$main_repo/hooks/post-update.sample")) {
+ rename ("$main_repo/hooks/post-update.sample",
+ "$main_repo/hooks/post-update") ;
}
- if (!is_file ("$repo/hooks/post-update")) {
- $f = fopen ("$repo/hooks/post-update") ;
+ if (!is_file ("$main_repo/hooks/post-update")) {
+ $f = fopen ("$main_repo/hooks/post-update") ;
fwrite ($f, "exec git-update-server-info\n") ;
fclose ($f) ;
}
- if (is_file ("$repo/hooks/post-update")) {
- system ("chmod +x $repo/hooks/post-update") ;
+ if (is_file ("$main_repo/hooks/post-update")) {
+ system ("chmod +x $main_repo/hooks/post-update") ;
}
- system ("echo \"Git repository for $project_name\" > $repo/description") ;
- system ("find $repo -type d | xargs chmod g+s") ;
+ system ("echo \"Git repository for $project_name\" > $main_repo/description") ;
+ system ("find $main_repo -type d | xargs chmod g+s") ;
}
-
system ("chgrp -R $unix_group $root") ;
+ system ("chmod g+s $root") ;
if ($project->enableAnonSCM()) {
- system ("chmod -R g+wX,o+rX-w $root") ;
- system ("find $root -type d -print0 | xargs --null chmod g+s");
+ system ("chmod g+wX,o+rX-w $root") ;
+ system ("chmod -R g+wX,o+rX-w $main_repo") ;
} else {
- system ("chmod -R g+wX,o-rwx $root") ;
- system ("find $root -type d -print0 | xargs --null chmod g+s");
+ system ("chmod g+wX,o-rwx $root") ;
+ system ("chmod -R g+wX,o-rwx $main_repo") ;
+ }
+
+ $result = db_query_params ('SELECT u.user_name FROM plugin_scmgit_personal_repos p, users u WHERE p.group_id=$1 AND u.user_id=p.user_id AND u.unix_status=$2',
+ array ($project->getID(),
+ 'A')) ;
+ $rows = db_numrows ($result) ;
+ for ($i=0; $i<$rows; $i++) {
+ system ("mkdir -p $root/users") ;
+ $user_name = db_result($result,$i,'user_name');
+ $repodir = $root . '/users/' . $user_name . '.git' ;
+
+ if (!is_file ("$repodir/HEAD") && !is_dir("$repodir/objects") && !is_dir("$repodir/refs")) {
+ system ("git clone --bare $main_repo $repodir") ;
+ system ("GIT_DIR=\"$repodir\" git update-server-info") ;
+ system ("echo \"Git repository for user $owner in project $project_name\" > $repodir/description") ;
+ system ("chown -R $user_name:$unix_group $repodir") ;
+ }
+ }
+ if (is_dir ("$root/users")) {
+ if ($project->enableAnonSCM()) {
+ system ("chmod -R g+rX-w,o+rX-w $root/users") ;
+ } else {
+ system ("chmod -R g+rX-w,o-rwx $root/users") ;
+ }
}
}
return false ;
}
- system ("git archive --format=tar --prefix=$group_name-scm-$today/ HEAD | gzip > $tmp/snapshot.tar.gz");
+ system ("GIT_DIR=\"$repo\" git archive --format=tar --prefix=$group_name-scm-$today/ HEAD | gzip > $tmp/snapshot.tar.gz");
chmod ("$tmp/snapshot.tar.gz", 0644) ;
copy ("$tmp/snapshot.tar.gz", $snapshot) ;
unlink ("$tmp/snapshot.tar.gz") ;
$adds = 0 ;
$updates = 0 ;
- $repo = $this->git_root . '/' . $project->getUnixName() ;
+ $repo = $this->git_root . '/' . $project->getUnixName() . '/' . $project->getUnixName() . '.git';
if (!is_dir ($repo) || !is_dir ("$repo/refs")) {
// echo "No repository\n" ;
db_rollback () ;
return false ;
}
- $pipe = popen ("GIT_DIR=$repo git log --since=@$start_time --until=@$end_time --all --pretty='format:%n%an <%ae>' --name-status", 'r' ) ;
+ $pipe = popen ("GIT_DIR=\"$repo\" git log --since=@$start_time --until=@$end_time --all --pretty='format:%n%an <%ae>' --name-status", 'r' ) ;
// cleaning stats_cvs_* table for the current day
$res = db_query_params ('DELETE FROM stats_cvs_group WHERE month=$1 AND day=$2 AND group_id=$3',
}
// inserting group results in stats_cvs_groups
- if (!db_query_params ('INSERT INTO stats_cvs_group (month,day,group_id,checkouts,commits,adds) VALUES ($1,$2,$3,$4,$5,$6)',
- array ($month_string,
- $day,
- $project->getID(),
- 0,
- $updates,
- $adds))) {
- echo "Error while inserting into stats_cvs_group\n" ;
- db_rollback () ;
- return false ;
+ if ($updates > 0 || $adds > 0) {
+ if (!db_query_params ('INSERT INTO stats_cvs_group (month,day,group_id,checkouts,commits,adds) VALUES ($1,$2,$3,$4,$5,$6)',
+ array ($month_string,
+ $day,
+ $project->getID(),
+ 0,
+ $updates,
+ $adds))) {
+ echo "Error while inserting into stats_cvs_group\n" ;
+ db_rollback () ;
+ return false ;
+ }
}
// building the user list
continue;
}
- if (!db_query_params ('INSERT INTO stats_cvs_user (month,day,group_id,user_id,commits,adds) VALUES ($1,$2,$3,$4,$5,$6)',
- array ($month_string,
- $day,
- $project->getID(),
- $user_id,
- $usr_updates[$user] ? $usr_updates[$user] : 0,
- $usr_adds[$user] ? $usr_adds[$user] : 0))) {
- echo "Error while inserting into stats_cvs_user\n" ;
- db_rollback () ;
- return false ;
+ $uu = $usr_updates[$user] ? $usr_updates[$user] : 0 ;
+ $ua = $usr_adds[$user] ? $usr_adds[$user] : 0 ;
+ if ($uu > 0 || $ua > 0) {
+ if (!db_query_params ('INSERT INTO stats_cvs_user (month,day,group_id,user_id,commits,adds) VALUES ($1,$2,$3,$4,$5,$6)',
+ array ($month_string,
+ $day,
+ $project->getID(),
+ $user_id,
+ $uu,
+ $ua))) {
+ echo "Error while inserting into stats_cvs_user\n" ;
+ db_rollback () ;
+ return false ;
+ }
}
}
}