* USA
*/
-class SVNPlugin extends SCM {
+class SVNPlugin extends SCMPlugin {
function SVNPlugin () {
global $gfconfig;
- $this->SCM () ;
+ $this->SCMPlugin () ;
$this->name = 'scmsvn';
$this->text = 'SVN';
- $this->hooks[] = 'scm_page';
- $this->hooks[] = 'scm_admin_update';
- $this->hooks[] = 'scm_admin_page';
- $this->hooks[] = 'scm_stats';
- $this->hooks[] = 'scm_createrepo';
- $this->hooks[] = 'scm_plugin';
+ $this->hooks[] = 'scm_browser_page';
+ $this->hooks[] = 'scm_update_repolist' ;
+ $this->hooks[] = 'scm_generate_snapshots' ;
+ $this->hooks[] = 'scm_gather_stats' ;
require_once $gfconfig.'plugins/scmsvn/config.php' ;
$this->default_svn_server = $default_svn_server ;
- $this->enabled_by_default = $enabled_by_default ;
$this->use_ssh = $use_ssh;
$this->use_dav = $use_dav;
$this->use_ssl = $use_ssl;
- $this->svn_root = $svn_root;
+ if (isset ($svn_root)) {
+ $this->svn_root = $svn_root;
+ } else {
+ $this->svn_root = $GLOBALS['sys_chroot'].'/scmrepos/svn' ;
+ }
$this->register () ;
}
return $this->default_svn_server ;
}
- function CallHook ($hookname, $params) {
- global $HTML ;
-
- switch ($hookname) {
- case 'scm_page':
- $group_id = $params['group_id'] ;
- $this->getPage ($group_id) ;
- break ;
- case 'scm_admin_update':
- $this->AdminUpdate ($params) ;
- break ;
- case 'scm_admin_page':
- $this->getAdminPage ($params) ;
- break ;
- case 'scm_stats':
- $this->getStats ($params) ;
- break;
- case 'scm_createrepo':
- $this->createOrUpdateRepo ($params) ;
- break;
- case 'scm_plugin':
- $scm_plugins=& $params['scm_plugins'];
- $scm_plugins[]=$this->name;
- break;
- default:
- // Forgot something
+ function printShortStats ($params) {
+ $project = $this->checkParams ($params) ;
+ if (!$project) {
+ return false ;
}
- }
-
- function getPage ($group_id) {
- global $HTML, $sys_scm_snapshots_path;
-
- $project =& group_get_object($group_id);
- if (!$project || !is_object($project)) {
- return false;
- } elseif ($project->isError()) {
- return false;
- }
-
- if ($project->usesPlugin ($this->name)) {
-
- // SVN browser links must be displayed if
- // project enables anon SVN or if logged-in
- // user is a member of the group
- $displaySvnBrowser = $project->enableAnonSCM();
- if(session_loggedin()) {
- $perm =& $project->getPermission(session_get_user());
- if ($perm && is_object($perm) && !$perm->isError() && $perm->isMember()) {
- $displaySvnBrowser = true;
- }
- }
-
- // Table for summary info
- print '<table width="100%"><tr valign="top"><td width="65%">' ;
- print _('<p>Documentation for Subversion (sometimes referred to as "SVN") is available <a href="http://svnbook.red-bean.com/">here</a>.</p>');
-
- // Anonymous SVN Instructions
- if ($project->enableAnonSCM()) {
- print _('<p><b>Anonymous Subversion Access</b></p><p>This project\'s SVN repository can be checked out through anonymous access with the following command(s).</p>');
- print '<p>';
- if ($this->use_ssh) {
- print '<tt>svn checkout svn://'.$project->getSCMBox().'/'.$this->svn_root.'/'.$project->getUnixName().'</tt><br />';
- }
- if ($this->use_dav) {
- print '<tt>svn checkout --username anonsvn http'.(($this->use_ssl) ? 's' : '').'://' . $project->getSCMBox(). '/' . $this->svn_root .'/'. $project->getUnixName() .'</tt><br/><br/>';
- print _('The password is \'anonsvn\'').'<br/>';
- }
- print '</p>';
- }
-
- // Developer Access
- if ($this->use_ssh) {
- echo _('<p><b>Developer Subversion Access via SSH</b></p><p>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.</p>');
- print '<p><tt>svn checkout svn+ssh://<i>'._('developername').'</i>@' . $project->getSCMBox() . '/'. $this->svn_root .'/'. $project->getUnixName().'</tt></p>' ;
- }
- if ($this->use_dav) {
- echo _('<p><b>Developer Subversion Access via DAV</b></p><p>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.</p>');
- print '<p><tt>svn checkout --username <i>'._('developername').'</i> http'.(($this->use_ssl) ? 's' : '').'://'. $project->getSCMBox() .'/'. $this->svn_root .'/'.$project->getUnixName().'</tt></p>' ;
- }
-
- // SVN Snapshot
- if ($displaySvnBrowser) {
- $filename=$project->getUnixName().'-scm-latest.tar.gz';
- if (file_exists($sys_scm_snapshots_path.'/'.$filename)) {
- print '<p>[' ;
- print util_make_link ("/snapshots.php?group_id=$group_id",
- _('Download The Nightly SVN Tree Snapshot')
- ) ;
- print ']</p>';
- }
+
+ 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;
}
- print '</td><td width="35%" valign="top">' ;
-
- // SVN Browsing
- echo $HTML->boxTop(_('Repository History'));
- echo $this->getDetailedStats(array('group_id'=>$group_id)).'<p>';
- if ($displaySvnBrowser) {
- echo _('<b>Browse the Subversion Tree</b><p>Browsing the SVN tree gives you a great view into the current status of this project\'s code. You may also view the complete histories of any file in the repository.</p>');
- echo '<p>[' ;
- echo util_make_link ("/scm/viewvc.php/?root=".$project->getUnixName(),
- _('Browse Subversion Repository')
- ) ;
- echo ']</p>' ;
+ if (!$add_num) {
+ $add_num=0;
}
-
- echo $HTML->boxBottom();
- print '</td></tr></table>' ;
+ echo ' (SVN: '.sprintf(_('<strong>%1$s</strong> commits, <strong>%2$s</strong> adds'), number_format($commit_num, 0), number_format($add_num, 0)).")";
}
}
- function AdminUpdate ($params) {
- $group =& group_get_object($params['group_id']);
- if (!$group || !is_object($group)) {
- return false;
- } elseif ($group->isError()) {
- return false;
- }
-
- if ( $group->usesPlugin ( $this->name ) ) {
- if ($params['scmsvn_enable_anon_svn']) {
- $group->SetUsesAnonSCM(true);
- } else {
- $group->SetUsesAnonSCM(false);
- }
- }
+ function getBlurb () {
+ return _('<p>Documentation for Subversion (sometimes referred to as "SVN") is available <a href="http://svnbook.red-bean.com/">here</a>.</p>') ;
}
-
- // This function is used to render checkboxes below
- function c($v) {
- if ($v) {
- return 'checked="checked"';
- } else {
- return '';
+
+ function getInstructionsForAnon ($project) {
+ $b = _('<p><b>Anonymous Subversion Access</b></p><p>This project\'s SVN repository can be checked out through anonymous access with the following command(s).</p>');
+ $b .= '<p>' ;
+ if ($this->use_ssh) {
+ $b .= '<tt>svn checkout svn://'.$project->getSCMBox().$this->svn_root.'/'.$project->getUnixName().'</tt><br />';
}
- }
-
- function getAdminPage ($params) {
- $group =& group_get_object($params['group_id']);
- if ( $group->usesPlugin ( $this->name ) && $group->isPublic()) {
- print '<p><input type="checkbox" name="scmsvn_enable_anon_svn" value="1" '.$this->c($group->enableAnonSCM()).' /><strong>'._('Enable Anonymous Access').'</strong></p>';
+ if ($this->use_dav) {
+ $b .= '<tt>svn checkout --username anonsvn http'.(($this->use_ssl) ? 's' : '').'://' . $project->getSCMBox(). $this->svn_root .'/'. $project->getUnixName() .'</tt><br/><br/>';
+ $b .= _('The password is \'anonsvn\'').'<br/>';
}
+ $b .= '</p>';
+ return $b ;
}
-
- function getStats ($params) {
- $group_id = $params['group_id'] ;
- $project =& group_get_object($group_id);
- if (!$project || !is_object($project)) {
- return false;
- } elseif ($project->isError()) {
- return false;
+
+ function getInstructionsForRW ($project) {
+ $b = '' ;
+ if ($this->use_ssh) {
+ $b .= _('<p><b>Developer Subversion Access via SSH</b></p><p>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.</p>');
+ $b .= '<p><tt>svn checkout svn+ssh://<i>'._('developername').'</i>@' . $project->getSCMBox() . $this->svn_root .'/'. $project->getUnixName().'</tt></p>' ;
}
-
- if ($project->usesPlugin ($this->name)) {
- list($commit_num, $add_num) = $this->getTotalStats($group_id);
- echo ' (SVN: '.sprintf(_('<strong>%1$s</strong> updates, <strong>%2$s</strong> adds'), number_format($commit_num, 0), number_format($add_num, 0)).')';
+ if ($this->use_dav) {
+ $b .= _('<p><b>Developer Subversion Access via DAV</b></p><p>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.</p>');
+ $b .= '<p><tt>svn checkout --username <i>'._('developername').'</i> http'.(($this->use_ssl) ? 's' : '').'://'. $project->getSCMBox() . $this->svn_root .'/'.$project->getUnixName().'</tt></p>' ;
}
+
+ return $b ;
}
-
- // Get the total stats for a group
- function getTotalStats($group_id) {
- $result = db_query("
- SELECT SUM(commits) AS commits, SUM(adds) AS adds
- FROM stats_cvs_group
- WHERE group_id='$group_id'");
- $commit_num = db_result($result,0,0);
- $add_num = db_result($result,0,1);
- if (!$commit_num) {
- $commit_num=0;
- }
- if (!$add_num) {
- $add_num=0;
- }
- return array($commit_num, $add_num);
+
+ function getSnapshotPara ($project) {
+ return ;
+ }
+
+ function getBrowserLinkBlock ($project) {
+ global $HTML ;
+ $b = $HTML->boxMiddle(_('Subversion Repository Browser'));
+ $b .= _('<p>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.</p>');
+ $b .= '<p>[' ;
+ $b .= util_make_link ("/scm/browser.php?group_id=".$project->getID(),
+ _('Browse Subversion Repository')
+ ) ;
+ $b .= ']</p>' ;
+ return $b ;
}
- function getDetailedStats ($params) {
- global $HTML;
- $group_id = $params['group_id'] ;
-
- $result = db_query('
- 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=\''.$group_id.'\' AND s.user_id=u.user_id AND (commits>0 OR adds >0)
- GROUP BY group_id, realname, user_name
- ORDER BY combined DESC, realname;
- ');
+ 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')
+ _('Commits')
);
- echo $HTML->listTableTop($tableHeaders);
+ $b .= $HTML->listTableTop($tableHeaders);
$i = 0;
$total = array('adds' => 0, 'commits' => 0);
while($data = db_fetch_array($result)) {
- echo '<tr '. $HTML->boxGetAltRowStyle($i) .'>';
- echo '<td width="50%">' ;
- echo util_make_link_u ($data['user_name'], $data['user_id'], $data['realname']) ;
- echo '</td><td width="25%" align="right">'.$data['adds']. '</td>'.
+ $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++;
}
- list($commit_num, $add_num) = $this->getTotalStats($group_id);
- if ($commit_num > $total['commits'] ||
- $add_num > $total['adds']) {
- echo '<tr '. $HTML->boxGetAltRowStyle($i) .'>';
- echo '<td width="50%">' .
- _('Unknown') .
- '</td><td width="25%" align="right">'.
- ($add_num - $total['adds']) . '</td>'.
- '<td width="25%" align="right">'.
- ($commit_num - $total['commits']) .
- '</td></tr>';
- $i++;
- }
- echo '<tr '. $HTML->boxGetAltRowStyle($i) .'>';
- echo '<td width="50%"><strong>'._('Total').':</strong></td>'.
- '<td width="25%" align="right"><strong>'.$add_num. '</strong></td>'.
- '<td width="25%" align="right"><strong>'.$commit_num.'</strong></td>';
- echo '</tr>';
- echo $HTML->listTableBottom();
- echo '<hr size="1" />';
+ $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();
+ $b .= '<hr size="1" />';
}
+
+ return $b ;
}
- function createOrUpdateRepo ($params) {
- return true ; // Disabled for now
+ function printBrowserPage ($params) {
+ global $HTML;
- $group_id = $params['group_id'] ;
+ $project = $this->checkParams ($params) ;
+ if (!$project) {
+ return false ;
+ }
+
+ if ($project->usesPlugin ($this->name)) {
+ if ($this->browserDisplayable ($project)) {
+ print '<iframe src="'.util_make_url ("/scm/viewvc.php/?root=".$project->getUnixName()).'" frameborder="no" width=100% height=700></iframe>' ;
+ }
+ }
+ }
- $project =& group_get_object($group_id);
- if (!$project || !is_object($project)) {
- return false;
- } elseif ($project->isError()) {
- return false;
+ function createOrUpdateRepo ($params) {
+ $project = $this->checkParams ($params) ;
+ if (!$project) {
+ return false ;
}
-
+
if (! $project->usesPlugin ($this->name)) {
return false;
}
$repo = $this->svn_root . '/' . $project->getUnixName() ;
$unix_group = 'scm_' . $project->getUnixName() ;
- $repo_exists = false ;
- if (is_dir ($repo) && is_file ("$repo/format")) {
- $repo_exists = true ;
+ if (!is_dir ($repo) || !is_file ("$repo/format")) {
+ system ("svnadmin create $repo") ;
+ system ("svn mkdir -m'Init' file:///$repo/trunk file:///$repo/tags file:///$repo/branches") ;
+ system ("find $repo -type d | xargs chmod g+s") ;
+ }
+
+ if ($this->use_ssh) {
+ system ("chgrp -R $unix_group $repo") ;
+ if ($project->enableAnonSCM()) {
+ system ("chmod -R g+wX,o+rX-w $repo") ;
+ } else {
+ system ("chmod -R g+wX,o-rwx $repo") ;
+ }
+ } else {
+ $unix_user = $GLOBALS['sys_apache_user'];
+ system ("chown -R $unix_user:$unix_group $repo") ;
+ if ($project->enableAnonSCM()) {
+ system ("chmod -R g+wX,o+rX-w $repo") ;
+ } else {
+ system ("chmod -R g+wX,o-rwx $repo") ;
+ }
+ }
+ }
+
+ function updateRepositoryList ($params) {
+ $groups = $this->getGroups () ;
+
+ // Update WebDAV stuff
+ if (!$this->use_dav) {
+ return true ;
+ }
+
+ $access_data = '' ;
+ $password_data = '' ;
+
+ $svnusers = array () ;
+ foreach ($groups as $project) {
+ $users = $project->getMembers () ;
+ $perm = $project->getPermission ($user) ;
+ if ($perm->isMember ('scm', 0)) {
+ $svnusers[$user->getID()] = $user ;
+ }
+
+ $access_data .= '[' . $project->getUnixName () . ":/]\n" ;
+ if ($perm->isMember ('scm', 1)) {
+ $access_data .= $user->getUnixName() . "= rw\n" ;
+ } elseif ($perm->isMember ('scm', 0)) {
+ $access_data .= $user->getUnixName() . "= r\n" ;
+ }
+ if ( $project->enableAnonSCM() ) {
+ $access_data .= "anonsvn= r\n" ;
+ $access_data .= "* = r\n" ;
+
+ }
+ $access_data .= "\n" ;
+ }
+
+ foreach ($svnusers as $user_id => $user) {
+ $password_data .= $user->getUnixName ().':'.$user->getMD5Passwd ()."\n" ;
+ }
+ $password_data .= "anonsvn:$apr1$Kfr69/..$J08mbyNpD81y42x7xlFDm.\n" ;
+
+ $fname = $sys_var_path.'/svnroot-access' ;
+ $f = fopen ($fname.'.new', 'w') ;
+ fwrite ($f, $password_data) ;
+ fclose ($f) ;
+ chmod ($fname.'.new', 0644) ;
+ rename ($fname.'.new', $fname) ;
+
+ $fname = $sys_var_path.'/svnroot-authfile' ;
+ $f = fopen ($fname.'.new', 'w') ;
+ fwrite ($f, $access_data) ;
+ fclose ($f) ;
+ chmod ($fname.'.new', 0644) ;
+ rename ($fname.'.new', $fname) ;
+ }
+
+ function gatherStats ($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;
+
+ $time_ok = true ;
+
+ $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'] ;
+ $month_string = sprintf( "%04d%02d", $year, $month );
+ $start_time = gmmktime( 0, 0, 0, $month, $day, $year);
+ $end_time = $start_time + 86400;
+
+ $updates = 0 ;
+ $adds = 0 ;
+ $usr_adds = array () ;
+ $usr_updates = array () ;
+
+ $repo = $this->svn_root . '/' . $project->getUnixName() ;
+ if (!is_dir ($repo) || !is_file ("$repo/format")) {
+ echo "No repository\n" ;
+ db_rollback () ;
+ return false ;
+ }
+
+ $d1 = date ('Y-m-d', $start_time - 150000) ;
+ $d2 = date ('Y-m-d', $end_time + 150000) ;
+
+ $pipe = popen ("svn log file://$repo --xml -v -q -r '".'{'.$d2.'}:{'.$d1.'}'."' 2> /dev/null", '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',
+ array ($month_string,
+ $day,
+ $project->getID())) ;
+ if(!$res) {
+ echo "Error while cleaning stats_cvs_group\n" ;
+ 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,
+ $project->getID())) ;
+ if(!$res) {
+ echo "Error while cleaning stats_cvs_user\n" ;
+ 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");
+
+ // Analyzing history stream
+ while (!feof($pipe) &&
+ $data = fgets ($pipe, 4096)) {
+
+ if (!xml_parse ($xml_parser, $data, feof ($pipe))) {
+ debug("Unable to parse XML with error " .
+ xml_error_string(xml_get_error_code($xml_parser)) .
+ " on line " .
+ xml_get_current_line_number($xml_parser));
+ db_rollback () ;
+ return false ;
+ break;
+ }
+
+ if (!$time_ok && $last_time && $last_time > $end_time) {
+ break;
+ }
+ }
+
+ xml_parser_free ($xml_parser);
+
+ // inserting group results in stats_cvs_groups
+ 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
+ $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
+ $u = &user_get_object_by_name ($user) ;
+ if ($u) {
+ $user_id = $u->getID();
+ } else {
+ continue;
+ }
+
+ $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 ;
+ }
+ }
+ }
}
-
- if (!$repo_exists) {
- system ("svnadmin create --fs-type fsfs $repo") ;
+ db_commit();
+ }
+
+ function generateSnapshots ($params) {
+ global $sys_scm_snapshots_path ;
+ global $sys_scm_tarballs_path ;
+
+ $project = $this->checkParams ($params) ;
+ if (!$project) {
+ return false ;
+ }
+
+ $group_name = $project->getUnixName() ;
+
+ $snapshot = $sys_scm_snapshots_path.'/'.$group_name.'-scm-latest.tar.gz';
+ $tarball = $sys_scm_tarballs_path.'/'.$group_name.'-scmroot.tar.gz';
+
+ if (! $project->usesPlugin ($this->name)) {
+ return false;
}
- system ("chgrp -R $unix_group $repo") ;
- if ($project->enableAnonSCM()) {
- system ("chmod -R g+wXs,o+rX-w $repo") ;
+ if (! $project->enableAnonSCM()) {
+ unlink ($snapshot) ;
+ unlink ($tarball) ;
+ return false;
+ }
+
+ $toprepo = $this->svn_root ;
+ $repo = $toprepo . '/' . $project->getUnixName() ;
+
+ if (!is_dir ($repo) || !is_file ("$repo/format")) {
+ unlink ($snapshot) ;
+ unlink ($tarball) ;
+ return false ;
+ }
+
+ $tmp = trim (`mktemp -d`) ;
+ if ($tmp == '') {
+ return false ;
+ }
+ $today = date ('Y-m-d') ;
+ $dir = $project->getUnixName ()."-$today" ;
+ system ("mkdir -p $tmp") ;
+ $code = 0 ;
+ system ("svn ls file://$repo/trunk", $code) ;
+ if ($code == 0) {
+ system ("cd $tmp ; svn checkout file://$repo/trunk $dir > /dev/null 2>&1") ;
+ system ("tar czCf $tmp $tmp/snapshot.tar.gz $dir") ;
+ chmod ("$tmp/snapshot.tar.gz", 0644) ;
+ copy ("$tmp/snapshot.tar.gz", $snapshot) ;
+ unlink ("$tmp/snapshot.tar.gz") ;
+ system ("rm -rf $tmp/$dir") ;
} else {
- system ("chmod -R g+wXs,o-rwx $repo") ;
+ unlink ($snapshot) ;
}
+
+ 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") ;
}
}
+// 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;
+ switch ($last_tag) {
+ case "AUTHOR":
+ $last_user = ereg_replace ('[^a-z0-9_-]', '',
+ strtolower (trim ($chars))) ;
+ break;
+ case "DATE":
+ $chars = preg_replace('/T(\d\d:\d\d:\d\d)\.\d+Z?$/', ' ${1}', $chars);
+ $last_time = strtotime($chars);
+ if ($start_time <= $last_time && $last_time < $end_time) {
+ $time_ok = true;
+ } else {
+ $time_ok = false;
+ }
+ break;
+ }
+}
+
+function SVNPluginStartElement($parser, $name, $attrs) {
+ global $last_user, $last_time, $last_tag, $time_ok,
+ $adds, $updates, $usr_adds, $usr_updates;
+ $last_tag = $name;
+ switch($name) {
+ case "LOGENTRY":
+ // Make sure we clean up before doing a new log entry
+ $last_user = "";
+ $last_time = "";
+ break;
+ case "PATH":
+ if ($time_ok) {
+ if ($attrs['ACTION'] == "M") {
+ $updates++;
+ if ($last_user) {
+ $usr_updates[$last_user]++;
+ }
+ } elseif ($attrs['ACTION'] == "A") {
+ $adds++;
+ if ($last_user) {
+ $usr_adds[$last_user]++;
+ }
+ }
+ }
+ break;
+ }
+}
+
+function SVNPluginEndElement ($parser, $name) {
+ global $time_ok, $last_tag, $commits;
+ if ($name == "LOGENTRY" && $time_ok) {
+ $commits++;
+ }
+ $last_tag = "";
+}
+
// Local Variables:
// mode: php
// c-file-style: "bsd"