Mercurial > hg > soundsoftware-site
diff lib/redmine/scm/adapters/.svn/text-base/abstract_adapter.rb.svn-base @ 245:051f544170fe
* Update to SVN trunk revision 4993
author | Chris Cannam |
---|---|
date | Thu, 03 Mar 2011 11:42:28 +0000 |
parents | 8661b858af72 |
children | cbce1fd3b1b7 |
line wrap: on
line diff
--- a/lib/redmine/scm/adapters/.svn/text-base/abstract_adapter.rb.svn-base Thu Mar 03 11:40:10 2011 +0000 +++ b/lib/redmine/scm/adapters/.svn/text-base/abstract_adapter.rb.svn-base Thu Mar 03 11:42:28 2011 +0000 @@ -19,25 +19,29 @@ module Redmine module Scm - module Adapters + module Adapters class CommandFailed < StandardError #:nodoc: end - + class AbstractAdapter #:nodoc: class << self + def client_command + "" + end + # Returns the version of the scm client # Eg: [1, 5, 0] or [] if unknown def client_version [] end - + # Returns the version string of the scm client # Eg: '1.5.0' or 'Unknown version' if unknown def client_version_string v = client_version || 'Unknown version' v.is_a?(Array) ? v.join('.') : v.to_s end - + # Returns true if the current client version is above # or equals the given one # If option is :unknown is set to true, it will return @@ -45,19 +49,32 @@ def client_version_above?(v, options={}) ((client_version <=> v) >= 0) || (client_version.empty? && options[:unknown]) end + + def client_available + true + end + + def shell_quote(str) + if Redmine::Platform.mswin? + '"' + str.gsub(/"/, '\\"') + '"' + else + "'" + str.gsub(/'/, "'\"'\"'") + "'" + end + end end - - def initialize(url, root_url=nil, login=nil, password=nil) + + def initialize(url, root_url=nil, login=nil, password=nil, + path_encoding=nil) @url = url @login = login if login && !login.empty? @password = (password || "") if @login @root_url = root_url.blank? ? retrieve_root_url : root_url end - + def adapter_name 'Abstract' end - + def supports_cat? true end @@ -65,11 +82,11 @@ def supports_annotate? respond_to?('annotate') end - + def root_url @root_url end - + def url @url end @@ -138,7 +155,7 @@ path ||= '' (path[-1,1] == "/") ? path : "#{path}/" end - + def without_leading_slash(path) path ||= '' path.gsub(%r{^/+}, '') @@ -148,13 +165,9 @@ path ||= '' (path[-1,1] == "/") ? path[0..-2] : path end - + def shell_quote(str) - if Redmine::Platform.mswin? - '"' + str.gsub(/"/, '\\"') + '"' - else - "'" + str.gsub(/'/, "'\"'\"'") + "'" - end + self.class.shell_quote(str) end private @@ -168,19 +181,19 @@ base = path.match(/^\//) ? root_url : url shell_quote("#{base}/#{path}".gsub(/[?<>\*]/, '')) end - + def logger self.class.logger end - + def shellout(cmd, &block) self.class.shellout(cmd, &block) end - + def self.logger RAILS_DEFAULT_LOGGER end - + def self.shellout(cmd, &block) logger.debug "Shelling out: #{strip_credential(cmd)}" if logger && logger.debug? if Rails.env == 'development' @@ -188,7 +201,12 @@ cmd = "#{cmd} 2>>#{RAILS_ROOT}/log/scm.stderr.log" end begin - IO.popen(cmd, "r+") do |io| + if RUBY_VERSION < '1.9' + mode = "r+" + else + mode = "r+:ASCII-8BIT" + end + IO.popen(cmd, mode) do |io| io.close_write block.call(io) if block_given? end @@ -198,8 +216,8 @@ logger.error("SCM command failed, make sure that your SCM binary (eg. svn) is in PATH (#{ENV['PATH']}): #{strip_credential(cmd)}\n with: #{msg}") raise CommandFailed.new(msg) end - end - + end + # Hides username/password in a given command def self.strip_credential(cmd) q = (Redmine::Platform.mswin? ? '"' : "'") @@ -209,8 +227,19 @@ def strip_credential(cmd) self.class.strip_credential(cmd) end + + def scm_iconv(to, from, str) + return nil if str.nil? + return str if to == from + begin + Iconv.conv(to, from, str) + rescue Iconv::Failure => err + logger.error("failed to convert from #{from} to #{to}. #{err}") + nil + end + end end - + class Entries < Array def sort_by_name sort {|x,y| @@ -219,7 +248,7 @@ else x.kind <=> y.kind end - } + } end def revisions @@ -295,29 +324,8 @@ def format_identifier identifier end + end - def save(repo) - Changeset.transaction do - changeset = Changeset.new( - :repository => repo, - :revision => identifier, - :scmid => scmid, - :committer => author, - :committed_on => time, - :comments => message) - - if changeset.save - paths.each do |file| - Change.create( - :changeset => changeset, - :action => file[:action], - :path => file[:path]) - end - end - end - end - end - class Annotate attr_reader :lines, :revisions