[Fusionforge-commits] r11902 - in branches/Branch_5_1/src: plugins/scmdarcs plugins/scmdarcs/bin plugins/scmdarcs/common plugins/scmdarcs/db plugins/scmdarcs/packaging/install www/scm

Roland Mas lolando at libremir.placard.fr.eu.org
Tue Dec 28 11:07:59 CET 2010


Author: lolando
Date: 2010-12-28 11:07:59 +0100 (Tue, 28 Dec 2010)
New Revision: 11902

Added:
   branches/Branch_5_1/src/plugins/scmdarcs/bin/
   branches/Branch_5_1/src/plugins/scmdarcs/bin/db-delete.pl
   branches/Branch_5_1/src/plugins/scmdarcs/bin/db-upgrade.pl
   branches/Branch_5_1/src/plugins/scmdarcs/db/
   branches/Branch_5_1/src/plugins/scmdarcs/db/scmdarcs-init.sql
Modified:
   branches/Branch_5_1/src/plugins/scmdarcs/common/DarcsPlugin.class.php
   branches/Branch_5_1/src/plugins/scmdarcs/packaging/install/plugin-scmdarcs
   branches/Branch_5_1/src/www/scm/browser.php
Log:
Darcs plugin: handle multiple branches per project (patch [#238] from Sylvain Le Gall)

Added: branches/Branch_5_1/src/plugins/scmdarcs/bin/db-delete.pl
===================================================================
--- branches/Branch_5_1/src/plugins/scmdarcs/bin/db-delete.pl	                        (rev 0)
+++ branches/Branch_5_1/src/plugins/scmdarcs/bin/db-delete.pl	2010-12-28 10:07:59 UTC (rev 11902)
@@ -0,0 +1,189 @@
+#!/usr/bin/perl -w
+#
+# $Id: db-delete.pl,v 1.1.1.1 2005/09/22 17:32:56 rhertzog Exp $
+#
+# Debian-specific script to delete plugin-specific tables
+# Roland Mas <lolando at debian.org>
+
+use strict ;
+use diagnostics ;
+
+use DBI ;
+use MIME::Base64 ;
+use HTML::Entities ;
+
+use vars qw/$dbh @reqlist $query/ ;
+use vars qw/$sys_default_domain $sys_cvs_host $sys_download_host
+    $sys_shell_host $sys_users_host $sys_docs_host $sys_lists_host
+    $sys_dns1_host $sys_dns2_host $FTPINCOMING_DIR $FTPFILES_DIR
+    $sys_urlroot $sf_cache_dir $sys_name $sys_themeroot
+    $sys_news_group $sys_dbhost $sys_dbname $sys_dbuser $sys_dbpasswd
+    $sys_ldap_base_dn $sys_ldap_host $admin_login $admin_password
+    $server_admin $domain_name $newsadmin_groupid $statsadmin_groupid
+    $skill_list/ ;
+use vars qw/$pluginname/ ;
+
+sub is_lesser ( $$ ) ;
+sub is_greater ( $$ ) ;
+sub debug ( $ ) ;
+sub parse_sql_file ( $ ) ;
+
+require ("/usr/share/gforge/lib/include.pl") ; # Include a few predefined functions 
+require ("/usr/share/gforge/lib/sqlparser.pm") ; # Our magic SQL parser
+
+debug "You'll see some debugging info during this installation." ;
+debug "Do not worry unless told otherwise." ;
+
+&db_connect ;
+
+# debug "Connected to the database OK." ;
+
+$pluginname = "scmdarcs" ;
+
+$dbh->{AutoCommit} = 0;
+$dbh->{RaiseError} = 1;
+eval {
+    my ($sth, @array, $version, $action, $path, $target, $rname) ;
+
+    my $pattern = "plugin_" . $pluginname . '_%' ;
+
+    $query = "SELECT relname FROM pg_class WHERE relname LIKE '$pattern' AND relkind='v'" ;
+    $sth = $dbh->prepare ($query) ;
+    $sth->execute () ;
+    while (@array = $sth->fetchrow_array ()) {
+	$rname = $array [0] ;
+	&drop_view_if_exists ($rname) ;
+    }
+    $sth->finish () ;
+
+    $query = "SELECT relname FROM pg_class WHERE relname LIKE '$pattern' AND relkind='r'" ;
+    $sth = $dbh->prepare ($query) ;
+    $sth->execute () ;
+    while (@array = $sth->fetchrow_array ()) {
+	$rname = $array [0] ;
+	&drop_table_if_exists ($rname) ;
+    }
+    $sth->finish () ;
+
+    $query = "SELECT relname FROM pg_class WHERE relname LIKE '$pattern' AND relkind='i'" ;
+    $sth = $dbh->prepare ($query) ;
+    $sth->execute () ;
+    while (@array = $sth->fetchrow_array ()) {
+	$rname = $array [0] ;
+	&drop_index_if_exists ($rname) ;
+    }
+    $sth->finish () ;
+
+    $query = "SELECT relname FROM pg_class WHERE relname LIKE '$pattern' AND relkind='s'" ;
+    $sth = $dbh->prepare ($query) ;
+    $sth->execute () ;
+    while (@array = $sth->fetchrow_array ()) {
+	$rname = $array [0] ;
+	&drop_sequence_if_exists ($rname) ;
+    }
+    $sth->finish () ;
+
+    $dbh->commit ();
+
+
+    debug "It seems your database deletion went well and smoothly.  That's cool." ;
+    debug "Please enjoy using Debian GForge." ;
+
+    # There should be a commit at the end of every block above.
+    # If there is not, then it might be symptomatic of a problem.
+    # For safety, we roll back.
+    $dbh->rollback ();
+};
+
+if ($@) {
+    warn "Transaction aborted because $@" ;
+    debug "Transaction aborted because $@" ;
+    debug "Last SQL query was:\n$query\n(end of query)" ;
+    $dbh->rollback ;
+    debug "Please report this bug on the Debian bug-tracking system." ;
+    debug "Please include the previous messages as well to help debugging." ;
+    debug "You should not worry too much about this," ;
+    debug "your DB is still in a consistent state and should be usable." ;
+    exit 1 ;
+}
+
+$dbh->rollback ;
+$dbh->disconnect ;
+
+sub debug ( $ ) {
+    my $v = shift ;
+    chomp $v ;
+    print STDERR "$v\n" ;
+}
+
+sub drop_table_if_exists ( $ ) {
+    my $tname = shift or die  "Not enough arguments" ;
+    $query = "SELECT count(*) FROM pg_class WHERE relname='$tname' AND relkind='r'" ;
+    my $sth = $dbh->prepare ($query) ;
+    $sth->execute () ;
+    my @array = $sth->fetchrow_array () ;
+    $sth->finish () ;
+
+    if ($array [0] != 0) {
+	# debug "Dropping table $tname" ;
+	$query = "DROP TABLE $tname" ;
+	# debug $query ;
+	$sth = $dbh->prepare ($query) ;
+	$sth->execute () ;
+	$sth->finish () ;
+    }
+}
+
+sub drop_sequence_if_exists ( $ ) {
+    my $sname = shift or die  "Not enough arguments" ;
+    $query = "SELECT count(*) FROM pg_class WHERE relname='$sname' AND relkind='S'" ;
+    my $sth = $dbh->prepare ($query) ;
+    $sth->execute () ;
+    my @array = $sth->fetchrow_array () ;
+    $sth->finish () ;
+
+    if ($array [0] != 0) {
+	# debug "Dropping sequence $sname" ;
+	$query = "DROP SEQUENCE $sname" ;
+	# debug $query ;
+	$sth = $dbh->prepare ($query) ;
+	$sth->execute () ;
+	$sth->finish () ;
+    }
+}
+
+sub drop_index_if_exists ( $ ) {
+    my $iname = shift or die  "Not enough arguments" ;
+    $query = "SELECT count(*) FROM pg_class WHERE relname='$iname' AND relkind='i'" ;
+    my $sth = $dbh->prepare ($query) ;
+    $sth->execute () ;
+    my @array = $sth->fetchrow_array () ;
+    $sth->finish () ;
+
+    if ($array [0] != 0) {
+	# debug "Dropping index $iname" ;
+	$query = "DROP INDEX $iname" ;
+	# debug $query ;
+	$sth = $dbh->prepare ($query) ;
+	$sth->execute () ;
+	$sth->finish () ;
+    }
+}
+
+sub drop_view_if_exists ( $ ) {
+    my $iname = shift or die  "Not enough arguments" ;
+    $query = "SELECT count(*) FROM pg_class WHERE relname='$iname' AND relkind='v'" ;
+    my $sth = $dbh->prepare ($query) ;
+    $sth->execute () ;
+    my @array = $sth->fetchrow_array () ;
+    $sth->finish () ;
+
+    if ($array [0] != 0) {
+	# debug "Dropping view $iname" ;
+	$query = "DROP VIEW $iname" ;
+	# debug $query ;
+	$sth = $dbh->prepare ($query) ;
+	$sth->execute () ;
+	$sth->finish () ;
+    }
+}

Added: branches/Branch_5_1/src/plugins/scmdarcs/bin/db-upgrade.pl
===================================================================
--- branches/Branch_5_1/src/plugins/scmdarcs/bin/db-upgrade.pl	                        (rev 0)
+++ branches/Branch_5_1/src/plugins/scmdarcs/bin/db-upgrade.pl	2010-12-28 10:07:59 UTC (rev 11902)
@@ -0,0 +1,276 @@
+#!/usr/bin/perl -w
+#
+# $Id: db-upgrade.pl,v 1.1.1.1 2005/09/22 17:32:56 rhertzog Exp $
+#
+# Debian-specific script to upgrade the database between releases
+# Roland Mas <lolando at debian.org>
+
+use strict ;
+use diagnostics ;
+
+use DBI ;
+use MIME::Base64 ;
+use HTML::Entities ;
+
+use vars qw/$dbh @reqlist $query/ ;
+use vars qw/$sys_default_domain $sys_cvs_host $sys_download_host
+    $sys_shell_host $sys_users_host $sys_docs_host $sys_lists_host
+    $sys_dns1_host $sys_dns2_host $FTPINCOMING_DIR $FTPFILES_DIR
+    $sys_urlroot $sf_cache_dir $sys_name $sys_themeroot
+    $sys_news_group $sys_dbhost $sys_dbname $sys_dbuser $sys_dbpasswd
+    $sys_ldap_base_dn $sys_ldap_host $admin_login $admin_password
+    $server_admin $domain_name $newsadmin_groupid $statsadmin_groupid
+    $skill_list/ ;
+use vars qw/$pluginname/ ;
+
+sub is_lesser ( $$ ) ;
+sub is_greater ( $$ ) ;
+sub debug ( $ ) ;
+sub parse_sql_file ( $ ) ;
+
+require ("/usr/share/gforge/lib/include.pl") ; # Include a few predefined functions 
+require ("/usr/share/gforge/lib/sqlparser.pm") ; # Our magic SQL parser
+
+debug "You'll see some debugging info during this installation." ;
+debug "Do not worry unless told otherwise." ;
+
+&db_connect ;
+
+# debug "Connected to the database OK." ;
+
+$pluginname = "scmdarcs" ;
+
+$dbh->{AutoCommit} = 0;
+$dbh->{RaiseError} = 1;
+eval {
+    my ($sth, @array, $version, $path, $target) ;
+
+    &create_metadata_table ("0") ;
+    
+    $version = &get_db_version ;
+    $target = "0.1" ;
+    if (is_lesser $version, $target) {
+	my @filelist = ( "/usr/share/gforge/plugins/$pluginname/lib/$pluginname-init.sql" ) ;
+	
+	foreach my $file (@filelist) {
+	    debug "Processing $file" ;
+	    @reqlist = @{ &parse_sql_file ($file) } ;
+	    
+	    foreach my $s (@reqlist) {
+		$query = $s ;
+		# debug $query ;
+		$sth = $dbh->prepare ($query) ;
+		$sth->execute () ;
+		$sth->finish () ;
+	    }
+	}
+	@reqlist = () ;
+	
+	&update_db_version ($target) ;
+	debug "Committing." ;
+	$dbh->commit () ;
+    }
+    
+    debug "It seems your database install/upgrade went well and smoothly.  That's cool." ;
+    debug "Please enjoy using Debian GForge." ;
+
+    # There should be a commit at the end of every block above.
+    # If there is not, then it might be symptomatic of a problem.
+    # For safety, we roll back.
+    $dbh->rollback ();
+};
+
+if ($@) {
+    warn "Transaction aborted because $@" ;
+    debug "Transaction aborted because $@" ;
+    debug "Last SQL query was:\n$query\n(end of query)" ;
+    $dbh->rollback ;
+    debug "Please report this bug on the Debian bug-tracking system." ;
+    debug "Please include the previous messages as well to help debugging." ;
+    debug "You should not worry too much about this," ;
+    debug "your DB is still in a consistent state and should be usable." ;
+    exit 1 ;
+}
+
+$dbh->rollback ;
+$dbh->disconnect ;
+
+sub is_lesser ( $$ ) {
+    my $v1 = shift || 0 ;
+    my $v2 = shift || 0 ;
+
+    my $rc = system "dpkg --compare-versions $v1 lt $v2" ;
+
+    return (! $rc) ;
+}
+
+sub is_greater ( $$ ) {
+    my $v1 = shift || 0 ;
+    my $v2 = shift || 0 ;
+
+    my $rc = system "dpkg --compare-versions $v1 gt $v2" ;
+
+    return (! $rc) ;
+}
+
+sub debug ( $ ) {
+    my $v = shift ;
+    chomp $v ;
+    print STDERR "$v\n" ;
+}
+
+sub create_metadata_table ( $ ) {
+    my $v = shift || "0" ;
+    my $tablename = "plugin_" .$pluginname . "_meta_data" ;
+    # Do we have the metadata table?
+
+    $query = "SELECT count(*) FROM pg_class WHERE relname = '$tablename' and relkind = 'r'";
+    # debug $query ;
+    my $sth = $dbh->prepare ($query) ;
+    $sth->execute () ;
+    my @array = $sth->fetchrow_array () ;
+    $sth->finish () ;
+
+    # Let's create this table if we have it not
+
+    if ($array [0] == 0) {
+	debug "Creating $tablename table." ;
+	$query = "CREATE TABLE $tablename (key varchar primary key, value text not null)" ;
+	# debug $query ;
+	$sth = $dbh->prepare ($query) ;
+	$sth->execute () ;
+	$sth->finish () ;
+    }
+
+    $query = "SELECT count(*) FROM $tablename WHERE key = 'db-version'";
+    # debug $query ;
+    $sth = $dbh->prepare ($query) ;
+    $sth->execute () ;
+    @array = $sth->fetchrow_array () ;
+    $sth->finish () ;
+
+    # Empty table?  We'll have to fill it up a bit
+
+    if ($array [0] == 0) {
+	debug "Inserting first data into $tablename table." ;
+	$query = "INSERT INTO $tablename (key, value) VALUES ('db-version', '$v')" ;
+	# debug $query ;
+	$sth = $dbh->prepare ($query) ;
+	$sth->execute () ;
+	$sth->finish () ;
+    }
+}
+
+sub update_db_version ( $ ) {
+    my $v = shift or die "Not enough arguments" ;
+    my $tablename = "plugin_" .$pluginname . "_meta_data" ;
+
+    debug "Updating $tablename table." ;
+    $query = "UPDATE $tablename SET value = '$v' WHERE key = 'db-version'" ;
+    # debug $query ;
+    my $sth = $dbh->prepare ($query) ;
+    $sth->execute () ;
+    $sth->finish () ;
+}
+
+sub get_db_version () {
+    my $tablename = "plugin_" .$pluginname . "_meta_data" ;
+
+    $query = "SELECT value FROM $tablename WHERE key = 'db-version'" ;
+    # debug $query ;
+    my $sth = $dbh->prepare ($query) ;
+    $sth->execute () ;
+    my @array = $sth->fetchrow_array () ;
+    $sth->finish () ;
+
+    my $version = $array [0] ;
+
+    return $version ;
+}
+
+sub drop_table_if_exists ( $ ) {
+    my $tname = shift or die  "Not enough arguments" ;
+    $query = "SELECT count(*) FROM pg_class WHERE relname='$tname' AND relkind='r'" ;
+    my $sth = $dbh->prepare ($query) ;
+    $sth->execute () ;
+    my @array = $sth->fetchrow_array () ;
+    $sth->finish () ;
+
+    if ($array [0] != 0) {
+	# debug "Dropping table $tname" ;
+	$query = "DROP TABLE $tname" ;
+	# debug $query ;
+	$sth = $dbh->prepare ($query) ;
+	$sth->execute () ;
+	$sth->finish () ;
+    }
+}
+
+sub drop_sequence_if_exists ( $ ) {
+    my $sname = shift or die  "Not enough arguments" ;
+    $query = "SELECT count(*) FROM pg_class WHERE relname='$sname' AND relkind='S'" ;
+    my $sth = $dbh->prepare ($query) ;
+    $sth->execute () ;
+    my @array = $sth->fetchrow_array () ;
+    $sth->finish () ;
+
+    if ($array [0] != 0) {
+	# debug "Dropping sequence $sname" ;
+	$query = "DROP SEQUENCE $sname" ;
+	# debug $query ;
+	$sth = $dbh->prepare ($query) ;
+	$sth->execute () ;
+	$sth->finish () ;
+    }
+}
+
+sub drop_index_if_exists ( $ ) {
+    my $iname = shift or die  "Not enough arguments" ;
+    $query = "SELECT count(*) FROM pg_class WHERE relname='$iname' AND relkind='i'" ;
+    my $sth = $dbh->prepare ($query) ;
+    $sth->execute () ;
+    my @array = $sth->fetchrow_array () ;
+    $sth->finish () ;
+
+    if ($array [0] != 0) {
+	# debug "Dropping index $iname" ;
+	$query = "DROP INDEX $iname" ;
+	# debug $query ;
+	$sth = $dbh->prepare ($query) ;
+	$sth->execute () ;
+	$sth->finish () ;
+    }
+}
+
+sub drop_view_if_exists ( $ ) {
+    my $iname = shift or die  "Not enough arguments" ;
+    $query = "SELECT count(*) FROM pg_class WHERE relname='$iname' AND relkind='v'" ;
+    my $sth = $dbh->prepare ($query) ;
+    $sth->execute () ;
+    my @array = $sth->fetchrow_array () ;
+    $sth->finish () ;
+
+    if ($array [0] != 0) {
+	# debug "Dropping view $iname" ;
+	$query = "DROP VIEW $iname" ;
+	# debug $query ;
+	$sth = $dbh->prepare ($query) ;
+	$sth->execute () ;
+	$sth->finish () ;
+    }
+}
+
+sub bump_sequence_to ( $$ ) {
+    my ($sth, @array, $seqname, $targetvalue) ;
+
+    $seqname = shift ;
+    $targetvalue = shift ;
+
+    do {
+	$query = "select nextval ('$seqname')" ;
+	$sth = $dbh->prepare ($query) ;
+	$sth->execute () ;
+	@array = $sth->fetchrow_array () ;
+	$sth->finish () ;
+    } until $array[0] >= $targetvalue ;
+}

Modified: branches/Branch_5_1/src/plugins/scmdarcs/common/DarcsPlugin.class.php
===================================================================
--- branches/Branch_5_1/src/plugins/scmdarcs/common/DarcsPlugin.class.php	2010-12-27 17:42:37 UTC (rev 11901)
+++ branches/Branch_5_1/src/plugins/scmdarcs/common/DarcsPlugin.class.php	2010-12-28 10:07:59 UTC (rev 11902)
@@ -42,6 +42,27 @@
 		return forge_get_config('default_server', 'scmdarcs') ;
 	}
 
+	function getRootRepositories ($project) {
+		return (forge_get_config('repos_path', 'scmdarcs') . '/' . $project->getUnixName());
+	}
+
+	function getRepositories ($project) {
+		$res = array();
+		$toprepo = $this->getRootRepositories($project);
+		if (is_dir($toprepo))
+		{
+			foreach (scandir($toprepo) as $repo_name)
+			{
+				$repo = $toprepo . '/' . $repo_name;
+				if (is_dir($repo) && is_dir($repo . '/_darcs'))
+				{
+					$res[] = $repo_name;
+				}
+			}
+		}
+		return $res;
+	}
+
 	function printShortStats ($params) {
 		$project = $this->checkParams ($params) ;
 		if (!$project) {
@@ -67,6 +88,40 @@
 		return '<p>' . _('Documentation for Darcs is available <a href="http://darcs.net/">here</a>.') . '</p>';
 	}
 
+ 	function getInstructionForDarcs ($project, $rw) {
+ 		$repo_names = $this->getRepositories($project);
+ 		if (count($repo_names) > 0)
+ 		{
+ 			$default_repo = "REPO";
+ 			if (count($repo_names) == 1)
+ 			{
+ 				$default_repo = $repo_names[0];
+ 			}
+ 			if ($rw)
+ 			{
+ 				$url = $project->getSCMBox() . ':'. $this->getRootRepositories($project) . '/' . $default_repo;
+ 			}
+ 			else
+ 			{
+ 				$url = util_make_url ('/anonscm/darcs/'.$project->getUnixName().'/' . $default_repo);
+			}
+			$b = '<p><tt>darcs get ' . $url . '</tt></p>';
+ 			if (count($repo_names) > 1)
+ 			{
+ 				$b .= _('<p>where REPO can be: ') . implode(_(', '), $repo_names) . '</p>';
+ 			}
+ 		}
+ 		else if (is_dir($this->getRootRepositories($project)))
+ 		{
+ 			$b = _('<p><em>No repositories defined.</em></p>');
+ 		}
+ 		else
+ 		{
+ 			$b = _('<p><em>Repository not yet created, wait an hour.</em></p>');
+ 		};
+ 		return $b ;
+ 	}
+ 
 	function getInstructionsForAnon ($project) {
 		$b = '<h2>';
 		$b .=  _('Anonymous Darcs Access');
@@ -74,8 +129,7 @@
 		$b .= '<p>';
 		$b .=  _('This project\'s Darcs repository can be checked out through anonymous access with the following command.');
 		$b .= '</p>';
-		$b .= '<p>' ;
-		$b .= '<tt>darcs get '.util_make_url ('/anonscm/darcs/'.$project->getUnixName().'/').'</tt>';
+		$b .= $this->getInstructionForDarcs($project, false);
 		$b .= '</p>';
 		return $b ;
 	}
@@ -87,7 +141,7 @@
 		$b .= '<p>';
 		$b .= ('Only project developers can access the Darcs 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 .= '</p>';
-		$b .= '<p><tt>darcs get '.$project->getSCMBox() . ':'. forge_get_config('repos_path', 'scmdarcs') .'/'. $project->getUnixName().'/ .</tt></p>' ;
+		$b .= $this->getInstructionForDarcs($project, true);
 		return $b ;
 	}
 
@@ -111,11 +165,21 @@
 		$b .= '<p>';
 		$b .= _('Browsing the Darcs 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 .= '</p>';
-		$b .= '<p>[' ;
-		$b .= util_make_link ("/scm/browser.php?group_id=".$project->getID(),
-				      _('Browse Darcs Repository')
-			) ;
-		$b .= ']</p>' ;
+ 		$repo_names = $this->getRepositories($project);
+ 		if (count($repo_names) > 0)
+ 		{
+ 			foreach ($repo_names as $repo_name)
+ 			{
+ 				$b .= '<p>[' ;
+ 				$b .= util_make_link ("/scm/browser.php?group_id=".$project->getID()."&repo_name=".$repo_name,
+ 									_('Browse Darcs Repository '. $repo_name));
+ 				$b .= ']</p>' ;
+ 			}
+ 		}
+ 		else
+ 		{
+ 			$b .= _('<p>No repositories to browse</p>');
+ 		}
 		return $b ;
 	}
 
@@ -170,7 +234,10 @@
 		
 		if ($project->usesPlugin ($this->name)) {
 			if ($this->browserDisplayable ($project)) {
-				print '<iframe src="'.util_make_url ("/plugins/scmdarcs/cgi-bin/darcsweb.cgi?r=".$project->getUnixName()).'" frameborder="no" width=100% height=700></iframe>' ;
+				print '<iframe src="'.
+					util_make_url ("/plugins/scmdarcs/cgi-bin/darcsweb.cgi?r=".
+					$project->getUnixName()). '/' . $params['repo_name'] .
+					'" frameborder="no" width=100% height=700></iframe>' ;
 			}
 		}
 	}
@@ -185,23 +252,74 @@
 			return false;
 		}
 
