Project

General

Profile

Patch #5669 » reposman.diff

Patch file against 0.9-stable branch at r3768 - Bryce Nordgren, 2010-06-10 23:46

View differences:

extra/svn/reposman.rb (working copy)
65 65
require 'rdoc/usage'
66 66
require 'find'
67 67
require 'etc'
68
require 'uri'
68 69

  
69 70
Version = "1.3"
70
SUPPORTED_SCM = %w( Subversion Darcs Mercurial Bazaar Git Filesystem )
71
SUPPORTED_SCM = %w( Subversion Subversion_mirror Darcs Mercurial Bazaar Git Filesystem )
71 72

  
72 73
opts = GetoptLong.new(
73 74
                      ['--svn-dir',      '-s', GetoptLong::REQUIRED_ARGUMENT],
......
97 98
$test         = false
98 99
$force        = false
99 100
$scm          = 'Subversion'
101
$identifier   = false
100 102

  
101 103
def log(text, options={})
102 104
  level = options[:level] || 0
......
114 116
    def self.create(path)
115 117
      system_or_raise "svnadmin create #{path}"
116 118
    end
119
    
120
    def self.disregard_registration?
121
      false
122
    end
117 123
  end
124
  
125
  module Subversion_mirror
126
    def self.create(path)
127
        
128
      # Create the repository
129
      system_or_raise "svnadmin create #{path}"
130
      
131
      # enable pre-revprop-change
132
      if mswin? 
133
        revprop_file = File.join(path,"hooks","pre-revprop-change.bat")
134
      else
135
        revprop_file = File.join(path,"hooks","pre-revprop-change")        
136
      end
137
      File.new(revprop_file, "w+")
138
      File.chmod(0755, revprop_file)
139
      
140
      # Switch the slashes if on Windows.        
141
      if mswin?
142
        normalpath=path.gsub("\\","/")
143
      else
144
        normalpath=path
145
      end
146
      
147
      # initialize the sync
148
      file_url = "file://#{normalpath}"
149
      system_or_raise "svnsync init #{file_url} #{$svn_url}#{$identifier}"       
150
    end
151
    
152
    def self.disregard_registration?
153
      true
154
    end
155
    
156
    def self.validate_opts
157
      log("Subversion_mirror requires --url option", :exit => true) if not $svn_url
158
    end
159
  end
118 160

  
119 161
  module Git
120 162
    def self.create(path)
......
124 166
        system_or_raise "git update-server-info"
125 167
      end
126 168
    end
169
    
170
    def self.disregard_registration?
171
      false
172
    end
127 173
  end
128 174

  
129 175
end
......
171 217
end
172 218

  
173 219
unless File.directory?($repos_base)
174
  log("directory '#{$repos_base}' doesn't exists", :exit => true)
220
  log("directory '#{$repos_base}' doesn't exist", :exit => true)
175 221
end
176 222

  
223
# Perform SCM-specific option validation
224
if (not scm_module.nil? and scm_module.respond_to?("validate_opts"))
225
  scm_module.validate_opts
226
end
227

  
177 228
begin
178 229
  require 'active_resource'
179 230
rescue LoadError
......
203 254
log("retrieved #{projects.size} projects", :level => 1)
204 255

  
205 256
def set_owner_and_rights(project, repos_path, &block)
206
  if RUBY_PLATFORM =~ /mswin/
257
  if mswin?
207 258
    yield if block_given?
208 259
  else
209 260
    uid, gid = Etc.getpwnam($svn_owner).uid, ($use_groupid ? Etc.getgrnam(project.identifier).gid : Etc.getgrnam($svn_group).gid)
......
240 291
    log("\tinvalid identifier for project #{project.name} : #{project.identifier}");
241 292
    next;
242 293
  end
294
  
295
  if project.respond_to?(:repository) and not project.repository.nil?
296
    url_pieces = URI.split(project.repository.url)
297
    path_pieces = File.split(url_pieces[5])
298
    $identifier = path_pieces[1]
299
  else
300
    $identifier = project.identifier
301
  end
302
  repos_path = File.join($repos_base, $identifier).gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR)
243 303

  
244
  repos_path = File.join($repos_base, project.identifier).gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR)
245

  
246 304
  if File.directory?(repos_path)
247 305

  
248 306
    # we must verify that repository has the good owner and the good
......
266 324
    log("\tmode change on #{repos_path}");
267 325

  
268 326
  else
327
    # if there's an SCM module defined, check to see if it disregards 
328
    # registration of a project in Redmine. (if there's no scm module defined,
329
    # value should be false)
330
    disregard_registration = ((not scm_module.nil?) and scm_module.disregard_registration?)
331

  
269 332
    # if repository is already declared in redmine, we don't create
270
    # unless user use -f with reposman
271
    if $force == false and project.respond_to?(:repository)
333
    # unless user use -f with reposman, or the SCM module specifies that 
334
    # the Redmine registration is disregarded.
335
    if (($force == false) and ((not disregard_registration) and project.respond_to?(:repository)))
272 336
      log("\trepository for project #{project.identifier} already exists in Redmine", :level => 1)
273 337
      next
274 338
    end
......
277 341

  
278 342
    if $test
279 343
      log("\tcreate repository #{repos_path}")
280
      log("\trepository #{repos_path} registered in Redmine with url #{$svn_url}#{project.identifier}") if $svn_url;
344
      log("\trepository #{repos_path} registered in Redmine with url #{$svn_url}#{project.identifier}") if $svn_url and not disregard_registration;
281 345
      next
282 346
    end
283 347

  
......
294 358
      next
295 359
    end
296 360

  
297
    if $svn_url
361
    if $svn_url and not disregard_registration
298 362
      begin
299 363
        project.post(:repository, :vendor => $scm, :repository => {:url => "#{$svn_url}#{project.identifier}"}, :key => $api_key)
300 364
        log("\trepository #{repos_path} registered in Redmine with url #{$svn_url}#{project.identifier}");
......
305 369

  
306 370
    log("\trepository #{repos_path} created");
307 371
  end
308

  
309 372
end
310 373
  
(1-1/2)