Mercurial > hg > soundsoftware-site
diff lib/redmine/scm/adapters/.svn/text-base/darcs_adapter.rb.svn-base @ 246:eeebe205a056 cannam
* Merge from default branch, bringing us up to SVN trunk rev 4993
author | Chris Cannam |
---|---|
date | Thu, 03 Mar 2011 12:02:03 +0000 |
parents | 051f544170fe |
children | cbce1fd3b1b7 |
line wrap: on
line diff
--- a/lib/redmine/scm/adapters/.svn/text-base/darcs_adapter.rb.svn-base Thu Jan 20 09:59:02 2011 +0000 +++ b/lib/redmine/scm/adapters/.svn/text-base/darcs_adapter.rb.svn-base Thu Mar 03 12:02:03 2011 +0000 @@ -20,31 +20,45 @@ module Redmine module Scm - module Adapters - class DarcsAdapter < AbstractAdapter + module Adapters + class DarcsAdapter < AbstractAdapter # Darcs executable name - DARCS_BIN = "darcs" - + DARCS_BIN = Redmine::Configuration['scm_darcs_command'] || "darcs" + class << self + def client_command + @@bin ||= DARCS_BIN + end + + def sq_bin + @@sq_bin ||= shell_quote(DARCS_BIN) + end + def client_version @@client_version ||= (darcs_binary_version || []) end - + + def client_available + !client_version.empty? + end + def darcs_binary_version - cmd = "#{DARCS_BIN} --version" - version = nil - shellout(cmd) do |io| - # Read darcs version in first returned line - if m = io.gets.match(%r{((\d+\.)+\d+)}) - version = m[0].scan(%r{\d+}).collect(&:to_i) - end + darcsversion = darcs_binary_version_from_command_line.dup + if darcsversion.respond_to?(:force_encoding) + darcsversion.force_encoding('ASCII-8BIT') end - return nil if $? && $?.exitstatus != 0 - version + if m = darcsversion.match(%r{\A(.*?)((\d+\.)+\d+)}) + m[2].scan(%r{\d+}).collect(&:to_i) + end + end + + def darcs_binary_version_from_command_line + shellout("#{sq_bin} --version") { |io| io.read }.to_s 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 @root_url = url end @@ -59,14 +73,16 @@ rev = revisions(nil,nil,nil,{:limit => 1}) rev ? Info.new({:root_url => @url, :lastrev => rev.last}) : 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_prefix = (path.blank? ? '' : "#{path}/") - path = '.' if path.blank? - entries = Entries.new - cmd = "#{DARCS_BIN} annotate --repodir #{shell_quote @url} --xml-output" + if path.blank? + path = ( self.class.client_version_above?([2, 2, 0]) ? @url : '.' ) + end + entries = Entries.new + cmd = "#{self.class.sq_bin} annotate --repodir #{shell_quote @url} --xml-output" cmd << " --match #{shell_quote("hash #{identifier}")}" if identifier cmd << " #{shell_quote path}" shellout(cmd) do |io| @@ -86,11 +102,11 @@ return nil if $? && $?.exitstatus != 0 entries.compact.sort_by_name end - + def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={}) path = '.' if path.blank? revisions = Revisions.new - cmd = "#{DARCS_BIN} changes --repodir #{shell_quote @url} --xml-output" + cmd = "#{self.class.sq_bin} changes --repodir #{shell_quote @url} --xml-output" cmd << " --from-match #{shell_quote("hash #{identifier_from}")}" if identifier_from cmd << " --last #{options[:limit].to_i}" if options[:limit] shellout(cmd) do |io| @@ -113,10 +129,10 @@ return nil if $? && $?.exitstatus != 0 revisions end - + def diff(path, identifier_from, identifier_to=nil) path = '*' if path.blank? - cmd = "#{DARCS_BIN} diff --repodir #{shell_quote @url}" + cmd = "#{self.class.sq_bin} diff --repodir #{shell_quote @url}" if identifier_to.nil? cmd << " --match #{shell_quote("hash #{identifier_from}")}" else @@ -133,9 +149,9 @@ return nil if $? && $?.exitstatus != 0 diff end - + def cat(path, identifier=nil) - cmd = "#{DARCS_BIN} show content --repodir #{shell_quote @url}" + cmd = "#{self.class.sq_bin} show content --repodir #{shell_quote @url}" cmd << " --match #{shell_quote("hash #{identifier}")}" if identifier cmd << " #{shell_quote path}" cat = nil @@ -148,7 +164,7 @@ end private - + # Returns an Entry from the given XML element # or nil if the entry was deleted def entry_from_xml(element, path_prefix) @@ -156,7 +172,7 @@ if modified_element.elements['modified_how'].text.match(/removed/) return nil end - + Entry.new({:name => element.attributes['name'], :path => path_prefix + element.attributes['name'], :kind => element.name == 'file' ? 'file' : 'dir', @@ -165,12 +181,41 @@ :identifier => nil, :scmid => modified_element.elements['patch'].attributes['hash'] }) - }) + }) end - + + def get_paths_for_patch(hash) + paths = get_paths_for_patch_raw(hash) + if self.class.client_version_above?([2, 4]) + orig_paths = paths + paths = [] + add_paths = [] + add_paths_name = [] + mod_paths = [] + other_paths = [] + orig_paths.each do |path| + if path[:action] == 'A' + add_paths << path + add_paths_name << path[:path] + elsif path[:action] == 'M' + mod_paths << path + else + other_paths << path + end + end + add_paths_name.each do |add_path| + mod_paths.delete_if { |m| m[:path] == add_path } + end + paths.concat add_paths + paths.concat mod_paths + paths.concat other_paths + end + paths + end + # Retrieve changed paths for a single patch - def get_paths_for_patch(hash) - cmd = "#{DARCS_BIN} annotate --repodir #{shell_quote @url} --summary --xml-output" + def get_paths_for_patch_raw(hash) + cmd = "#{self.class.sq_bin} annotate --repodir #{shell_quote @url} --summary --xml-output" cmd << " --match #{shell_quote("hash #{hash}")} " paths = [] shellout(cmd) do |io|