-		$repo = forge_get_config('repos_path', 'scmdarcs') . '/' . $project->getUnixName() ;
+		$toprepo = $this->getRootRepositories($project);
 		$unix_group = 'scm_' . $project->getUnixName() ;
 
-		if (!is_dir ($repo."/_darcs")) {
-			system ("mkdir -p $repo") ;
-			system ("cd $repo ; darcs init >/dev/null") ;
-			system ("find $repo -type d | xargs chmod g+s") ;
+		system("chmod g+ws $toprepo");
+
+		$result = db_query_params(
+			"SELECT repo_name, clone_repo_name FROM plugin_scmdarcs_create_repos WHERE group_id=$1",
+			array($project->getID()));
+		if (!$result)
+		{
+			echo "Error while retrieving darcs repository to create\n";
 		}
-		
-		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
+		{
+			while ($res = db_fetch_array($result))
+			{
+				$repo = $toprepo . '/' . $res['repo_name'];
+				$clone_repo = NULL;
+				if ($res['clone_repo_name'] != '')
+				{
+					$clone_repo = $toprepo . '/' . $res['clone_repo_name'];
+				}
+				if (!is_dir ($repo."/_darcs")) {
+					system ("mkdir -p '$repo'") ;
+					system ("cd $repo ; darcs init >/dev/null") ;
+					if ($clone_repo)
+					{
+						system ("darcs fetch '$clone_repo'") ;
+					}
+					system ("find $repo -type d | xargs chmod g+s") ;
+				}
+				$result1 = db_query_params(
+					"DELETE FROM plugin_scmdarcs_create_repos WHERE group_id=$1 AND repo_name=$2",
+					array($project->getID(), $res['repo_name']));
+				if (!$result1)
+				{
+					echo "Cannot remove scheduling of darcs repository creation ".$res['repo_name']."\n";
+				}
+			}
 		}
+	
+			
+		foreach ($this->getRepositories($project) as $repo_name)
+		{
+			$repo =  $toprepo . '/' . $repo_name ;
+
+			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") ;
+			}
+		}
 	}
 
