changeset 241:7658d21a1493 feature_73

A bit more work on external repo conversion script
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Tue, 22 Feb 2011 17:49:00 +0000
parents 6c282df74a30
children bde4f47b6427
files extra/soundsoftware/convert-external-repos.rb extra/soundsoftware/reposman-soundsoftware.rb extra/soundsoftware/update-external-repo.sh
diffstat 3 files changed, 56 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/extra/soundsoftware/convert-external-repos.rb	Tue Feb 22 16:50:58 2011 +0000
+++ b/extra/soundsoftware/convert-external-repos.rb	Tue Feb 22 17:49:00 2011 +0000
@@ -2,10 +2,8 @@
 
 # == Synopsis
 #
-# convert-external-repos: Update local Mercurial mirrors of external repos
-#
-# This command is specific to the SoundSoftware Redmine instance and
-# its use of Mercurial repositories.  It makes use of the hg convert extension.
+# convert-external-repos: Update local Mercurial mirrors of external repos,
+# by running an external command for each project requiring an update.
 #
 # == Usage
 #
@@ -13,12 +11,16 @@
 #     
 # == Arguments (mandatory)
 #
-#   -h, --hg-dir=DIR          use DIR as base directory for repositories
+#   -s, --scm-dir=DIR         use DIR as base directory for repositories
 #   -r, --redmine-host=HOST   assume Redmine is hosted on HOST. Examples:
 #                             -r redmine.example.net
 #                             -r http://redmine.example.net
 #                             -r https://example.net/redmine
 #   -k, --key=KEY             use KEY as the Redmine API key
+#   -c, --command=COMMAND     use this command to update each external
+#                             repository: command is called with the name
+#                             of the project, the path to its repo, and
+#                             its external repo url as its three args
 #
 # == Options
 #
@@ -39,11 +41,12 @@
 Version = "1.0"
 
 opts = GetoptLong.new(
-                      ['--hg-dir',       '-h', GetoptLong::REQUIRED_ARGUMENT],
+                      ['--scm-dir',      '-s', GetoptLong::REQUIRED_ARGUMENT],
                       ['--redmine-host', '-r', GetoptLong::REQUIRED_ARGUMENT],
                       ['--key',          '-k', GetoptLong::REQUIRED_ARGUMENT],
                       ['--http-user',          GetoptLong::REQUIRED_ARGUMENT],
                       ['--http-pass',          GetoptLong::REQUIRED_ARGUMENT],
+                      ['--command' ,     '-c', GetoptLong::REQUIRED_ARGUMENT],
                       ['--test',         '-t', GetoptLong::NO_ARGUMENT],
                       ['--verbose',      '-v', GetoptLong::NO_ARGUMENT],
                       ['--version',      '-V', GetoptLong::NO_ARGUMENT],
@@ -72,11 +75,12 @@
 begin
   opts.each do |opt, arg|
     case opt
-    when '--hg-dir';         $repos_base   = arg.dup
+    when '--scm-dir';        $repos_base   = arg.dup
     when '--redmine-host';   $redmine_host = arg.dup
     when '--key';            $api_key      = arg.dup
     when '--http-user';      $http_user    = arg.dup
     when '--http-pass';      $http_pass    = arg.dup
+    when '--command';        $command      = arg.dup
     when '--verbose';        $verbose += 1
     when '--test';           $test = true
     when '--version';        puts Version; exit
@@ -92,7 +96,7 @@
   log("running in test mode")
 end
 
-if ($redmine_host.empty? or $repos_base.empty?)
+if ($redmine_host.empty? or $repos_base.empty? or $command.empty?)
   RDoc::usage
 end
 
@@ -158,26 +162,12 @@
 
   repos_path = File.join($repos_base, project.identifier).gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR)
 
-  unless File.directory?($repos_path)
-    log("project repo directory '#{$repos_path}' doesn't exist")
+  unless File.directory?(repos_path)
+    log("\tproject repo directory '#{repos_path}' doesn't exist")
     next
   end
 
