comparison lib/redmine/scm/adapters/abstract_adapter.rb @ 909:cbb26bc654de redmine-1.3

Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author Chris Cannam
date Fri, 24 Feb 2012 19:09:32 +0000
parents 0c939c159af4
children 5e80956cc792 433d4f72a19b
comparison
equal deleted inserted replaced
908:c6c2cbd0afee 909:cbb26bc654de
22 module Adapters 22 module Adapters
23 class CommandFailed < StandardError #:nodoc: 23 class CommandFailed < StandardError #:nodoc:
24 end 24 end
25 25
26 class AbstractAdapter #:nodoc: 26 class AbstractAdapter #:nodoc:
27
28 # raised if scm command exited with error, e.g. unknown revision.
29 class ScmCommandAborted < CommandFailed; end
30
27 class << self 31 class << self
28 def client_command 32 def client_command
29 "" 33 ""
34 end
35
36 def shell_quote_command
37 if Redmine::Platform.mswin? && RUBY_PLATFORM == 'java'
38 client_command
39 else
40 shell_quote(client_command)
41 end
30 end 42 end
31 43
32 # Returns the version of the scm client 44 # Returns the version of the scm client
33 # Eg: [1, 5, 0] or [] if unknown 45 # Eg: [1, 5, 0] or [] if unknown
34 def client_version 46 def client_version
178 def retrieve_root_url 190 def retrieve_root_url
179 info = self.info 191 info = self.info
180 info ? info.root_url : nil 192 info ? info.root_url : nil
181 end 193 end
182 194
183 def target(path) 195 def target(path, sq=true)
184 path ||= '' 196 path ||= ''
185 base = path.match(/^\//) ? root_url : url 197 base = path.match(/^\//) ? root_url : url
186 shell_quote("#{base}/#{path}".gsub(/[?<>\*]/, '')) 198 str = "#{base}/#{path}".gsub(/[?<>\*]/, '')
199 if sq
200 str = shell_quote(str)
201 end
202 str
187 end 203 end
188 204
189 def logger 205 def logger
190 self.class.logger 206 self.class.logger
191 end 207 end
193 def shellout(cmd, &block) 209 def shellout(cmd, &block)
194 self.class.shellout(cmd, &block) 210 self.class.shellout(cmd, &block)
195 end 211 end
196 212
197 def self.logger 213 def self.logger
198 RAILS_DEFAULT_LOGGER 214 Rails.logger
199 end 215 end
200 216
201 def self.shellout(cmd, &block) 217 def self.shellout(cmd, &block)
202 if logger && logger.debug? 218 if logger && logger.debug?
203 logger.debug "Shelling out: #{strip_credential(cmd)}" 219 logger.debug "Shelling out: #{strip_credential(cmd)}"
204 end 220 end
205 if Rails.env == 'development' 221 if Rails.env == 'development'
206 # Capture stderr when running in dev environment 222 # Capture stderr when running in dev environment
207 cmd = "#{cmd} 2>>#{RAILS_ROOT}/log/scm.stderr.log" 223 cmd = "#{cmd} 2>>#{Rails.root}/log/scm.stderr.log"
208 end 224 end
209 begin 225 begin
210 if RUBY_VERSION < '1.9' 226 if RUBY_VERSION < '1.9'
211 mode = "r+" 227 mode = "r+"
212 else 228 else
214 end 230 end
215 IO.popen(cmd, mode) do |io| 231 IO.popen(cmd, mode) do |io|
216 io.close_write 232 io.close_write
217 block.call(io) if block_given? 233 block.call(io) if block_given?
218 end 234 end
219 rescue Errno::ENOENT => e 235 ## If scm command does not exist,
236 ## Linux JRuby 1.6.2 (ruby-1.8.7-p330) raises java.io.IOException
237 ## in production environment.
238 # rescue Errno::ENOENT => e
239 rescue Exception => e
220 msg = strip_credential(e.message) 240 msg = strip_credential(e.message)
221 # The command failed, log it and re-raise 241 # The command failed, log it and re-raise
222 logmsg = "SCM command failed, " 242 logmsg = "SCM command failed, "
223 logmsg += "make sure that your SCM command (e.g. svn) is " 243 logmsg += "make sure that your SCM command (e.g. svn) is "
224 logmsg += "in PATH (#{ENV['PATH']})\n" 244 logmsg += "in PATH (#{ENV['PATH']})\n"
311 end 331 end
312 end 332 end
313 333
314 class Revision 334 class Revision
315 attr_accessor :scmid, :name, :author, :time, :message, 335 attr_accessor :scmid, :name, :author, :time, :message,
316 :paths, :revision, :branch, :identifier 336 :paths, :revision, :branch, :identifier,
337 :parents
317 338
318 def initialize(attributes={}) 339 def initialize(attributes={})
319 self.identifier = attributes[:identifier] 340 self.identifier = attributes[:identifier]
320 self.scmid = attributes[:scmid] 341 self.scmid = attributes[:scmid]
321 self.name = attributes[:name] || self.identifier 342 self.name = attributes[:name] || self.identifier
323 self.time = attributes[:time] 344 self.time = attributes[:time]
324 self.message = attributes[:message] || "" 345 self.message = attributes[:message] || ""
325 self.paths = attributes[:paths] 346 self.paths = attributes[:paths]
326 self.revision = attributes[:revision] 347 self.revision = attributes[:revision]
327 self.branch = attributes[:branch] 348 self.branch = attributes[:branch]
349 self.parents = attributes[:parents]
328 end 350 end
329 351
330 # Returns the readable identifier. 352 # Returns the readable identifier.
331 def format_identifier 353 def format_identifier
332 self.identifier.to_s 354 self.identifier.to_s
352 374
353 def empty? 375 def empty?
354 lines.empty? 376 lines.empty?
355 end 377 end
356 end 378 end
379
380 class Branch < String
381 attr_accessor :revision, :scmid
382 end
357 end 383 end
358 end 384 end
359 end 385 end