+	function darcswebRepository ($project, $repo_name, $repo_url, $repo_dir) {
+			$classname = preg_replace ('/\W/', '_', 'repo_' . $repo_name) ;
+			return ("class $classname:\n"
+				."\trepodir = '$repo_dir'\n"
+				."\treponame = '$repo_name'\n"
+				."\t".'repodesc = """Repository ' . $repo_name . ' of '.$project->getPublicName().'"""'."\n"
+				."\trepourl = '" . util_make_url ('/anonscm/darcs/' . $repo_url) . "'\n"
+				."\trepoprojurl = '" . util_make_url ('/projects/' . $repo_url) . "'\n"
+				."\trepoencoding = 'utf8'\n"
+				. "\n") ;
+	}
+
+
 	function updateRepositoryList ($params) {
 		$groups = $this->getGroups () ;
 		$list = array () ;
@@ -222,18 +340,25 @@
 			. "\n") ;
 
 		foreach ($list as $project) {
-			$classname = str_replace ('-', '_',
-						  'repo_' . $project->getUnixName()) ;
-			
-			$repo = forge_get_config('repos_path', 'scmdarcs') . '/' . $project->getUnixName() ;
-			fwrite ($f, "class $classname:\n"
-				."\treponame = '".$project->getUnixName()."'\n"
-				."\t".'repodesc = """'.$project->getPublicName().'"""'."\n"
-				."\trepodir = '$repo'\n"
-				."\trepourl = '" . util_make_url ('/anonscm/darcs/'.$project->getUnixName().'/') . "'\n"
-				."\trepoprojurl = '" . util_make_url ('/projects/'.$project->getUnixName().'/') . "'\n"
-				."\trepoencoding = 'utf8'\n"
-				. "\n") ;
+			$unix_name = $project->getUnixName();
+			$toprepo = $this->getRootRepositories($project);
+			$repo_names = $this->getRepositories($project);
+			foreach ($repo_names as $repo_name) {
+				if ($repo_name == $unix_name)
+				{
+					# Default repository name, we create a default entry for it
+					fwrite ($f,
+						$this->darcswebRepository($project, 
+																			"$unix_name", 
+																			"$unix_name/$repo_name", 
+																			"$toprepo/$repo_name"));
+				}
+				fwrite ($f, 
+					$this->darcswebRepository($project, 
+																		"$unix_name/$repo_name", 
+																		"$unix_name/$repo_name", 
+																		"$toprepo/$repo_name"));
+			}
 		}
 		fclose ($f) ;
 		chmod ($fname.'.new', 0644) ;