-  # We need to handle different source repository types separately.
-  # 
-  # The convert extension cannot convert directly from a remote git
-  # repo; we have to mirror to a local repo first.  Incremental
-  # conversions do work though.
-  # 
-  # We can of course convert directly from remote Subversion repos,
-  # but we need to keep track of that -- you can ask to convert into a
-  # repo that has already been used (for Mercurial) and it'll do so
-  # happily; we don't want that.
-  #
-  # Converting from a remote Hg repo should be fine!
-  #
-
-  
+  system($command, project.identifier, repos_path, external_url)
 
 end
   
--- a/extra/soundsoftware/reposman-soundsoftware.rb	Tue Feb 22 16:50:58 2011 +0000
+++ b/extra/soundsoftware/reposman-soundsoftware.rb	Tue Feb 22 17:49:00 2011 +0000
@@ -9,12 +9,12 @@
 #    reposman [OPTIONS...] -s [DIR] -r [HOST]
 #     
 #  Examples:
-#    reposman --svn-dir=/var/svn --redmine-host=redmine.example.net --scm subversion
+#    reposman --scm-dir=/var/svn --redmine-host=redmine.example.net --scm subversion
 #    reposman -s /var/git -r redmine.example.net -u http://svn.example.net --scm git
 #
 # == Arguments (mandatory)
 #
-#   -s, --svn-dir=DIR         use DIR as base directory for svn repositories
+#   -s, --scm-dir=DIR         use DIR as base directory for repositories
 #   -r, --redmine-host=HOST   assume Redmine is hosted on HOST. Examples:
 #                             -r redmine.example.net
 #                             -r http://redmine.example.net
@@ -70,7 +70,7 @@
 SUPPORTED_SCM = %w( Subversion Darcs Mercurial Bazaar Git Filesystem )
 
 opts = GetoptLong.new(
-                      ['--svn-dir',      '-s', GetoptLong::REQUIRED_ARGUMENT],
+                      ['--scm-dir',      '-s', GetoptLong::REQUIRED_ARGUMENT],
                       ['--redmine-host', '-r', GetoptLong::REQUIRED_ARGUMENT],
                       ['--key',          '-k', GetoptLong::REQUIRED_ARGUMENT],
                       ['--owner',        '-o', GetoptLong::REQUIRED_ARGUMENT],
@@ -133,7 +133,7 @@
 begin
   opts.each do |opt, arg|
     case opt
-    when '--svn-dir';        $repos_base   = arg.dup
+    when '--scm-dir';        $repos_base   = arg.dup
     when '--redmine-host';   $redmine_host = arg.dup
     when '--key';            $api_key      = arg.dup
     when '--owner';          $svn_owner    = arg.dup; $use_groupid = false;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extra/soundsoftware/update-external-repo.sh	Tue Feb 22 17:49:00 2011 +0000
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+project="$1"
+local_repo="$2"
+remote_repo="$3"
+
+if [ -z "$project" ] || [ -z "$local_repo" ] || [ -z "$remote_repo" ]; then
+    echo "Usage: $0 <project> <local-repo-path> <remote-repo-url>"
+    exit 2
+fi
+
+
+  # We need to handle different source repository types separately.
+  # 
+  # The convert extension cannot convert directly from a remote git
+  # repo; we'd have to mirror to a local repo first.  Incremental
+  # conversions do work though.  The hg-git plugin will convert
+  # directly from remote repositories, but not via all schemes
+  # (e.g. https is not currently supported).  It's probably easier to
+  # use git itself to clone locally and then convert or hg-git from
+  # there.
+  # 
+  # We can of course convert directly from remote Subversion repos,
+  # but we need to keep track of that -- you can ask to convert into a
+  # repo that has already been used (for Mercurial) and it'll do so
+  # happily; we don't want that.
+  #
+  # Converting from a remote Hg repo should be fine!
+  #
+  # One other thing -- we can't actually tell the difference between
+  # the various SCM types based on URL alone.  We have to try them
+  # (ideally in an order determined by a guess based on the URL) and
+  # see what happens.
+
+
+  
+