diff lib/redmine/scm/adapters/subversion_adapter.rb @ 245:051f544170fe

* Update to SVN trunk revision 4993
author Chris Cannam
date Thu, 03 Mar 2011 11:42:28 +0000
parents 0579821a129a
children cbce1fd3b1b7
line wrap: on
line diff
--- a/lib/redmine/scm/adapters/subversion_adapter.rb	Thu Mar 03 11:40:10 2011 +0000
+++ b/lib/redmine/scm/adapters/subversion_adapter.rb	Thu Mar 03 11:42:28 2011 +0000
@@ -20,38 +20,54 @@
 
 module Redmine
   module Scm
-    module Adapters    
+    module Adapters
       class SubversionAdapter < AbstractAdapter
-      
+
         # SVN executable name
         SVN_BIN = Redmine::Configuration['scm_subversion_command'] || "svn"
-        
+
         class << self
+          def client_command
+            @@bin    ||= SVN_BIN
+          end
+
+          def sq_bin
+            @@sq_bin ||= shell_quote(SVN_BIN)
+          end
+
           def client_version
             @@client_version ||= (svn_binary_version || [])
           end
-          
+
+          def client_available
+            !client_version.empty?
+          end
+
           def svn_binary_version
-            cmd = "#{SVN_BIN} --version"
-            version = nil
-            shellout(cmd) do |io|
-              # Read svn version in first returned line
-              if m = io.read.to_s.match(%r{\A(.*?)((\d+\.)+\d+)})
-                version = m[2].scan(%r{\d+}).collect(&:to_i)
-              end
+            scm_version = scm_version_from_command_line.dup
+            if scm_version.respond_to?(:force_encoding)
+              scm_version.force_encoding('ASCII-8BIT')
             end
-            return nil if $? && $?.exitstatus != 0
-            version
+            if m = scm_version.match(%r{\A(.*?)((\d+\.)+\d+)})
+              m[2].scan(%r{\d+}).collect(&:to_i)
+            end
+          end
+
+          def scm_version_from_command_line
+            shellout("#{sq_bin} --version") { |io| io.read }.to_s
           end
         end
-        
+
         # Get info about the svn repository
         def info
-          cmd = "#{SVN_BIN} info --xml #{target}"
+          cmd = "#{self.class.sq_bin} info --xml #{target}"
           cmd << credentials_string
           info = nil
           shellout(cmd) do |io|
             output = io.read
+            if output.respond_to?(:force_encoding)
+              output.force_encoding('UTF-8')
+            end
             begin
               doc = ActiveSupport::XmlMini.parse(output)
               #root_url = doc.elements["info/entry/repository/root"].text          
@@ -70,17 +86,20 @@
         rescue CommandFailed
           return nil
         end
-        
+
         # Returns an Entries collection
         # or nil if the given path doesn't exist in the repository
         def entries(path=nil, identifier=nil)
           path ||= ''
           identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD"
           entries = Entries.new
-          cmd = "#{SVN_BIN} list --xml #{target(path)}@#{identifier}"
+          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
             begin
               doc = ActiveSupport::XmlMini.parse(output)
               each_xml_element(doc['lists']['list'], 'entry') do |entry|
@@ -110,17 +129,20 @@
           logger.debug("Found #{entries.size} entries in the repository for #{target(path)}") if logger && logger.debug?
           entries.sort_by_name
         end
-        
+
         def properties(path, identifier=nil)
           # proplist xml output supported in svn 1.5.0 and higher
           return nil unless self.class.client_version_above?([1, 5, 0])
           
           identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD"
-          cmd = "#{SVN_BIN} proplist --verbose --xml #{target(path)}@#{identifier}"
+          cmd = "#{self.class.sq_bin} proplist --verbose --xml #{target(path)}@#{identifier}"
           cmd << credentials_string
           properties = {}
           shellout(cmd) do |io|
             output = io.read
+            if output.respond_to?(:force_encoding)
+              output.force_encoding('UTF-8')
+            end
             begin
               doc = ActiveSupport::XmlMini.parse(output)
               each_xml_element(doc['properties']['target'], 'property') do |property|
@@ -132,19 +154,22 @@
           return nil if $? && $?.exitstatus != 0
           properties
         end
-        
+
         def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={})
           path ||= ''
           identifier_from = (identifier_from && identifier_from.to_i > 0) ? identifier_from.to_i : "HEAD"
           identifier_to = (identifier_to && identifier_to.to_i > 0) ? identifier_to.to_i : 1
           revisions = Revisions.new
-          cmd = "#{SVN_BIN} log --xml -r #{identifier_from}:#{identifier_to}"
+          cmd = "#{self.class.sq_bin} log --xml -r #{identifier_from}:#{identifier_to}"
           cmd << credentials_string
           cmd << " --verbose " if  options[:with_paths]
           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
             begin
               doc = ActiveSupport::XmlMini.parse(output)
               each_xml_element(doc['log'], 'logentry') do |logentry|
@@ -171,13 +196,14 @@
           return nil if $? && $?.exitstatus != 0
           revisions
         end
-        
+
         def diff(path, identifier_from, identifier_to=nil, type="inline")
           path ||= ''
           identifier_from = (identifier_from and identifier_from.to_i > 0) ? identifier_from.to_i : ''
+
           identifier_to = (identifier_to and identifier_to.to_i > 0) ? identifier_to.to_i : (identifier_from.to_i - 1)
-          
-          cmd = "#{SVN_BIN} diff -r "
+
+          cmd = "#{self.class.sq_bin} diff -r "
           cmd << "#{identifier_to}:"
           cmd << "#{identifier_from}"
           cmd << " #{target(path)}@#{identifier_from}"
@@ -191,10 +217,10 @@
           return nil if $? && $?.exitstatus != 0
           diff
         end
-        
+
         def cat(path, identifier=nil)
           identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD"
-          cmd = "#{SVN_BIN} cat #{target(path)}@#{identifier}"
+          cmd = "#{self.class.sq_bin} cat #{target(path)}@#{identifier}"
           cmd << credentials_string
           cat = nil
           shellout(cmd) do |io|
@@ -204,10 +230,10 @@
           return nil if $? && $?.exitstatus != 0
           cat
         end
-        
+
         def annotate(path, identifier=nil)
           identifier = (identifier and identifier.to_i > 0) ? identifier.to_i : "HEAD"
-          cmd = "#{SVN_BIN} blame #{target(path)}@#{identifier}"
+          cmd = "#{self.class.sq_bin} blame #{target(path)}@#{identifier}"
           cmd << credentials_string
           blame = Annotate.new
           shellout(cmd) do |io|