[Developers] Subversion support for GetCactus

Frank Loeffler frank.loeffler at aei.mpg.de
Fri Sep 28 16:44:56 CDT 2007


Hi,

this patch adds Subversion support for GetCactus. I tried this for some
thorns using https as transport method, but it should work for anything
that Subversion can handle.

I tried not to change anything related to CVS and to keep the structure
of the file as it was as much as possible. However, in this patch I
also fix a obvious typo ($foundit instead of elsewhere unused $foundif)
in the CVS code and I added a comment to what I think is another mistake
in the CVS code, but I did not change the actual code (search for
'mistake' and feel free to fix it, which would be trivial).

Frank

Index: GetCactus
===================================================================
RCS file: /cactus/Utilities/Scripts/GetCactus,v
retrieving revision 1.58
diff -u -r1.58 GetCactus
--- GetCactus	12 May 2004 16:33:33 -0000	1.58
+++ GetCactus	28 Sep 2007 21:35:25 -0000
@@ -48,6 +48,7 @@
     print "\t-install=\"\"     : (default: ./Cactus)\n";
     print "\t-anonymous=\"\"   : [yes/no] (default: yes)\n";
     print "\t-cvs=\"\"         : [<cvs client>] (default: cvs)\n";
+    print "\t-svn=\"\"         : [<svn client>] (default: svn)\n";
     print "\t-repository=\"\"  : [stable/development] (default: stable)\n";
     print "\t-verbose=\"\"     : [yes/no] (default: no)\n";
     print "\t-defaults         : instruct program to use defaults when unsure\n";
@@ -69,6 +70,8 @@
 # Check that CVS is on the system
 $cvs = &CVSFound if (!defined $cvs);
 DIE("cvs not found") if (!$cvs);
+# Check if SVN is on the system
+$svn = &SVNFound if (!defined $svn);
 
 
 # Look for ThornList