@@ -261,8 +386,9 @@
 			return false;
 		}
 
+		# TODO: multi dir
 		$toprepo = forge_get_config('repos_path', 'scmdarcs') ;
-		$repo = $toprepo . '/' . $project->getUnixName() ;
+		$repo = $this->getRootRepositories($project);
 
 		if (!is_dir ($repo)) {
 			unlink ($tarball) ;
@@ -320,19 +446,10 @@
 			$usr_updates = array () ;
 			$usr_deletes = array ();
 		
-			$repo = forge_get_config('repos_path', 'scmdarcs') . '/' . $project->getUnixName() ;
-			if (!is_dir ($repo) || !is_dir ("$repo/_darcs")) {
-				echo "No repository\n" ;
-				db_rollback () ;
-				return false ;
-			}
-		
+			$toprepo = $this->getRootRepositories($project) ;
 			$from_date = date("c", $start_time);
 			$to_date   = date("c", $end_time);
-			$pipe = popen("darcs changes --repodir='$repo' "
-				      ."--match 'date \"between $from_date and $to_date\"' "
-				      ."--xml -s\n", '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,
@@ -354,26 +471,44 @@
 				return false ;
 			}
 		
-			$xml_parser = xml_parser_create();
-			xml_set_element_handler($xml_parser, "DarcsPluginStartElement", "DarcsPluginEndElement");
-		
-			// 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));
+			foreach ($this->getRepositories($project) as $repo_name)
+			{
+				$repo = $toprepo . '/' . $repo_name;
+				if (!is_dir ($repo) || !is_dir ("$repo/_darcs")) {
+					echo "No repository $repo\n" ;
 					db_rollback () ;
 					return false ;
-					break;
 				}
+				else
+				{
+					echo "$repo\n";
+				}
+		
+				$pipe = popen("darcs changes --repodir='$repo' "
+								."--match 'date \"between $from_date and $to_date\"' "
+								."--xml -s\n", 'r');
+			
+				$xml_parser = xml_parser_create();
+				xml_set_element_handler($xml_parser, "DarcsPluginStartElement", "DarcsPluginEndElement");
+			
+				// 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;
+					}
+				}
+				
+				xml_parser_free ($xml_parser);
 			}
 			
