summaryrefslogtreecommitdiffstats
path: root/lib/redmine/scm
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2014-10-22 17:37:16 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2014-10-22 17:37:16 +0000
commit2d1866d966d94c688f9cb87c5bf3f096dffac844 (patch)
tree7a733c1cc51448ab69b3f892285305dbfb0ae15e /lib/redmine/scm
parenta6ec78a4dc658e3517ed682792016b6530458696 (diff)
downloadredmine-2d1866d966d94c688f9cb87c5bf3f096dffac844.tar.gz
redmine-2d1866d966d94c688f9cb87c5bf3f096dffac844.zip
Merged rails-4.1 branch (#14534).
git-svn-id: http://svn.redmine.org/redmine/trunk@13482 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/redmine/scm')
-rw-r--r--lib/redmine/scm/adapters/abstract_adapter.rb27
-rw-r--r--lib/redmine/scm/adapters/bazaar_adapter.rb7
-rw-r--r--lib/redmine/scm/adapters/cvs_adapter.rb8
-rw-r--r--lib/redmine/scm/adapters/darcs_adapter.rb5
-rw-r--r--lib/redmine/scm/adapters/git_adapter.rb10
-rw-r--r--lib/redmine/scm/adapters/mercurial_adapter.rb22
-rw-r--r--lib/redmine/scm/adapters/subversion_adapter.rb25
7 files changed, 25 insertions, 79 deletions
diff --git a/lib/redmine/scm/adapters/abstract_adapter.rb b/lib/redmine/scm/adapters/abstract_adapter.rb
index ec168bf84..0e60de610 100644
--- a/lib/redmine/scm/adapters/abstract_adapter.rb
+++ b/lib/redmine/scm/adapters/abstract_adapter.rb
@@ -18,17 +18,13 @@
require 'cgi'
require 'redmine/scm/adapters'
-if RUBY_VERSION < '1.9'
- require 'iconv'
-end
-
module Redmine
module Scm
module Adapters
class AbstractAdapter #:nodoc:
# raised if scm command exited with error, e.g. unknown revision.
- class ScmCommandAborted < CommandFailed; end
+ class ScmCommandAborted < ::Redmine::Scm::Adapters::CommandFailed; end
class << self
def client_command
@@ -288,21 +284,12 @@ module Redmine
def scm_iconv(to, from, str)
return nil if str.nil?
return str if to == from
- if str.respond_to?(:force_encoding)
- str.force_encoding(from)
- begin
- str.encode(to)
- rescue Exception => err
- logger.error("failed to convert from #{from} to #{to}. #{err}")
- nil
- end
- else
- begin
- Iconv.conv(to, from, str)
- rescue Iconv::Failure => err
- logger.error("failed to convert from #{from} to #{to}. #{err}")
- nil
- end
+ str.force_encoding(from)
+ begin
+ str.encode(to)
+ rescue Exception => err
+ logger.error("failed to convert from #{from} to #{to}. #{err}")
+ nil
end
end
diff --git a/lib/redmine/scm/adapters/bazaar_adapter.rb b/lib/redmine/scm/adapters/bazaar_adapter.rb
index 93ac13e02..c5e9d124d 100644
--- a/lib/redmine/scm/adapters/bazaar_adapter.rb
+++ b/lib/redmine/scm/adapters/bazaar_adapter.rb
@@ -43,10 +43,7 @@ module Redmine
end
def scm_command_version
- scm_version = scm_version_from_command_line.dup
- if scm_version.respond_to?(:force_encoding)
- scm_version.force_encoding('ASCII-8BIT')
- end
+ scm_version = scm_version_from_command_line.dup.force_encoding('ASCII-8BIT')
if m = scm_version.match(%r{\A(.*?)((\d+\.)+\d+)})
m[2].scan(%r{\d+}).collect(&:to_i)
end
@@ -100,7 +97,7 @@ module Redmine
prefix_utf8 = "#{url}/#{path}".gsub('\\', '/')
logger.debug "PREFIX: #{prefix_utf8}"
prefix = scm_iconv(@path_encoding, 'UTF-8', prefix_utf8)
- prefix.force_encoding('ASCII-8BIT') if prefix.respond_to?(:force_encoding)
+ prefix.force_encoding('ASCII-8BIT')
re = %r{^V\s+(#{Regexp.escape(prefix)})?(\/?)([^\/]+)(\/?)\s+(\S+)\r?$}
io.each_line do |line|
next unless line =~ re
diff --git a/lib/redmine/scm/adapters/cvs_adapter.rb b/lib/redmine/scm/adapters/cvs_adapter.rb
index d1096e725..ec7ce7bcf 100644
--- a/lib/redmine/scm/adapters/cvs_adapter.rb
+++ b/lib/redmine/scm/adapters/cvs_adapter.rb
@@ -43,10 +43,7 @@ module Redmine
end
def scm_command_version
- scm_version = scm_version_from_command_line.dup
- if scm_version.respond_to?(:force_encoding)
- scm_version.force_encoding('ASCII-8BIT')
- end
+ scm_version = scm_version_from_command_line.dup.force_encoding('ASCII-8BIT')
if m = scm_version.match(%r{\A(.*?)((\d+\.)+\d+)}m)
m[2].scan(%r{\d+}).collect(&:to_i)
end
@@ -94,7 +91,7 @@ module Redmine
def entries(path=nil, identifier=nil, options={})
logger.debug "<cvs> entries '#{path}' with identifier '#{identifier}'"
path_locale = scm_iconv(@path_encoding, 'UTF-8', path)
- path_locale.force_encoding("ASCII-8BIT") if path_locale.respond_to?(:force_encoding)
+ path_locale.force_encoding("ASCII-8BIT")
entries = Entries.new
cmd_args = %w|-q rls -e|
cmd_args << "-D" << time_to_cvstime_rlog(identifier) if identifier
@@ -171,6 +168,7 @@ module Redmine
file_state = nil
branch_map = nil
io.each_line() do |line|
+ line = line.strip
if state != "revision" && /^#{ENDLOG}/ =~ line
commit_log = String.new
revision = nil
diff --git a/lib/redmine/scm/adapters/darcs_adapter.rb b/lib/redmine/scm/adapters/darcs_adapter.rb
index 3e4d55265..e2807352d 100644
--- a/lib/redmine/scm/adapters/darcs_adapter.rb
+++ b/lib/redmine/scm/adapters/darcs_adapter.rb
@@ -43,10 +43,7 @@ module Redmine
end
def darcs_binary_version
- darcsversion = darcs_binary_version_from_command_line.dup
- if darcsversion.respond_to?(:force_encoding)
- darcsversion.force_encoding('ASCII-8BIT')
- end
+ darcsversion = darcs_binary_version_from_command_line.dup.force_encoding('ASCII-8BIT')
if m = darcsversion.match(%r{\A(.*?)((\d+\.)+\d+)})
m[2].scan(%r{\d+}).collect(&:to_i)
end
diff --git a/lib/redmine/scm/adapters/git_adapter.rb b/lib/redmine/scm/adapters/git_adapter.rb
index 284a3f401..7a6a590b9 100644
--- a/lib/redmine/scm/adapters/git_adapter.rb
+++ b/lib/redmine/scm/adapters/git_adapter.rb
@@ -47,10 +47,7 @@ module Redmine
end
def scm_command_version
- scm_version = scm_version_from_command_line.dup
- if scm_version.respond_to?(:force_encoding)
- scm_version.force_encoding('ASCII-8BIT')
- end
+ scm_version = scm_version_from_command_line.dup.force_encoding('ASCII-8BIT')
if m = scm_version.match(%r{\A(.*?)((\d+\.)+\d+)})
m[2].scan(%r{\d+}).collect(&:to_i)
end
@@ -145,10 +142,7 @@ module Redmine
type = $1
sha = $2
size = $3
- name = $4
- if name.respond_to?(:force_encoding)
- name.force_encoding(@path_encoding)
- end
+ name = $4.force_encoding(@path_encoding)
full_path = p.empty? ? name : "#{p}/#{name}"
n = scm_iconv('UTF-8', @path_encoding, name)
full_p = scm_iconv('UTF-8', @path_encoding, full_path)
diff --git a/lib/redmine/scm/adapters/mercurial_adapter.rb b/lib/redmine/scm/adapters/mercurial_adapter.rb
index 881fdc89c..c6aa388a7 100644
--- a/lib/redmine/scm/adapters/mercurial_adapter.rb
+++ b/lib/redmine/scm/adapters/mercurial_adapter.rb
@@ -54,10 +54,7 @@ module Redmine
# The hg version is expressed either as a
# release number (eg 0.9.5 or 1.0) or as a revision
# id composed of 12 hexa characters.
- theversion = hgversion_from_command_line.dup
- if theversion.respond_to?(:force_encoding)
- theversion.force_encoding('ASCII-8BIT')
- end
+ theversion = hgversion_from_command_line.dup.force_encoding('ASCII-8BIT')
if m = theversion.match(%r{\A(.*?)((\d+\.)+\d+)})
m[2].scan(%r{\d+}).collect(&:to_i)
end
@@ -130,10 +127,7 @@ module Redmine
def summary
return @summary if @summary
hg 'rhsummary' do |io|
- output = io.read
- if output.respond_to?(:force_encoding)
- output.force_encoding('UTF-8')
- end
+ output = io.read.force_encoding('UTF-8')
begin
@summary = parse_xml(output)['rhsummary']
rescue
@@ -146,10 +140,7 @@ module Redmine
p1 = scm_iconv(@path_encoding, 'UTF-8', path)
manifest = hg('rhmanifest', '-r', CGI.escape(hgrev(identifier)),
CGI.escape(without_leading_slash(p1.to_s))) do |io|
- output = io.read
- if output.respond_to?(:force_encoding)
- output.force_encoding('UTF-8')
- end
+ output = io.read.force_encoding('UTF-8')
begin
parse_xml(output)['rhmanifest']['repository']['manifest']
rescue
@@ -193,10 +184,7 @@ module Redmine
hg_args << '--limit' << options[:limit] if options[:limit]
hg_args << hgtarget(path) unless path.blank?
log = hg(*hg_args) do |io|
- output = io.read
- if output.respond_to?(:force_encoding)
- output.force_encoding('UTF-8')
- end
+ output = io.read.force_encoding('UTF-8')
begin
# Mercurial < 1.5 does not support footer template for '</log>'
parse_xml("#{output}</log>")['log']
@@ -278,7 +266,7 @@ module Redmine
blame = Annotate.new
hg 'rhannotate', '-ncu', '-r', CGI.escape(hgrev(identifier)), hgtarget(p) do |io|
io.each_line do |line|
- line.force_encoding('ASCII-8BIT') if line.respond_to?(:force_encoding)
+ line.force_encoding('ASCII-8BIT')
next unless line =~ %r{^([^:]+)\s(\d+)\s([0-9a-f]+):\s(.*)$}
r = Revision.new(:author => $1.strip, :revision => $2, :scmid => $3,
:identifier => $3)
diff --git a/lib/redmine/scm/adapters/subversion_adapter.rb b/lib/redmine/scm/adapters/subversion_adapter.rb
index fcc9be90d..30ebc0c18 100644
--- a/lib/redmine/scm/adapters/subversion_adapter.rb
+++ b/lib/redmine/scm/adapters/subversion_adapter.rb
@@ -46,10 +46,7 @@ module Redmine
end
def svn_binary_version
- scm_version = scm_version_from_command_line.dup
- if scm_version.respond_to?(:force_encoding)
- scm_version.force_encoding('ASCII-8BIT')
- end
+ scm_version = scm_version_from_command_line.dup.force_encoding('ASCII-8BIT')
if m = scm_version.match(%r{\A(.*?)((\d+\.)+\d+)})
m[2].scan(%r{\d+}).collect(&:to_i)
end
@@ -66,10 +63,7 @@ module Redmine
cmd << credentials_string
info = nil
shellout(cmd) do |io|
- output = io.read
- if output.respond_to?(:force_encoding)
- output.force_encoding('UTF-8')
- end
+ output = io.read.force_encoding('UTF-8')
begin
doc = parse_xml(output)
# root_url = doc.elements["info/entry/repository/root"].text
@@ -98,10 +92,7 @@ module Redmine
cmd = "#{self.class.sq_bin} list --xml #{target(path)}@#{identifier}"
cmd << credentials_string
shellout(cmd) do |io|
- output = io.read
- if output.respond_to?(:force_encoding)
- output.force_encoding('UTF-8')
- end
+ output = io.read.force_encoding('UTF-8')
begin
doc = parse_xml(output)
each_xml_element(doc['lists']['list'], 'entry') do |entry|
@@ -141,10 +132,7 @@ module Redmine
cmd << credentials_string
properties = {}
shellout(cmd) do |io|
- output = io.read
- if output.respond_to?(:force_encoding)
- output.force_encoding('UTF-8')
- end
+ output = io.read.force_encoding('UTF-8')
begin
doc = parse_xml(output)
each_xml_element(doc['properties']['target'], 'property') do |property|
@@ -168,10 +156,7 @@ module Redmine
cmd << " --limit #{options[:limit].to_i}" if options[:limit]
cmd << ' ' + target(path)
shellout(cmd) do |io|
- output = io.read
- if output.respond_to?(:force_encoding)
- output.force_encoding('UTF-8')
- end
+ output = io.read.force_encoding('UTF-8')
begin
doc = parse_xml(output)
each_xml_element(doc['log'], 'logentry') do |logentry|