<?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.
*
$this->_addHook('scm_gather_stats');
$this->_addHook('widget_instance', 'myPageBox', false);
$this->_addHook('widgets', 'widgets', false);
+ $this->_addHook('activity');
$this->register();
}
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.',
'Some of this project\'s members also have personal Git repositories that can be checked out anonymously.',
$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).') ['.util_make_link('/scm/browser.php?group_id='.$project->getID().'&user_id='.$user_id, _('Browse Git Repository')).']<br />';
}
$b .= '</p>';
}
function getInstructionsForRW($project) {
if (session_loggedin()) {
- $u =& user_get_object(user_getid());
+ $u = user_get_object(user_getid());
$d = $u->getUnixName();
+ $validSetup = 0;
+ $b = '';
if (forge_get_config('use_ssh', 'scmgit')) {
- $b = '<h2>';
- $b .= _('Developer GIT Access via SSH');
+ $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. 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')) {
+ $validSetup = 1;
+ }
+ if (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 .= _('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 {
+ $validSetup = 1;
+ }
+ if ($validSetup == 0) {
$b = '<p class="warning">'._('Missing configuration for access in scmgit.ini : use_ssh and use_dav disabled').'</p>';
}
} 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')) {
+ }
+ if (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) {
}
function printBrowserPage($params) {
- global $HTML;
-
$project = $this->checkParams($params);
if (!$project) {
return false;
}
if ($project->usesPlugin($this->name)) {
- if ($this->browserDisplayable($project)) {
+ if ($params['user_id']) {
+ $user = user_get_object($params['user_id']);
+ echo $project->getUnixName().'/users/'.$user->getUnixName();
+ print '<iframe src="'.util_make_url("/plugins/scmgit/cgi-bin/gitweb.cgi?p=".$project->getUnixName().'/users/'.$user->getUnixName().'.git').'" frameborder="0" width=100% height=700></iframe>' ;
+ } else 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>' ;
}
}
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") ;
+ system ("chmod -R g+rwX,o+rX-w $main_repo") ;
} else {
system ("chmod g+wX,o-rwx $root") ;
- system ("chmod -R g+wX,o-rwx $main_repo") ;
+ system ("chmod -R g+rwX,o-rwx $main_repo") ;
}
} else {
$unix_user = forge_get_config('apache_user');
}
$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') ;
$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, "\$logo = '". util_make_url('/plugins/scmgit/static/git-logo.png') . "';\n");
+ fwrite($config_f, "\$favicon = '". util_make_url('/plugins/scmgit/static/git-favicon.png')."';\n");
+ fwrite($config_f, "\$stylesheet = '". util_make_url('/plugins/scmgit/static/gitweb.css')."';\n");
+ fwrite($config_f, "\$javascript = '". util_make_url('/plugins/scmgit/static/gitweb.js')."';\n");
fwrite($config_f, "\$prevent_xss = 'true';\n");
fclose($config_f);
chmod ($fname.'.new', 0644) ;
}
function gatherStats ($params) {
- global $last_user, $usr_adds, $usr_deletes,
- $usr_updates, $updates, $adds;
-
$project = $this->checkParams ($params) ;
if (!$project) {
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 ;
}
+ // 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 ;
}
}
}
+
+ function activity($params) {
+ $group_id = $params['group'];
+ $project = group_get_object($group_id);
+ if (! $project->usesPlugin($this->name)) {
+ return false;
+ }
+ if (in_array('scm', $params['show'])) {
+ $start_time = $params['begin'];
+ $end_time = $params['end'];
+ $repo = forge_get_config('repos_path', 'scmgit') . '/' . $project->getUnixName() . '/' . $project->getUnixName() . '.git';
+ $pipe = popen("GIT_DIR=\"$repo\" git log --date=raw --since=@$start_time --until=@$end_time --all --pretty='format:%ad||%an||%s||%h' --name-status", 'r' );
+ while (!feof($pipe) && $data = fgets($pipe)) {
+ $line = trim($data);
+ $splitedLine = explode('||', $line);
+ if (sizeof($splitedLine) == 4) {
+ $result = array();
+ $result['section'] = 'scm';
+ $result['group_id'] = $group_id;
+ $result['ref_id'] = 'browser.php?group_id='.$group_id;
+ $result['description'] = $splitedLine[2].' (commit '.$splitedLine[3].')';
+ $result['realname'] = '';
+ $splitedDate = explode(' ', $splitedLine[0]);
+ $result['activity_date'] = $splitedDate[0];
+ $result['subref_id'] = '';
+ $params['results'][] = $result;
+ }
+ }
+ }
+ $params['ids'][] = 'scm';
+ $params['texts'][] = _('SCM Git Commits');
+ return true;
+ }
}
// Local Variables: