Index: extra/svn/reposman.rb =================================================================== --- extra/svn/reposman.rb (revision 3768) +++ extra/svn/reposman.rb (working copy) @@ -65,9 +65,10 @@ require 'rdoc/usage' require 'find' require 'etc' +require 'uri' Version = "1.3" -SUPPORTED_SCM = %w( Subversion Darcs Mercurial Bazaar Git Filesystem ) +SUPPORTED_SCM = %w( Subversion Subversion_mirror Darcs Mercurial Bazaar Git Filesystem ) opts = GetoptLong.new( ['--svn-dir', '-s', GetoptLong::REQUIRED_ARGUMENT], @@ -97,6 +98,7 @@ $test = false $force = false $scm = 'Subversion' +$identifier = false def log(text, options={}) level = options[:level] || 0 @@ -114,7 +116,47 @@ def self.create(path) system_or_raise "svnadmin create #{path}" end + + def self.disregard_registration? + false + end end + + module Subversion_mirror + def self.create(path) + + # Create the repository + system_or_raise "svnadmin create #{path}" + + # enable pre-revprop-change + if mswin? + revprop_file = File.join(path,"hooks","pre-revprop-change.bat") + else + revprop_file = File.join(path,"hooks","pre-revprop-change") + end + File.new(revprop_file, "w+") + File.chmod(0755, revprop_file) + + # Switch the slashes if on Windows. + if mswin? + normalpath=path.gsub("\\","/") + else + normalpath=path + end + + # initialize the sync + file_url = "file://#{normalpath}" + system_or_raise "svnsync init #{file_url} #{$svn_url}#{$identifier}" + end + + def self.disregard_registration? + true + end + + def self.validate_opts + log("Subversion_mirror requires --url option", :exit => true) if not $svn_url + end + end module Git def self.create(path) @@ -124,6 +166,10 @@ system_or_raise "git update-server-info" end end + + def self.disregard_registration? + false + end end end @@ -171,9 +217,14 @@ end unless File.directory?($repos_base) - log("directory '#{$repos_base}' doesn't exists", :exit => true) + log("directory '#{$repos_base}' doesn't exist", :exit => true) end +# Perform SCM-specific option validation +if (not scm_module.nil? and scm_module.respond_to?("validate_opts")) + scm_module.validate_opts +end + begin require 'active_resource' rescue LoadError @@ -203,7 +254,7 @@ log("retrieved #{projects.size} projects", :level => 1) def set_owner_and_rights(project, repos_path, &block) - if RUBY_PLATFORM =~ /mswin/ + if mswin? yield if block_given? else uid, gid = Etc.getpwnam($svn_owner).uid, ($use_groupid ? Etc.getgrnam(project.identifier).gid : Etc.getgrnam($svn_group).gid) @@ -240,9 +291,16 @@ log("\tinvalid identifier for project #{project.name} : #{project.identifier}"); next; end + + if project.respond_to?(:repository) and not project.repository.nil? + url_pieces = URI.split(project.repository.url) + path_pieces = File.split(url_pieces[5]) + $identifier = path_pieces[1] + else + $identifier = project.identifier + end + repos_path = File.join($repos_base, $identifier).gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR) - repos_path = File.join($repos_base, project.identifier).gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR) - if File.directory?(repos_path) # we must verify that repository has the good owner and the good @@ -266,9 +324,15 @@ log("\tmode change on #{repos_path}"); else + # if there's an SCM module defined, check to see if it disregards + # registration of a project in Redmine. (if there's no scm module defined, + # value should be false) + disregard_registration = ((not scm_module.nil?) and scm_module.disregard_registration?) + # if repository is already declared in redmine, we don't create - # unless user use -f with reposman - if $force == false and project.respond_to?(:repository) + # unless user use -f with reposman, or the SCM module specifies that + # the Redmine registration is disregarded. + if (($force == false) and ((not disregard_registration) and project.respond_to?(:repository))) log("\trepository for project #{project.identifier} already exists in Redmine", :level => 1) next end @@ -277,7 +341,7 @@ if $test log("\tcreate repository #{repos_path}") - log("\trepository #{repos_path} registered in Redmine with url #{$svn_url}#{project.identifier}") if $svn_url; + log("\trepository #{repos_path} registered in Redmine with url #{$svn_url}#{project.identifier}") if $svn_url and not disregard_registration; next end @@ -294,7 +358,7 @@ next end - if $svn_url + if $svn_url and not disregard_registration begin project.post(:repository, :vendor => $scm, :repository => {:url => "#{$svn_url}#{project.identifier}"}, :key => $api_key) log("\trepository #{repos_path} registered in Redmine with url #{$svn_url}#{project.identifier}"); @@ -305,6 +369,5 @@ log("\trepository #{repos_path} created"); end - end \ No newline at end of file