<?php
-/** FusionForge Git plugin
+/**
+ * FusionForge Git plugin
*
* Copyright 2009, Roland Mas
* Copyright 2009, Mehdi Dogguy <mehdi@debian.org>
+ * Copyright 2012, Franck Villaume - TrivialDev
+ * http://fusionforge.org
*
* This file is part of FusionForge.
*
$d = $u->getUnixName();
if (forge_get_config('use_ssh', 'scmgit')) {
$b = '<h2>';
- $b .= _('Developer GIT Access via SSH');
+ $b .= _('Developer Git Access via SSH');
$b .= '</h2>';
$b .= '<p>';
- $b .= _('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.');
+ $b .= _('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.');
$b .= '</p>';
$b .= '<p><tt>git clone git+ssh://'.$d.'@' . $this->getBoxForProject($project) . '/'. forge_get_config('repos_path', 'scmgit') .'/'. $project->getUnixName() .'/'. $project->getUnixName() .'.git</tt></p>' ;
} elseif (forge_get_config('use_dav', 'scmgit')) {
$protocol = forge_get_config('use_ssl', 'scmgit')? 'https' : 'http';
$b = '<h2>';
- $b .= _('Developer GIT Access via HTTP');
+ $b .= _('Developer Git Access via HTTP');
$b .= '</h2>';
$b .= '<p>';
- $b .= _('Only project developers can access the GIT tree via this method. Enter your site password when prompted.');
+ $b .= _('Only project developers can access the Git tree via this method. Enter your site password when prompted.');
$b .= '</p>';
$b .= '<p><tt>git clone '.$protocol.'://'.$d.'@' . $this->getBoxForProject($project) . '/'. forge_get_config('scm_root', 'scmgit') .'/'. $project->getUnixName() .'/'. $project->getUnixName() .'.git</tt></p>' ;
} else {
} else {
if (forge_get_config('use_ssh', 'scmgit')) {
$b = '<h2>';
- $b .= _('Developer GIT Access via SSH');
+ $b .= _('Developer Git Access via SSH');
$b .= '</h2>';
$b .= '<p>';
- $b .= _('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.');
+ $b .= _('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.');
$b .= '</p>';
$b .= '<p><tt>git clone git+ssh://<i>'._('developername').'</i>@' . $this->getBoxForProject($project) . '/'. forge_get_config('repos_path', 'scmgit') .'/'. $project->getUnixName() .'/'. $project->getUnixName() .'.git</tt></p>' ;
} elseif (forge_get_config('use_dav', 'scmgit')) {
$protocol = forge_get_config('use_ssl', 'scmgit')? 'https' : 'http';
$b = '<h2>';
- $b .= _('Developer GIT Access via HTTP');
+ $b .= _('Developer Git Access via HTTP');
$b .= '</h2>';
$b .= '<p>';
- $b .= _('Only project developers can access the GIT tree via this method. Enter your site password when prompted.');
+ $b .= _('Only project developers can access the Git tree via this method. Enter your site password when prompted.');
$b .= '</p>';
$b .= '<p><tt>git clone '.$protocol.'://<i>'._('developername').'</i>@' . $this->getBoxForProject($project) . '/'. forge_get_config('scm_root', 'scmgit') .'/'. $project->getUnixName() .'/'. $project->getUnixName() .'.git</tt></p>' ;
}
$b .= '<p>';
$b .= _('You have a personal repository for this project, accessible through SSH with the following method. Enter your site password when prompted.');
$b .= '</p>';
- $b .= '<p><tt>git clone git+ssh://'.$u->getUnixName().'@' . $this->getBoxForProject($project) . forge_get_config('repos_path', 'scmgit') .'/'. $project->getUnixName() .'/users/'. $u->getUnixName() .'.git</tt></p>' ;
+ $b .= '<p><tt>git clone git+ssh://'.$u->getUnixName().'@' . $this->getBoxForProject($project) . '/'. forge_get_config('repos_path', 'scmgit') .'/'. $project->getUnixName() .'/users/'. $u->getUnixName() .'.git</tt></p>' ;
} else {
$glist = $u->getGroups();
foreach ($glist as $g) {
return $b ;
}
-// function getStatsBlock ($project) {
-// global $HTML ;
-// $b = '' ;
-
-// $result = db_query_params('SELECT u.realname, u.user_name, u.user_id, sum(commits) as commits, sum(adds) as adds, sum(adds+commits) as combined FROM stats_cvs_user s, users u WHERE group_id=$1 AND s.user_id=u.user_id AND (commits>0 OR adds >0) GROUP BY u.user_id, realname, user_name, u.user_id ORDER BY combined DESC, realname',
-// array ($project->getID()));
-
-// if (db_numrows($result) > 0) {
-// $b .= $HTML->boxMiddle(_('Repository Statistics'));
-
-// $tableHeaders = array(
-// _('Name'),
-// _('Adds'),
-// _('Commits')
-// );
-// $b .= $HTML->listTableTop($tableHeaders);
-
-// $i = 0;
-// $total = array('adds' => 0, 'commits' => 0);
-
-// while($data = db_fetch_array($result)) {
-// $b .= '<tr '. $HTML->boxGetAltRowStyle($i) .'>';
-// $b .= '<td width="50%">' ;
-// $b .= util_make_link_u ($data['user_name'], $data['user_id'], $data['realname']) ;
-// $b .= '</td><td width="25%" align="right">'.$data['adds']. '</td>'.
-// '<td width="25%" align="right">'.$data['commits'].'</td></tr>';
-// $total['adds'] += $data['adds'];
-// $total['commits'] += $data['commits'];
-// $i++;
-// }
-// $b .= '<tr '. $HTML->boxGetAltRowStyle($i) .'>';
-// $b .= '<td width="50%"><strong>'._('Total').':</strong></td>'.
-// '<td width="25%" align="right"><strong>'.$total['adds']. '</strong></td>'.
-// '<td width="25%" align="right"><strong>'.$total['commits'].'</strong></td>';
-// $b .= '</tr>';
-// $b .= $HTML->listTableBottom();
-// }
-
-// return $b ;
-// }
-
- function getStatsBlock($project) {
- return ;
+ function getStatsBlock ($project) {
+ global $HTML ;
+ $b = '' ;
+
+ $result = db_query_params('SELECT u.realname, u.user_name, u.user_id, sum(commits) as commits, sum(adds) as adds, sum(adds+commits) as combined FROM stats_cvs_user s, users u WHERE group_id=$1 AND s.user_id=u.user_id AND (commits>0 OR adds >0) GROUP BY u.user_id, realname, user_name, u.user_id ORDER BY combined DESC, realname',
+ array ($project->getID()));
+
+ if (db_numrows($result) > 0) {
+// $b .= $HTML->boxMiddle(_('Repository Statistics'));
+
+ $tableHeaders = array(
+ _('Name'),
+ _('Adds'),
+ _('Updates')
+ );
+ $b .= $HTML->listTableTop($tableHeaders, false, '', 'repo-history');
+
+ $i = 0;
+ $total = array('adds' => 0, 'commits' => 0);
+
+ while($data = db_fetch_array($result)) {
+ $b .= '<tr '. $HTML->boxGetAltRowStyle($i) .'>';
+ $b .= '<td class="halfwidth">' ;
+ $b .= util_make_link_u ($data['user_name'], $data['user_id'], $data['realname']) ;
+ $b .= '</td><td class="onequarterwidth align-right">'.$data['adds']. '</td>'.
+ '<td class="onequarterwidth align-right">'.$data['commits'].'</td></tr>';
+ $total['adds'] += $data['adds'];
+ $total['commits'] += $data['commits'];
+ $i++;
+ }
+ $b .= '<tr '. $HTML->boxGetAltRowStyle($i) .'>';
+ $b .= '<td class="halfwidth"><strong>'._('Total').':</strong></td>'.
+ '<td class="onequarterwidth align-right"><strong>'.$total['adds']. '</strong></td>'.
+ '<td class="onequarterwidth align-right"><strong>'.$total['commits'].'</strong></td>';
+ $b .= '</tr>';
+ $b .= $HTML->listTableBottom();
+ }
+
+ return $b ;
}
function createOrUpdateRepo($params) {
$project_name = $project->getUnixName();
$root = forge_get_config('repos_path', 'scmgit') . '/' . $project_name ;
- $unix_group = 'scm_' . $project_name;
- system ("mkdir -p $root");
+ system ("mkdir -p $root");
+ $output = '';
$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") ;
+ exec ("GIT_DIR=\"$main_repo\" git init --bare --shared=group", $result) ;
+ $output .= join("<br />", $result);
+ $result = '';
+ exec ("GIT_DIR=\"$main_repo\" git update-server-info", $result) ;
+ $output .= join("<br />", $result);
if (is_file ("$main_repo/hooks/post-update.sample")) {
rename ("$main_repo/hooks/post-update.sample",
"$main_repo/hooks/post-update") ;
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 g+wX,o+rX-w $root") ;
- system ("chmod -R g+wX,o+rX-w $main_repo") ;
+ if (forge_get_config('use_ssh','scmgit')) {
+ $unix_group = 'scm_' . $project_name ;
+ system ("chgrp -R $unix_group $root") ;
+ system ("chmod g+s $root") ;
+ if ($project->enableAnonSCM()) {
+ system ("chmod g+wX,o+rX-w $root") ;
+ system ("chmod -R g+wX,o+rX-w $main_repo") ;
+ } else {
+ system ("chmod g+wX,o-rwx $root") ;
+ system ("chmod -R g+wX,o-rwx $main_repo") ;
+ }
} else {
- system ("chmod g+wX,o-rwx $root") ;
- system ("chmod -R g+wX,o-rwx $main_repo") ;
+ $unix_user = forge_get_config('apache_user');
+ $unix_group = forge_get_config('apache_group');
+ system ("chown -R $unix_user:$unix_group $main_repo") ;
+ system ("chmod -R g-rwx,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',
system ("chmod -R g+rX-w,o-rwx $root/users") ;
}
}
+ $params['output'] = $output;
}
function updateRepositoryList($params) {
function getRepositories($path) {
if (! is_dir($path)) {
- echo 'pas de path ?';
- return;
+ return array();
}
$list = array();
$entries = scandir($path);
while (!feof($pipe) && $data = fgets ($pipe)) {
$line = trim($data);
if (strlen($line) > 0) {
- $result = preg_match("/^(?<name>.+) <(?<mail>.+)>/", $line, $matches);
+ $result = preg_match("/^(?P<name>.+) <(?P<mail>.+)>/", $line, $matches);
if ($result) {
// Author line
$last_user = $matches['name'];
+ $user2email[$last_user] = strtolower($matches['mail']);
} else {
// Short-commit stats line
- preg_match("/^(?<mode>[AM])\s+(?<file>.+)$/", $line, $matches);
+ preg_match("/^(?P<mode>[AM])\s+(?P<file>.+)$/", $line, $matches);
if ($last_user == "") continue;
if ($matches['mode'] == 'A') {
$usr_adds[$last_user]++;
$user_list = array_unique( array_merge( array_keys( $usr_adds ), array_keys( $usr_updates ) ) );
foreach ( $user_list as $user ) {
- // trying to get user id from user name
+ // Trying to get user id from user name or email
$u = &user_get_object_by_name ($user) ;
if ($u) {
$user_id = $u->getID();
} else {
- continue;
+ $res=db_query_params('SELECT user_id FROM users WHERE lower(realname)=$1 OR email=$2',
+ array (strtolower($user), $user2email[$user]));
+ if ($res && db_numrows($res) > 0) {
+ $user_id = db_result($res,0,'user_id');
+ } else {
+ continue;
+ }
}
$uu = $usr_updates[$user] ? $usr_updates[$user] : 0 ;
return false ;
}
+ // Skip empty repo (no HEAD present in repository)
+ $ref = trim(`GIT_DIR=$repo git symbolic-ref HEAD`);
+ if (!file_exists($repo.'/'.$ref)) {
+ return false;
+ }
+
$tmp = trim (`mktemp -d`) ;
if ($tmp == '') {
return false ;