<?php
-/** FusionForge Subversion plugin
+/**
+ * FusionForge Subversion plugin
*
* Copyright 2003-2010, Roland Mas, Franck Villaume
* Copyright 2004, GForge, LLC
function printShortStats($params) {
$project = $this->checkParams($params);
if (!$project) {
- return false;
+ return;
}
- if ($project->usesPlugin($this->name)) {
+ if ($project->usesPlugin($this->name) && forge_check_perm('scm', $project->getID(), 'read')) {
$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');
}
function getBlurb() {
- return '<p>' . _('Documentation for Subversion (sometimes referred to as "SVN") is available <a href="http://svnbook.red-bean.com/">here</a>.') . '</p>';
+ return '<p>'
+ . sprintf(_('Documentation for %1$s is available at <a href="%2$s">%2$s</a>.'),
+ 'Subversion (“SVN”)',
+ 'http://svnbook.red-bean.com/')
+ . '</p>';
}
function topModule($project) {
$module = $this->topModule($project);
if (session_loggedin()) {
- $u =& user_get_object(user_getid());
+ $u = user_get_object(user_getid());
$d = $u->getUnixName() ;
if (forge_get_config('use_ssh', 'scmsvn')) {
$b .= '<h2>';
- $b .= _('Developer Subversion Access via SSH');
+ $b .= sprintf(_('Developer %s Access via SSH'), 'Subversion');
$b .= '</h2>';
$b .= '<p>';
- $b .= _('Only project developers can access the SVN tree via this method. SSH must be installed on your client machine. Enter your site password when prompted.');
+ $b .= sprintf(_('Only project developers can access the %s tree via this method.'), 'Subversion');
+ $b .= ' ';
+ $b .= _('SSH must be installed on your client machine.');
+ $b .= ' ';
+ $b .= _('Enter your site password when prompted.');
$b .= '</p>';
$b .= '<p><tt>svn checkout svn+ssh://'.$d.'@' . $this->getBoxForProject($project) . $this->svn_root_fs .'/'. $project->getUnixName().$module.'</tt></p>' ;
}
$b .= _('Developer Subversion Access via DAV');
$b .= '</h2>';
$b .= '<p>';
- $b .= _('Only project developers can access the SVN tree via this method. Enter your site password when prompted.');
+ $b .= sprintf(_('Only project developers can access the %s tree via this method.'), 'Subversion');
+ $b .= ' ';
+ $b .= _('Enter your site password when prompted.');
$b .= '</p>';
$b .= '<p><tt>svn checkout --username '.$d.' http'.((forge_get_config('use_ssl', 'scmsvn')) ? 's' : '').'://'. $this->getBoxForProject($project) . $this->svn_root_dav .'/'.$project->getUnixName().$module.'</tt></p>' ;
}
} else {
if (forge_get_config('use_ssh', 'scmsvn')) {
$b .= '<h2>';
- $b .= _('Developer Subversion Access via SSH');
+ $b .= sprintf(_('Developer %s Access via SSH'), 'Subversion');
$b .= '</h2>';
$b .= '<p>';
- $b .= _('Only project developers can access the SVN 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.');
+ $b .= sprintf(_('Only project developers can access the %s tree via this method.'), 'Subversion');
+ $b .= ' ';
+ $b .= _('SSH must be installed on your client machine.');
+ $b .= ' ';
+ $b .= _('Substitute <em>developername</em> with the proper values.');
+ $b .= ' ';
+ $b .= _('Enter your site password when prompted.');
$b .= '</p>';
$b .= '<p><tt>svn checkout svn+ssh://<i>'._('developername').'</i>@' . $this->getBoxForProject($project) . $this->svn_root_fs .'/'. $project->getUnixName().$module.'</tt></p>' ;
}
$b .= _('Developer Subversion Access via DAV');
$b .= '</h2>';
$b .= '<p>';
- $b .= _('Only project developers can access the SVN tree via this method. Substitute <i>developername</i> with the proper values. Enter your site password when prompted.');
+ $b .= sprintf(_('Only project developers can access the %s tree via this method.'), 'Subversion');
+ $b .= ' ';
+ $b .= _('Substitute <em>developername</em> with the proper values.');
+ $b .= ' ';
+ $b .= _('Enter your site password when prompted.');
$b .= '</p>';
$b .= '<p><tt>svn checkout --username <i>'._('developername').'</i> http'.((forge_get_config('use_ssl', 'scmsvn')) ? 's' : '').'://'. $this->getBoxForProject($project) . $this->svn_root_dav .'/'.$project->getUnixName().$module.'</tt></p>' ;
}
function getBrowserLinkBlock($project) {
global $HTML ;
- $b = $HTML->boxMiddle(_('Subversion Repository Browser'));
+ $b = $HTML->boxMiddle(sprintf(_('%s Repository Browser'), 'Subversion'));
$b .= '<p>';
- $b .= _('Browsing the Subversion tree gives you a view into the current status of this project\'s code. You may also view the complete histories of any file in the repository.');
+ $b .= sprintf(_("Browsing the %s tree gives you a view into the current status of this project's code."), 'Subversion');
+ $b .= ' ';
+ $b .= _('You may also view the complete histories of any file in the repository.');
$b .= '</p>';
$b .= '<p>[' ;
$b .= util_make_link ("/scm/browser.php?group_id=".$project->getID(),
- _('Browse Subversion Repository')
+ sprintf(_('Browse %s Repository'), 'Subversion')
) ;
$b .= ']</p>' ;
return $b ;
function printBrowserPage($params) {
$project = $this->checkParams($params);
if (!$project) {
- return false;
+ return;
}
if ($project->usesPlugin($this->name)) {
if ($ret != 0) {
return false;
}
+ system ("svn mkdir -m'Init' file:///$repo/trunk file:///$repo/tags file:///$repo/branches >/dev/null") ;
if (forge_get_config('use_ssh', 'scmsvn')) {
$unix_group = 'scm_' . $project->getUnixName() ;
system ("find $repo -type d | xargs -I{} chmod g+s {}") ;
if ($project->enableAnonSCM()) {
- system ("chmod -R g+wX,o+rX-w $repo") ;
+ system ("chmod -R g+rwX,o+rX-w $repo") ;
} else {
- system ("chmod -R g+wX,o-rwx $repo") ;
+ system ("chmod -R g+rwX,o-rwx $repo") ;
}
system ("chgrp -R $unix_group $repo") ;
} else {
system ("chmod -R g-rwx,o-rwx $repo") ;
system ("chown -R $unix_user:$unix_group $repo") ;
}
- system ("svn mkdir -m'Init' file:///$repo/trunk file:///$repo/tags file:///$repo/branches >/dev/null") ;
}
- $this->installOrUpdateCmds($project, $project->getUnixName(), $repo);
-
if (forge_get_config('use_ssh', 'scmsvn')) {
$unix_group = 'scm_' . $project->getUnixName();
system("find $repo -type d | xargs -I{} chmod g+s {}");
system("chgrp $unix_group $repo");
}
if ($project->enableAnonSCM()) {
- system("chmod g+wX,o+rX-w $repo") ;
+ system("chmod g+rwX,o+rX-w $repo") ;
} else {
- system("chmod g+wX,o-rwx $repo") ;
+ system("chmod g+rwX,o-rwx $repo") ;
}
} else {
$unix_user = forge_get_config('apache_user');
$updates = 0;
$usr_adds = array();
$usr_updates = array();
-
+
$repo = forge_get_config('repos_path', 'scmsvn') . '/' . $project->getUnixName();
if (!is_dir ($repo) || !is_file ("$repo/format")) {
- echo "No repository\n";
+ echo "No repository $repo\n";
db_rollback();
return false;
}
db_rollback();
return false;
}
-
+
$res = db_query_params ('DELETE FROM stats_cvs_user WHERE month=$1 AND day=$2 AND group_id=$3',
array ($month_string,
$day,
db_rollback () ;
return false ;
}
-
+
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "SVNPluginStartElement", "SVNPluginEndElement");
xml_set_character_data_handler($xml_parser, "SVNPluginCharData");
foreach ( $user_list as $user ) {
// trying to get user id from user name
- $u = &user_get_object_by_name ($user) ;
+ $u = user_get_object_by_name ($user) ;
if ($u) {
$user_id = $u->getID();
} else {
$dir = $project->getUnixName ()."-$today" ;
system ("mkdir -p $tmp") ;
$code = 0 ;
- system ("svn ls file://$repo/trunk > /dev/null", $code) ;
+ system ("svn ls file://$repo/trunk > /dev/null 2> /dev/null", $code) ;
if ($code == 0) {
system ("cd $tmp ; svn export file://$repo/trunk $dir > /dev/null 2>&1") ;
system ("tar cCf $tmp - $dir |".forge_get_config('compression_method')."> $tmp/snapshot") ;
function activity($params) {
global $last_user, $last_time, $last_tag, $time_ok, $start_time, $end_time,
$adds, $deletes, $updates, $commits, $date_key,
- $usr_adds, $usr_deletes, $usr_updates,
- $messages, $last_message, $times, $revisions;
+ $usr_adds, $usr_deletes, $usr_updates, $old_commit,
+ $messages, $last_message, $times, $revisions, $users;
$group_id = $params['group'];
$project = group_get_object($group_id);
if (! $project->usesPlugin($this->name)) {
}
if (in_array('scmsvn', $params['show']) || (count($params['show']) < 1)) {
+ $commits = 0;
+ $old_commit = -1;
$start_time = $params['begin'];
$end_time = $params['end'];
$d1 = date('Y-m-d', $start_time - 80000);
$result['user_name'] = $users[$i];
$userObject = user_get_object_by_name($users[$i]);
if (is_a($userObject, 'GFUser')) {
- $result['realname'] = $user->getFirstName().' '.$user->getLastName();
- $result['user_id'] = $user->getId();
+ $result['realname'] = $userObject->getFirstName().' '.$userObject->getLastName();
+ $result['user_id'] = $userObject->getId();
} else {
$result['realname'] = '';
$result['user_id'] = '';
}
}
}
- $params['ids'][] = 'scm';
- $params['texts'][] = _('SCM SVN Commits');
+ $params['ids'][] = $this->name;
+ $params['texts'][] = _('Subversion Commits');
return true;
}
-
- function installOrUpdateCmds($project, $unix_group_name, $repos) {
-
- $hooks = array();
- $params = array();
- $params['unix_group_name'] = $unix_group_name;
- $group = group_get_object_by_name($unix_group_name);
- $params['group_id'] = $group->getID();
- $params['repos'] = $repos;
- $params['hooks'] = &$hooks;
- plugin_hook_by_reference('cmd_for_post_commit_hook', $params);
-
- foreach ($params['hooks'] as $plugin => $cmd ) {
- if (getenv('sys_localinc')) {
- $cmd = 'sys_localinc='.getenv(sys_localinc).' '.$cmd;
- }
- $contents = @file_get_contents($repos."/hooks/post-commit");
- if ($project->usesPlugin($plugin)) {
- if (strstr($contents, "#begin added by $plugin") === false ) {
- $this->installCmdInHook($repos, $plugin, $cmd);
- } else {
- $this->updateCmdInHook($repos, $plugin, $cmd);
- }
- } elseif (!$project->usesPlugin($plugin) &&
- (strstr($contents, "#begin added by $plugin") !== false )) {
- $this->removeCmdInHook($repos, $plugin);
- }
- }
- }
-
- function installCmdInHook($repos, $name, $text) {
-
- if (file_exists($repos.'/hooks/post-commit')) {
- $FOut = fopen($repos.'/hooks/post-commit', "a+");
- $Line = '';
- } else {
- $FOut = fopen($repos.'/hooks/post-commit', "w");
- $Line = '#!/bin/sh'."\n"; // add this line to first line or else the script fails
- }
-
- if ($FOut) {
- $Line .= "\n#begin added by $name\n$text\n#end added by $name\n";
-
- fwrite($FOut, $Line);
-
- system("chmod 700 $repos/hooks/post-commit");
- fclose($FOut);
- }
- }
-
- function updateCmdInHook($repos, $plugin, $text) {
-
- $contents = @file_get_contents($repos."/hooks/post-commit");
-
- $new = preg_replace("/(#begin added by $plugin\n)(.*)(\n#end added by $plugin)/s", '$1{COMMAND}$3', $contents);
- $new = str_replace('{COMMAND}', $text, $new);
-
- if ($contents !== $new) {
- $fout = fopen($repos.'/hooks/post-commit', "w");
- fwrite($fout, $new);
- fclose($fout);
- }
- }
-
- function removeCmdInHook($repos, $plugin) {
-
- $contents = @file_get_contents($repos."/hooks/post-commit");
- $new = preg_replace("/#begin added by $plugin\n.*?\n#end added by $plugin/s", '', $contents);
-
- if ($contents !== $new) {
- if (preg_match("/^#\!\/bin\/sh(\n+)$/s", $new)) {
- unlink($repos.'/hooks/post-commit');
- } else {
- $fout = fopen($repos.'/hooks/post-commit', "w");
- fwrite($fout, $new);
- fclose($fout);
- }
- }
- }
}
// End of class, helper functions now
function SVNPluginCharData($parser, $chars) {
- global $last_tag, $last_user, $last_time, $start_time, $end_time,
- $time_ok, $user_list, $last_message, $messages, $times;
+ global $last_tag, $last_user, $last_time, $start_time, $end_time, $old_commit, $commits,
+ $time_ok, $user_list, $last_message, $messages, $times, $users;
switch ($last_tag) {
case "AUTHOR": {
$last_user = preg_replace('/[^a-z0-9_-]/', '', strtolower(trim($chars)));
+ $users[] = $last_user;
break;
}
case "DATE": {
break;
}
case "MSG": {
- $messages[] = $chars;
+ /* If commit id is the same, then concatenate the string with the previous
++ * (happen when the message contain accents).
++ */
+ if ($old_commit == $commits) {
+ $messages[count($messages)-1] .= $chars;
+ } else {
+ $messages[] = $chars;
+ }
+ $old_commit = $commits;
break;
}
}
// mode: php
// c-file-style: "bsd"
// End:
-
-?>