comparison lib/redmine/scm/adapters/abstract_adapter.rb @ 1115:433d4f72a19b redmine-2.2

Update to Redmine SVN revision 11137 on 2.2-stable branch
author Chris Cannam
date Mon, 07 Jan 2013 12:01:42 +0000
parents cbb26bc654de
children bb32da3bea34 622f24f53b42 261b3d9a4903
comparison
equal deleted inserted replaced
929:5f33065ddc4b 1115:433d4f72a19b
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
204 204
205 def logger 205 def logger
206 self.class.logger 206 self.class.logger
207 end 207 end
208 208
209 def shellout(cmd, &block) 209 def shellout(cmd, options = {}, &block)
210 self.class.shellout(cmd, &block) 210 self.class.shellout(cmd, options, &block)
211 end 211 end
212 212
213 def self.logger 213 def self.logger
214 Rails.logger 214 Rails.logger
215 end 215 end
216 216
217 def self.shellout(cmd, &block) 217 def self.shellout(cmd, options = {}, &block)
218 if logger && logger.debug? 218 if logger && logger.debug?
219 logger.debug "Shelling out: #{strip_credential(cmd)}" 219 logger.debug "Shelling out: #{strip_credential(cmd)}"
220 end 220 end
221 if Rails.env == 'development' 221 if Rails.env == 'development'
222 # Capture stderr when running in dev environment 222 # Capture stderr when running in dev environment
223 cmd = "#{cmd} 2>>#{Rails.root}/log/scm.stderr.log" 223 cmd = "#{cmd} 2>>#{shell_quote(Rails.root.join('log/scm.stderr.log').to_s)}"
224 end 224 end
225 begin 225 begin
226 if RUBY_VERSION < '1.9' 226 mode = "r+"
227 mode = "r+"
228 else
229 mode = "r+:ASCII-8BIT"
230 end
231 IO.popen(cmd, mode) do |io| 227 IO.popen(cmd, mode) do |io|
232 io.close_write 228 io.set_encoding("ASCII-8BIT") if io.respond_to?(:set_encoding)
229 io.close_write unless options[:write_stdin]
233 block.call(io) if block_given? 230 block.call(io) if block_given?
234 end 231 end
235 ## If scm command does not exist, 232 ## If scm command does not exist,
236 ## Linux JRuby 1.6.2 (ruby-1.8.7-p330) raises java.io.IOException 233 ## Linux JRuby 1.6.2 (ruby-1.8.7-p330) raises java.io.IOException
237 ## in production environment. 234 ## in production environment.
261 end 258 end
262 259
263 def scm_iconv(to, from, str) 260 def scm_iconv(to, from, str)
264 return nil if str.nil? 261 return nil if str.nil?
265 return str if to == from 262 return str if to == from
266 begin 263 if str.respond_to?(:force_encoding)
267 Iconv.conv(to, from, str) 264 str.force_encoding(from)
268 rescue Iconv::Failure => err 265 begin
269 logger.error("failed to convert from #{from} to #{to}. #{err}") 266 str.encode(to)
270 nil 267 rescue Exception => err
271 end 268 logger.error("failed to convert from #{from} to #{to}. #{err}")
269 nil
270 end
271 else
272 begin
273 Iconv.conv(to, from, str)
274 rescue Iconv::Failure => err
275 logger.error("failed to convert from #{from} to #{to}. #{err}")
276 nil
277 end
278 end
279 end
280
281 def parse_xml(xml)
282 if RUBY_PLATFORM == 'java'
283 xml = xml.sub(%r{<\?xml[^>]*\?>}, '')
284 end
285 ActiveSupport::XmlMini.parse(xml)
272 end 286 end
273 end 287 end
274 288
275 class Entries < Array 289 class Entries < Array
276 def sort_by_name 290 def sort_by_name
277 sort {|x,y| 291 dup.sort! {|x,y|
278 if x.kind == y.kind 292 if x.kind == y.kind
279 x.name.to_s <=> y.name.to_s 293 x.name.to_s <=> y.name.to_s
280 else 294 else
281 x.kind <=> y.kind 295 x.kind <=> y.kind
282 end 296 end
295 self.lastrev = attributes[:lastrev] 309 self.lastrev = attributes[:lastrev]
296 end 310 end
297 end 311 end
298 312
299 class Entry 313 class Entry
300 attr_accessor :name, :path, :kind, :size, :lastrev 314 attr_accessor :name, :path, :kind, :size, :lastrev, :changeset
315
301 def initialize(attributes={}) 316 def initialize(attributes={})
302 self.name = attributes[:name] if attributes[:name] 317 self.name = attributes[:name] if attributes[:name]
303 self.path = attributes[:path] if attributes[:path] 318 self.path = attributes[:path] if attributes[:path]
304 self.kind = attributes[:kind] if attributes[:kind] 319 self.kind = attributes[:kind] if attributes[:kind]
305 self.size = attributes[:size].to_i if attributes[:size] 320 self.size = attributes[:size].to_i if attributes[:size]
314 'dir' == self.kind 329 'dir' == self.kind
315 end 330 end
316 331
317 def is_text? 332 def is_text?
318 Redmine::MimeType.is_type?('text', name) 333 Redmine::MimeType.is_type?('text', name)
334 end
335
336 def author
337 if changeset
338 changeset.author.to_s
339 elsif lastrev
340 Redmine::CodesetUtil.replace_invalid_utf8(lastrev.author.to_s.split('<').first)
341 end
319 end 342 end
320 end 343 end
321 344
322 class Revisions < Array 345 class Revisions < Array
323 def latest 346 def latest
351 374
352 # Returns the readable identifier. 375 # Returns the readable identifier.
353 def format_identifier 376 def format_identifier
354 self.identifier.to_s 377 self.identifier.to_s
355 end 378 end
379
380 def ==(other)
381 if other.nil?
382 false
383 elsif scmid.present?
384 scmid == other.scmid
385 elsif identifier.present?
386 identifier == other.identifier
387 elsif revision.present?
388 revision == other.revision
389 end
390 end
356 end 391 end
357 392
358 class Annotate 393 class Annotate
359 attr_reader :lines, :revisions 394 attr_reader :lines, :revisions
360 395