<?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.
*
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2 of the License,
* or (at your option) any later version.
- *
+ *
* FusionForge is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with FusionForge; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-forge_define_config_item ('default_server', 'scmgit', forge_get_config ('web_host')) ;
-forge_define_config_item ('repos_path', 'scmgit', forge_get_config('chroot').'/scmrepos/git') ;
+forge_define_config_item('default_server', 'scmgit', forge_get_config ('web_host')) ;
+forge_define_config_item('repos_path', 'scmgit', forge_get_config('chroot').'/scmrepos/git') ;
class GitPlugin extends SCMPlugin {
- function GitPlugin () {
- global $gfconfig;
- $this->SCMPlugin () ;
+ function GitPlugin() {
+ $this->SCMPlugin();
$this->name = 'scmgit';
$this->text = 'Git';
- $this->hooks[] = 'scm_update_repolist' ;
- $this->hooks[] = 'scm_browser_page' ;
- $this->hooks[] = 'scm_gather_stats' ;
- $this->hooks[] = 'scm_generate_snapshots' ;
-
- $this->register () ;
+ $this->_addHook('scm_browser_page');
+ $this->_addHook('scm_update_repolist');
+ $this->_addHook('scm_generate_snapshots');
+ $this->_addHook('scm_gather_stats');
+ $this->_addHook('widget_instance', 'myPageBox', false);
+ $this->_addHook('widgets', 'widgets', false);
+ $this->register();
}
function getDefaultServer() {
return forge_get_config('default_server', 'scmgit') ;
}
- function printShortStats ($params) {
- $project = $this->checkParams ($params) ;
- if (!$project) {
- return false ;
- }
-
- if ($project->usesPlugin($this->name)) {
- $result = db_query_params('SELECT sum(commits) AS commits, sum(adds) AS adds FROM stats_cvs_group WHERE group_id=$1',
- array ($project->getID())) ;
- $commit_num = db_result($result,0,'commits');
- $add_num = db_result($result,0,'adds');
- if (!$commit_num) {
- $commit_num=0;
- }
- if (!$add_num) {
- $add_num=0;
- }
- echo ' (Git: '.sprintf(_('<strong>%1$s</strong> commits, <strong>%2$s</strong> adds'), number_format($commit_num, 0), number_format($add_num, 0)).")";
- }
- }
+ function printShortStats ($params) {
+ $project = $this->checkParams($params);
+ if (!$project) {
+ return false;
+ }
+
+ if ($project->usesPlugin($this->name)) {
+ $result = db_query_params('SELECT sum(commits) AS commits, sum(adds) AS adds FROM stats_cvs_group WHERE group_id=$1',
+ array ($project->getID())) ;
+ $commit_num = db_result($result,0,'commits');
+ $add_num = db_result($result,0,'adds');
+ if (!$commit_num) {
+ $commit_num=0;
+ }
+ if (!$add_num) {
+ $add_num=0;
+ }
+ echo ' (Git: '.sprintf(_('<strong>%1$s</strong> commits, <strong>%2$s</strong> adds'), number_format($commit_num, 0), number_format($add_num, 0)).")";
+ }
+ }
- function getBlurb () {
+ function getBlurb() {
return '<p>' . _('Documentation for Git is available at <a href="http://git-scm.com/">http://git-scm.com/</a>.') . '</p>';
}
- function getInstructionsForAnon ($project) {
- $b = '<h2>';
- $b .= _('Anonymous Git Access');
- $b .= '</h2>';
+ function getInstructionsForAnon($project) {
+ $b = '<h2>' . _('Anonymous Git Access') . '</h2>';
$b .= '<p>';
$b .= _('This project\'s Git repository can be checked out through anonymous access with the following command.');
$b .= '</p>';
+
$b .= '<p>' ;
$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',
+ $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) ;
+ 'A'));
+ $rows = db_numrows($result);
if ($rows > 0) {
$b .= '<h2>';
$b .= _('Developer\'s repository');
- $b .= '</h2>';
+ $b .= '</h2>'."\n";
$b .= '<p>';
- $b .= ngettext ('One of this project\'s members also has a personal Git repository that can be checked out anonymously.',
+ $b .= ngettext('One of this project\'s members also has a personal Git repository that can be checked out anonymously.',
'Some of this project\'s members also have personal Git repositories that can be checked out anonymously.',
$rows);
$b .= '</p>';
$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 .= '<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) {
+ function getInstructionsForRW($project) {
+
if (session_loggedin()) {
- $u =& user_get_object(user_getid()) ;
- $d = $u->getUnixName() ;
+ $u = user_get_object(user_getid());
+ $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.'@' . $project->getSCMBox() . '/'. forge_get_config('scm_root', 'scmgit') .'/'. $project->getUnixName() .'/'. $project->getUnixName() .'.git</tt></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.'@' . $project->getSCMBox() . '/'. forge_get_config('scm_root', 'scmgit') .'/'. $project->getUnixName() .'/'. $project->getUnixName() .'.git</tt></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 {
+ $b = '<p class="warning">'._('Missing configuration for access in scmgit.ini : use_ssh and use_dav disabled').'</p>';
}
} else {
- $b = '<h2>';
- $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 .= '</p>';
- $b .= '<p><tt>git clone git+ssh://<i>'._('developername').'</i>@' . $project->getSCMBox() . '/'. forge_get_config('scm_root', 'scmgit') .'/'. $project->getUnixName() .'/'. $project->getUnixName() .'.git</tt></p>' ;
+ if (forge_get_config('use_ssh', 'scmgit')) {
+ $b = '<h2>';
+ $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 .= '</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 .= '</h2>';
+ $b .= '<p>';
+ $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>' ;
+ }
}
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',
+ $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())) ;
+ $u->getID()));
if ($result && db_numrows ($result) > 0) {
$b .= '<h2>';
$b .= _('Access to your personal repository');
$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().'@' . $project->getSCMBox() . forge_get_config('scm_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 ;
+ return $b;
}
- function getSnapshotPara ($project) {
+ function getSnapshotPara($project) {
$b = "" ;
- $filename = $project->getUnixName().'-scm-latest.tar.gz';
+ $filename = $project->getUnixName().'-scm-latest.tar'.util_get_compressed_file_extension();
if (file_exists(forge_get_config('scm_snapshots_path').'/'.$filename)) {
$b .= '<p>[' ;
- $b .= util_make_link ("/snapshots.php?group_id=".$project->getID(),
+ $b .= util_make_link("/snapshots.php?group_id=".$project->getID(),
_('Download the nightly snapshot')
- ) ;
+ );
$b .= ']</p>';
}
return $b ;
}
- function printBrowserPage ($params) {
- global $HTML;
-
- $project = $this->checkParams ($params) ;
+ function printBrowserPage($params) {
+ $project = $this->checkParams($params);
if (!$project) {
- return false ;
+ return false;
}
-
- if ($project->usesPlugin ($this->name)) {
- if ($this->browserDisplayable ($project)) {
- print '<iframe src="'.util_make_url ("/plugins/scmgit/cgi-bin/gitweb.cgi?p=".$project->getUnixName().'/'.$project->getUnixName().'.git').'" frameborder="no" width=100% height=700></iframe>' ;
+
+ if ($project->usesPlugin($this->name)) {
+ if ($this->browserDisplayable($project)) {
+ print '<iframe src="'.util_make_url("/plugins/scmgit/cgi-bin/gitweb.cgi?p=".$project->getUnixName().'/'.$project->getUnixName().'.git').'" frameborder="0" width=100% height=700></iframe>' ;
}
}
}
- function getBrowserLinkBlock ($project) {
+ function getBrowserLinkBlock($project) {
global $HTML ;
$b = $HTML->boxMiddle(_('Git Repository Browser'));
$b .= '<p>';
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 ;
+ 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 = $this->checkParams ($params) ;
+ function createOrUpdateRepo($params) {
+ $project = $this->checkParams($params);
if (!$project) {
return false ;
}
-
+
if (! $project->usesPlugin ($this->name)) {
return false;
}
- $project_name = $project->getUnixName() ;
+ $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',
if (is_file ("$repodir/hooks/post-update")) {
system ("chmod +x $repodir/hooks/post-update") ;
}
- system ("echo \"Git repository for user $owner in project $project_name\" > $repodir/description") ;
+ system("echo \"Git repository for user $user_name in project $project_name\" > $repodir/description");
system ("chown -R $user_name:$unix_group $repodir") ;
}
}
system ("chmod -R g+rX-w,o-rwx $root/users") ;
}
}
+ $params['output'] = $output;
}
- function updateRepositoryList ($params) {
- $groups = $this->getGroups () ;
- $list = array () ;
+ function updateRepositoryList($params) {
+ $groups = $this->getGroups();
+ $list = array();
foreach ($groups as $project) {
- if ($this->browserDisplayable ($project)) {
- $list[] = $project ;
+ if ($this->browserDisplayable($project)) {
+ $list[] = $project;
}
}
- $config_dir = '/etc/gforge/plugins/scmgit' ;
+ $config_dir = forge_get_config('config_path').'/plugins/scmgit';
+ if (!is_dir($config_dir)) {
+ mkdir($config_dir, 0755, true);
+ }
$fname = $config_dir . '/gitweb.conf' ;
- $config_f = fopen ($fname.'.new', 'w') ;
+ $config_f = fopen($fname.'.new', 'w') ;
$rootdir = forge_get_config('repos_path', 'scmgit');
fwrite($config_f, "\$projectroot = '$rootdir';\n");
fwrite($config_f, "\$projects_list = '$config_dir/gitweb.list';\n");
- fwrite($config_f, "@git_base_url_list = ('". util_make_url ('/anonscm/git') . "');\n");
- fwrite($config_f, "\$logo = '". util_make_url ('/plugins/scmgit/git-logo.png') . "';\n");
- fwrite($config_f, "\$favicon = '". util_make_url ('/plugins/scmgit/git-favicon.png')."';\n");
- fwrite($config_f, "\$stylesheet = '". util_make_url ('/plugins/scmgit/gitweb.css')."';\n");
+ fwrite($config_f, "@git_base_url_list = ('". util_make_url('/anonscm/git') . "');\n");
+ fwrite($config_f, "\$logo = '". util_make_url('/plugins/scmgit/git-logo.png') . "';\n");
+ fwrite($config_f, "\$favicon = '". util_make_url('/plugins/scmgit/git-favicon.png')."';\n");
+ fwrite($config_f, "\$stylesheet = '". util_make_url('/plugins/scmgit/gitweb.css')."';\n");
fwrite($config_f, "\$prevent_xss = 'true';\n");
fclose($config_f);
chmod ($fname.'.new', 0644) ;
$fname = $config_dir . '/gitweb.list' ;
- $f = fopen ($fname.'.new', 'w') ;
+ $f = fopen ($fname.'.new', 'w');
foreach ($list as $project) {
$repos = $this->getRepositories($rootdir . "/" . $project->getUnixName());
foreach ($repos as $repo) {
$reldir = substr($repo, strlen($rootdir) + 1);
- fwrite ($f, $reldir . "\n");
+ fwrite($f, $reldir . "\n");
}
}
- fclose ($f) ;
- chmod ($fname.'.new', 0644) ;
- rename ($fname.'.new', $fname) ;
+ fclose($f);
+ chmod($fname.'.new', 0644);
+ rename($fname.'.new', $fname);
}
- function getRepositories($path) {
- if (! is_dir($path))
- return;
- $list = array();
- $entries = scandir($path);
- foreach ($entries as $entry) {
- $fullname = $path . "/" . $entry;
- if (($entry == ".") or ($entry == ".."))
- continue;
- if (is_dir($fullname)) {
- if (is_link($fullname))
- continue;
- $result = $this->getRepositories($fullname);
- $list = array_merge($list, $result);
- } else if ($entry == "HEAD") {
- $list[] = $path;
- }
- }
- return $list;
- }
-
- function generateSnapshots ($params) {
-
-
- $project = $this->checkParams ($params) ;
- if (!$project) {
- return false ;
- }
-
- $group_name = $project->getUnixName() ;
-
- $snapshot = forge_get_config('scm_snapshots_path').'/'.$group_name.'-scm-latest.tar.gz';
- $tarball = forge_get_config('scm_tarballs_path').'/'.$group_name.'-scmroot.tar.gz';
-
- if (! $project->usesPlugin ($this->name)) {
- return false;
- }
-
- if (! $project->enableAnonSCM()) {
- unlink ($tarball) ;
- return false;
- }
-
- // TODO: ideally we generate one snapshot per git repository
- $toprepo = forge_get_config('repos_path', 'scmgit') ;
- $repo = $toprepo . '/' . $project->getUnixName() . '/' . $project->getUnixName() . '.git' ;
-
- if (!is_dir ($repo)) {
- unlink ($tarball) ;
- return false ;
+ function getRepositories($path) {
+ if (! is_dir($path)) {
+ return array();
}
-
- $today = date ('Y-m-d') ;
- $tmp = trim (`mktemp -d`) ;
- if ($tmp == '') {
- return false ;
+ $list = array();
+ $entries = scandir($path);
+ foreach ($entries as $entry) {
+ $fullname = $path . "/" . $entry;
+ if (($entry == ".") or ($entry == ".."))
+ continue;
+ if (is_dir($fullname)) {
+ if (is_link($fullname))
+ continue;
+ $result = $this->getRepositories($fullname);
+ $list = array_merge($list, $result);
+ } else if ($entry == "HEAD") {
+ $list[] = $path;
+ }
}
-
- 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") ;
-
- system ("tar czCf $toprepo $tmp/tarball.tar.gz " . $project->getUnixName()) ;
- chmod ("$tmp/tarball.tar.gz", 0644) ;
- copy ("$tmp/tarball.tar.gz", $tarball) ;
- unlink ("$tmp/tarball.tar.gz") ;
- system ("rm -rf $tmp") ;
+ return $list;
}
function gatherStats ($params) {
- global $last_user, $usr_adds, $usr_deletes,
- $usr_updates, $updates, $adds;
-
$project = $this->checkParams ($params) ;
if (!$project) {
return false ;
}
-
+
if (! $project->usesPlugin ($this->name)) {
return false;
}
if ($params['mode'] == 'day') {
- db_begin();
-
$year = $params ['year'] ;
$month = $params ['month'] ;
$day = $params ['day'] ;
$repo = forge_get_config('repos_path', 'scmgit') . '/' . $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 2>/dev/null", 'r' ) ;
+
+ db_begin();
// 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',
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]++;
return false ;
}
}
-
+
// building the user list
$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 ;
$ua = $usr_adds[$user] ? $usr_adds[$user] : 0 ;
if ($uu > 0 || $ua > 0) {
}
db_commit();
}
- }
+
+ function generateSnapshots ($params) {
+
+ $project = $this->checkParams ($params) ;
+ if (!$project) {
+ return false ;
+ }
+
+ $group_name = $project->getUnixName() ;
+
+ $snapshot = forge_get_config('scm_snapshots_path').'/'.$group_name.'-scm-latest.tar'.util_get_compressed_file_extension();
+ $tarball = forge_get_config('scm_tarballs_path').'/'.$group_name.'-scmroot.tar'.util_get_compressed_file_extension();
+
+ if (! $project->usesPlugin ($this->name)) {
+ return false;
+ }
+
+ if (! $project->enableAnonSCM()) {
+ if (is_file($snapshot)) {
+ unlink ($snapshot) ;
+ }
+ if (is_file($tarball)) {
+ unlink ($tarball) ;
+ }
+ return false;
+ }
+
+ // TODO: ideally we generate one snapshot per git repository
+ $toprepo = forge_get_config('repos_path', 'scmgit') ;
+ $repo = $toprepo . '/' . $project->getUnixName() . '/' . $project->getUnixName() . '.git' ;
+
+ if (!is_dir ($repo)) {
+ if (is_file($snapshot)) {
+ unlink ($snapshot) ;
+ }
+ if (is_file($tarball)) {
+ unlink ($tarball) ;
+ }
+ 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 ;
+ }
+ $today = date ('Y-m-d') ;
+ system ("GIT_DIR=\"$repo\" git archive --format=tar --prefix=$group_name-scm-$today/ HEAD |".forge_get_config('compression_method')." > $tmp/snapshot");
+ chmod ("$tmp/snapshot", 0644) ;
+ copy ("$tmp/snapshot", $snapshot) ;
+ unlink ("$tmp/snapshot") ;
+
+ system ("tar cCf $toprepo - ".$project->getUnixName() ."|".forge_get_config('compression_method')."> $tmp/tarball") ;
+ chmod ("$tmp/tarball", 0644) ;
+ copy ("$tmp/tarball", $tarball) ;
+ unlink ("$tmp/tarball") ;
+ system ("rm -rf $tmp") ;
+ }
+
+ /**
+ * widgets - 'widgets' hook handler
+ * @param array $params
+ * @return boolean
+ */
+ function widgets($params) {
+ require_once('common/widget/WidgetLayoutManager.class.php');
+ if ($params['owner_type'] == WidgetLayoutManager::OWNER_TYPE_GROUP) {
+ $params['fusionforge_widgets'][] = 'plugin_scmgit_project_latestcommits';
+ }
+ if ($params['owner_type'] == WidgetLayoutManager::OWNER_TYPE_USER) {
+ $params['fusionforge_widgets'][] = 'plugin_scmgit_user_myrepositories';
+ }
+ return true;
+ }
+
+ /**
+ * Process the 'widget_instance' hook to create instances of the widgets
+ * @param array $params
+ */
+ function myPageBox($params) {
+ global $gfplugins;
+ $user = UserManager::instance()->getCurrentUser();
+ require_once('common/widget/WidgetLayoutManager.class.php');
+ if ($params['widget'] == 'plugin_scmgit_user_myrepositories') {
+ require_once $gfplugins.$this->name.'/common/scmgit_Widget_MyRepositories.class.php';
+ $params['instance'] = new scmgit_Widget_MyRepositories(WidgetLayoutManager::OWNER_TYPE_USER, $user->getId());
+ }
+ }
+}
// Local Variables:
// mode: php