-			xml_parser_free ($xml_parser);
-			
 			// inserting group results in stats_cvs_groups
 		
 			if (!db_query_params ('INSERT INTO stats_cvs_group (month,day,group_id,checkouts,commits,adds) VALUES ($1,$2,$3,$4,$5,$6)',
@@ -455,7 +590,98 @@
 			db_commit();
 		}
 	}
-  }	
+
+	function printAdminPage ($params) {
+		parent::printAdminPage($params);
+
+		$project = $this->checkParams($params);
+		if (!$project)
+		{
+			return false;
+		}
+
+		if ($project->usesPlugin($this->name))
+		{
+			$result = db_query_params(
+				"SELECT repo_name FROM plugin_scmdarcs_create_repos WHERE group_id=$1",
+				array($project->getID()));
+			if ($result && db_numrows($result) > 0)
+			{
+				$nm = array ();
+				while ($res = db_fetch_array($result))
+				{
+					array_push($nm, $res['repo_name']);
+				}
+				print '<p><strong>'._('Repository to be created: ') . '</strong>' . 
+					implode(_(', '), $nm) . '</p>';
+			}
+
+			print '<p><strong>Create new repository:</strong></p>';
+			print '<p>'._('Repository name: ').
+				'<input type="string" name="scm_create_repo_name" size=16 maxlength=128 /></p>';
+			print '<p>'._('Clone: ').
+				'<select name="scm_clone_repo_name">';
+			print '<option value="">&lt;none&gt;</option>';
+			foreach ($this->getRepositories($project) as $repo_name)
+			{
+				print '<option value="'.$repo_name.'">'.$repo_name.'</option>';
+			}
+			print '</select></p>';
+		}
+	}
+
+	function adminUpdate ($params) {
+		parent::adminUpdate($params);
+
+		$project = $this->checkParams($params);
+		if (!$project)
+		{
+			return false;
+		}
+
+		$new_repo_name = $params['scm_create_repo_name'];
+		$clone_repo_name = $params['scm_clone_repo_name'];
+		if ($new_repo_name != '')
+		{
+			$repo_names = $this->getRepositories($project);
+			if (in_array($new_repo_name, $repo_names))
+			{
+				html_error_top(_("Repository $new_repo_name already exists"));
+				return false;
+			}
+
+			if ($clone_repo_name != '' && !in_array($clone_repo_name, $repo_names))
+			{
+				html_error_top(_("Clone repository $clone_repo_name doesn't exist"));
+				return false;
+			}
+			if ($clone_repo_name == '<none>')
+			{
+				$clone_repo_name = '';
+			}
+
+			if (!preg_match('/^[\w][-_\w\d\.]+$/', $new_repo_name))
+			{
+				html_error_top("Invalid repository name $new_repo_name");
+				return false;
+			}
+
+			db_begin ();
+			if (!db_query_params ('INSERT INTO plugin_scmdarcs_create_repos (group_id,repo_name,clone_repo_name) 
+				VALUES ($1,$2,$3)',
+				array($project->getID(), $new_repo_name, $clone_repo_name)))
+			{
+				html_error_top("SQL error while scheduling new repository $new_repo_name");
+				db_rollback () ;
+				return false ;
+			}
+			db_commit ();
+
+			html_feedback_top(_("Repository $new_repo_name schedule for creation"));
+		}
+	}
+
+}	
 		
 function DarcsPluginStartElement($parser, $name, $attrs) {
 	global $last_user, $commits, 
@@ -464,6 +690,18 @@
 	switch($name) {
 	case "PATCH":
 		$last_user = $attrs['AUTHOR'];
+		if (!array_key_exists($last_user, $usr_deletes))
+		{
+			$usr_deletes[$last_user] = 0;
+		}
+		if (!array_key_exists($last_user, $usr_updates))
+		{
+			$usr_updates[$last_user] = 0;
+		}
+		if (!array_key_exists($last_user, $usr_adds))
+		{
+			$usr_adds[$last_user] = 0;
+		}
 		$commits++;
 		break;
 	case "REMOVE_FILE":

Added: branches/Branch_5_1/src/plugins/scmdarcs/db/scmdarcs-init.sql
===================================================================
--- branches/Branch_5_1/src/plugins/scmdarcs/db/scmdarcs-init.sql	                        (rev 0)
+++ branches/Branch_5_1/src/plugins/scmdarcs/db/scmdarcs-init.sql	2010-12-28 10:07:59 UTC (rev 11902)
@@ -0,0 +1,9 @@
+CREATE TABLE plugin_scmdarcs_create_repos (
+	group_id int NOT NULL,
+	repo_name character varying(128) NOT NULL,
+	clone_repo_name character varying(128),
+	FOREIGN KEY (group_id) REFERENCES groups (group_id) ON DELETE CASCADE ON UPDATE CASCADE,
+	CONSTRAINT plugin_scmdarcs_personal_repos_unique UNIQUE (group_id, repo_name)
+) ;
+
+CREATE INDEX plugin_scmdarcs_create_repos_gid_idx ON plugin_scmdarcs_create_repos (group_id) ;

Modified: branches/Branch_5_1/src/plugins/scmdarcs/packaging/install/plugin-scmdarcs
===================================================================
--- branches/Branch_5_1/src/plugins/scmdarcs/packaging/install/plugin-scmdarcs	2010-12-27 17:42:37 UTC (rev 11901)
+++ branches/Branch_5_1/src/plugins/scmdarcs/packaging/install/plugin-scmdarcs	2010-12-28 10:07:59 UTC (rev 11902)
@@ -1,3 +1,5 @@
+plugins/scmdarcs/bin/*		usr/share/gforge/plugins/scmdarcs/bin/
 plugins/scmdarcs/common/*               usr/share/gforge/plugins/scmdarcs/common/
+plugins/scmdarcs/db/*		usr/share/gforge/plugins/scmdarcs/lib/
 plugins/scmdarcs/etc/plugins/scmdarcs/* etc/gforge/plugins/scmdarcs/
 plugins/scmdarcs/etc/*.ini 		etc/@PACKAGE@/config.ini.d/

Modified: branches/Branch_5_1/src/www/scm/browser.php
===================================================================
--- branches/Branch_5_1/src/www/scm/browser.php	2010-12-27 17:42:37 UTC (rev 11901)
+++ branches/Branch_5_1/src/www/scm/browser.php	2010-12-28 10:07:59 UTC (rev 11902)
@@ -31,8 +31,11 @@
 $group_id = getIntFromRequest("group_id");
 scm_header(array('title'=>_('SCM Repository'),'group'=>$group_id));
 
+$repo_name = getStringFromRequest("repo_name", "none");
+
 $hook_params = array () ;
 $hook_params['group_id'] = $group_id ;
+$hook_params['repo_name'] = $repo_name ;
 plugin_hook ("scm_browser_page", $hook_params) ;
 
 scm_footer(); 




More information about the Fusionforge-commits mailing list