@@ -194,8 +197,9 @@
    next if ($key !~ /REPOSITORY/);
    if ($rep !~ $thorns{$key}) {
       $thorns{$key} =~ /(.*:)(.*?)(\/.*)/;
-      if ($2 eq "") {
-         my $temprepos = "${1}2401${3}";
+      my $tmp = $3;
+      if (($2 eq "") && ($1 =~ /:pserver.*/)) {
+         my $temprepos = "${1}2401${tmp}";
          if ($rep !~ $temprepos) {
             $unknownreps{$thorns{$key}} = 1;
          }
@@ -214,8 +218,8 @@
 chdir $installdir;
 $thorns{"THORNS"} = &ShouldWeUpdate("$cactusdir/arrangements/", $thorns{"THORNS"});
 
-# Get CVS options
-$cvs_options = &CVSOptions;
+# Get client options
+($cvs_options,$svn_options) = &CheckoutOptions;
 
 # Checkout the flesh
 # (if already checked out, get the checked out repository)
@@ -311,10 +315,11 @@
   {
     $cvs = "cvs ";
   }
-  $foundif = 0;
+  $foundit = 0;
   open(MODULES,"$cvs -v | ");
   while (<MODULES>)
   {
+    # Frank Loeffler: Isn't this '!' in the next line a mistake?
     if (!/Concurrent Versions System/)
     {
       $foundit = $cvs;
@@ -327,6 +332,63 @@
 }
 
 
+#/*@@
+#  @routine   SVNFound
+#  @date      Sep 2007
+#  @author    Frank Loeffler
+#  @desc
+#  See if svn is installed on the machine
+#  @enddesc
+#  @calls
+#  @calledby
+#  @history   copy of CVSFound with small changes
+#
+#  @endhistory
+#
+#@@*/
+
+sub SVNFound
+{
+
+  my($foundit);
+
+  # here we do thing differently than cvs, because I (Frank Loeffler) think
+  # that way is wrong. This script should by default choose the version of
+  # Subversion which is first in the user's path, if there is one.
+  $svn = "svn ";
+  $foundit = 0;
+  open(MODULES,"$svn --version | ");
+  while (<MODULES>)
+  {
+    if (/Subversion/)
+    {
+      $foundit = $svn;
+    }
+  }
+  close(MODULES);
+  if ($foundit eq 0)
+  {
+    if (-e "/usr/local/bin/svn")
+    {
+      $svn = "/usr/local/bin/svn ";
+    }
+    elsif (-e "/usr/ncsa/bin/svn")
+    {
+      $svn = "/usr/ncsa/bin/svn ";
+    }
+  }
+  open(MODULES,"$svn --version | ");
+  while (<MODULES>)
+  {
+    if (/Subversion/)
+    {
+      $foundit = $svn;
+    }
+  }
+
+  return $foundit;
+
+}
 
 #/*@@
 #  @routine   GetLoginName
@@ -818,7 +880,7 @@
 
           if ($debug != 1)
           {
- 	    &RunCVSCommand($command, 1);
+ 	    &RunCommand($command, 1);
             #open(CVSCO,$command);
             #while (<CVSCO>)
             #{
@@ -849,7 +911,7 @@
 
     if ($debug != 1)
     {
-      &RunCVSCommand($command, 1);
+      &RunCommand($command, 1);
       #open(CVSCO,$command);
       #while (<CVSCO>)
       #{
@@ -954,6 +1016,7 @@
 ####################################
 sub GetOneThorn {
     my ($fleshrep, $options, $tag, $th, %thorns) = @_;
+    my $client, $svn_repository;
 
     $answer = "";
 
@@ -1032,6 +1095,33 @@
 
       } # rep !~ $thorns{$th....
     } # ... =~ /pserver...
+    if ($thorns{"$th REPOSITORY"} =~ /svn/)
+    {
+      if ($svn eq 0)
+      {
+        DIE("Did not find Subversion binary 'svn', but Subversion repository ".
+            "checkout/update was requested.");
+      }
+      $client = "svn";
+      $svn_repository = $thorns{"$th REPOSITORY"};
+      if ($svn_repository =~ /svn:(.+)/)
+      {
+        $svn_repository = $1;
+      }
+      else
+      {
+        $svn_repository = "svn://";
+      }
+    }
+    else
+    {
+      $client = "cvs";
+    }
+      if ($svn eq 0)
+      {
+        DIE("Did not find Subversion binary 'svn', but Subversion repository ".
+            "checkout/update was requested.");
+      }
 
     $th =~ /(.*?)\//;
     my $cur_arrangement = $1;
@@ -1045,10 +1135,10 @@
        $arrangement_dirs{$cur_arrangement} = 1;
 
        my $command = "$cvs $cvs_options checkout -l $cur_arrangement $tag 2>&1 |";
-       &RunCVSCommand($command, 0);
+       &RunCommand($command, 0);
 
        $command = "$cvs $cvs_options checkout ${cur_arrangement}/doc $tag 2>&1 |";
-       &RunCVSCommand($command, 0);
+       &RunCommand($command, 0);
     }
 
     # Checkout or update
@@ -1067,9 +1157,33 @@
       }
       if ($answer =~ /^y/i)
       {
-        open(REP,"<$th/CVS/Root") || DIE("No CVS files for $th");
-        $installedrep = <REP>;
-        close(REP);
+        if ($client =~ /cvs/)
+        {
+          open(REP,"<$th/CVS/Root") || DIE("No CVS files for $th");
+          $installedrep = <REP>;
+          close(REP);
+        }
+        if ($client =~ /svn/)
+        {
+          $installedrep = 0;
+          open(REP,"$svn info $th | ");
+          while (<REP>)
+          {
+            if (!/URL: (.*)$/)
+            {
+              my $tmp = quotemeta($th);
+              if ($1 =~ /(.*)\/$tmp/)
+              {
+                $installedrep = $1
+              }
+            }
+          }
+          close(REP);
+          if ($installedrep eq 0)
+          {
+            DIE("Could not figure out Subversion URL for $th");
+          }
+        }
         chomp $installedrep;
 
         my $tp = $thorns{"$th REPOSITORY"};
@@ -1079,16 +1193,23 @@
 #        if (($thorns{"$th REPOSITORY"} !~ m:^$installedrep$:))
         if ($tp ne $installedrep)
         {
-          print "\n WARNING: GetCactus is refusing to update $th\n          Thorn installed from different repository\n          ($installedrep)\n";
+          print "\n WARNING: GetCactus is refusing to update $th\n          Thorn installed from different repository\n          ($installedrep!=$tp)\n";
         }
         else
         {
           print " Updating $th\n";
-          $command_up = "$cvs $cvs_options -d $thorns{\"$th REPOSITORY\"} update -d $tag $th 2>&1|";
-          print "  (CVS repository: $thorns{\"$th REPOSITORY\"})\n";
+          if ($client =~ /cvs/)
+          {
+            $command_up = "$cvs $cvs_options -d $thorns{\"$th REPOSITORY\"} update -d $tag $th 2>&1|";
+          }
+          if ($client =~ /svn/)
+          {
+            $command_up = "$svn $svn_options update $th 2>&1|";
+          }
+          print "  (Repository: $thorns{\"$th REPOSITORY\"})\n";
           if ($debug != 1)
           {
-	    &RunCVSCommand($command_up, 1);
+	    &RunCommand($command_up, 1);
             #open(CVSCO,$command_up);
             #while (<CVSCO>)
             #{
@@ -1107,12 +1228,19 @@
     {
 
 
-    print " Checking out thorn $th\n   CVS repository: $thorns{\"$th REPOSITORY\"}\n   CVS module: $thorns{\"$th MODULE\"}\n\n";
+    print " Checking out thorn $th\n   repository: $thorns{\"$th REPOSITORY\"}\n   module: $thorns{\"$th MODULE\"}\n\n";
 
 
       if ($th eq $thorns{"$th MODULE"})
       {
-        $command_co = "$cvs $cvs_options -d $thorns{\"$th REPOSITORY\"} co $CHECKOUT_OPTIONS $tag $th 2>&1|";
+        if ($client =~ /cvs/)
+        {
+          $command_co = "$cvs $cvs_options -d $thorns{\"$th REPOSITORY\"} co $CHECKOUT_OPTIONS $tag $th 2>&1|";
+        }
+        if ($client =~ /svn/)
+        {
+          $command_co = "$svn $svn_options co $CHECKOUT_OPTIONS $tag $svn_repository/$th $th 2>&1|";
+        }
         $check_dir = "";
       }
       else
@@ -1120,7 +1248,14 @@
         $th =~ m:^(.*)/(.*):;
         $check_dir = $1;
         $call_thorn = $2;
-        $command_co = "$cvs $cvs_options -d $thorns{\"$th REPOSITORY\"} co -d $call_thorn $tag $thorns{\"$th MODULE\"} 2>&1|";
+        if ($client =~ /cvs/)
+        {
+          $command_co = "$cvs $cvs_options -d $thorns{\"$th REPOSITORY\"} co -d $call_thorn $tag $thorns{\"$th MODULE\"} 2>&1|";
+        }
+        if ($client =~ /svn/)
+        {
+          $command_co = "$svn $svn_options co $CHECKOUT_OPTIONS $tag $svn_repository/$thorns{\"$th MODULE\"} $thorns{\"$th MODULE\"} 2>&1|";
+        }
       }
 
       if ($debug != 1)
@@ -1141,7 +1276,7 @@
           chdir $check_dir;
         }
 
-        &RunCVSCommand($command_co, 1);
+        &RunCommand($command_co, 1);
         #open(CVSCO,$command_co);
         #while (<CVSCO>)
         #{
@@ -1162,7 +1297,7 @@
     }
 }
 
-sub RunCVSCommand
+sub RunCommand
 {
    my $command = shift;
    my $display_results = shift;
@@ -1182,19 +1317,19 @@
 #  @date      Sat Mar 11 15:31:55 CET 2000
 #  @author    Gabrielle Allen
 #  @desc
-#  Get options to be passed to CVS
+#  Get options to be passed to CVS/Subversion
 #  @enddesc
 #  @calls
 #  @calledby
-#  @history
+#  @history   Sep 2007, Frank Loeffler, modified to include subversion options
 #
 #  @endhistory
 #
 #@@*/
 
-sub CVSOptions
+sub CheckoutOptions
 {
-  my($answer,$cvs_options);
+  my($answer,$cvs_options,$svn_options);
 
   # Chose information or not
   do
@@ -1219,29 +1354,32 @@
     elsif ($answer =~ /^y/i)
     {
       $cvs_options = " -z9 ";
+      $svn_options = "";
     }
     else
     {
       $cvs_options = " -Q -z9 ";
+      $svn_options = " -q";
     }
   } while ($answer =~ /^h/i);
 
-  return $cvs_options;
+  return ($cvs_options, $svn_options);
 
 }
 
 sub VerboseCheckoutHelp
 {
   print "\n\n";
-  print " CactusCode CVS checkout options\n";
+  print " CactusCode checkout options\n";
   print " -------------------------------\n\n";
   print " By default, all checkouts using this script use the option -z9\n";
-  print " which transfers a compressed version of each file across the \n";
+  print " for CVS which transfers a compressed version of each file across the \n";
   print " network\n\n";
   print " Choosing verbose checkout provides a report of all the files\n";
-  print " as they are checked out from the chosen CVS repository, by using \n";
-  print " the option -Q\n\n";
-  print " cvs -z9 [-Q] -d <repository name> checkout <module name>\n\n";
+  print " as they are checked out from the chosen repository, by using \n";
+  print " the option -Q for CVS and -q fuer Subversion\n\n";
+  print " cvs -z9 [-Q] -d <repository name> checkout <module name>\n";
+  print " svn [-q] method://<repository URL> co <module name>\n\n";
 }
 
 
@@ -1490,8 +1628,16 @@
       }
       elsif ($directive =~ "REPOSITORY_PORT")
       {
-         if ($value ne "2401") {
-            $repository_port = $value;
+         if ( $repository_type =~ /svn/ )
+         {
+           $repository_port = $value;
+         }
+         else
+         {
+           if ($value ne "2401")
+           {
+              $repository_port = $value;
+           }
          }
          next;
       }
@@ -1513,7 +1659,18 @@
     $name = &StripSpaces($1);
 
     # Thorn repository
-    $rep = ":$repository_type:$repository_user\@$repository_location:${repository_port}${repository_name}";
+    if ( $repository_type =~ /svn$/ )
+    {
+      $rep = "$repository_type://$repository_user\@$repository_location:${repository_port}${repository_name}";
+    }
+    elsif ( $repository_type =~ /svn:/ )
+    {
+      $rep = "$repository_type$repository_user\@$repository_location:${repository_port}${repository_name}";
+    }
+    else
+    {
+      $rep = ":$repository_type:$repository_user\@$repository_location:${repository_port}${repository_name}";
+    }
 
     if ($name && $rep)
     {
@@ -1660,6 +1817,13 @@
     print "              <arrangement name>/<thorn name>.\n\n";
     print " Sample thorn lists are provided on the Cactus Code web pages at \n\n";
     print "              www.cactuscode.org/Download/ThornLists/index.html\n\n";
+    print " This script also supports thorns in Subversion rather than CVS. In order\n";
+    print " to use this, Subversion has to be properly installed on your machine. You\n";
+    print " can check that by typing\n\n";
+    print "   svn --version\n\n";
+    print " This should give you information about the version of Subversion which is\n";
+    print " installed. If it is not installed, you can freely obtain it from\n\n";
+    print "   http://subversion.tigris.org/\n\n";
 
     print " The latest release of the Cactus Code (flesh and thorns) can also\n";
     print " be obtained as a tar file from our web site at \n\n";
@@ -1746,18 +1910,19 @@
   print " DESCRIPTION \n";
   print "     Description of the thornlist\n";
   print " REPOSITORY_TYPE \n";
-  print "     pserver\n";
+  print "     e.g. pserver, svn, svn:http://, svn:https://\n";
   print " REPOSITORY_TAG \n";
   print "     tag to use when checking out\n";
   print " REPOSITORY_USER \n";
   print "     user name for checking out\n";
   print " REPOSITORY_NAME \n";
-  print "     name of CVS repository (location in filesystem)\n";
+  print "     name of repository (location in filesystem)\n";
   print " REPOSITORY_LOCATION \n";
-  print "     CVS server machine\n";
+  print "     server machine\n";
   print " REPOSITORY_PORT\n";
-  print "     CVS server port number, defaults to 2401\n\n";
-
+  print "     server port number, defaults to 2401 for CVS. For Subversion\n";
+  print "     you can enter the port directly into REPOSITORY_LOCATION. Use\n";
+  print "     REPOSITORY_PORT after REPOSITORY_TYPE.\n\n";
 }
 
 
@@ -1826,7 +1991,7 @@
   print " Using Non Cactus Repositories\n";
   print " -----------------------------\n\n";
   print " Thorn lists can also be used to checkout thorns from\n";
-  print " other CVS repositories. These repositories may, or may not,\n";
+  print " other CVS or Subversion repositories. These repositories may, or may not,\n";
   print " require you to give a username and password depending on their\n";
   print " access mechanism.\n\n";
 }


--- StripMime Report -- processed MIME parts ---
multipart/mixed
  text/plain (text body -- kept)
  text/plain (text body -- kept)
---


More information about the Developers mailing list