Mercurial > hg > soundsoftware-site
comparison lib/redmine/scm/adapters/darcs_adapter.rb @ 210:0579821a129a
Update to Redmine trunk rev 4802
author | Chris Cannam |
---|---|
date | Tue, 08 Feb 2011 13:51:46 +0000 |
parents | 8661b858af72 |
children | 051f544170fe |
comparison
equal
deleted
inserted
replaced
128:07fa8a8b56a8 | 210:0579821a129a |
---|---|
21 module Redmine | 21 module Redmine |
22 module Scm | 22 module Scm |
23 module Adapters | 23 module Adapters |
24 class DarcsAdapter < AbstractAdapter | 24 class DarcsAdapter < AbstractAdapter |
25 # Darcs executable name | 25 # Darcs executable name |
26 DARCS_BIN = "darcs" | 26 DARCS_BIN = Redmine::Configuration['scm_darcs_command'] || "darcs" |
27 | 27 |
28 class << self | 28 class << self |
29 def client_version | 29 def client_version |
30 @@client_version ||= (darcs_binary_version || []) | 30 @@client_version ||= (darcs_binary_version || []) |
31 end | 31 end |
32 | 32 |
33 def darcs_binary_version | 33 def darcs_binary_version |
34 cmd = "#{DARCS_BIN} --version" | 34 darcsversion = darcs_binary_version_from_command_line |
35 version = nil | 35 if m = darcsversion.match(%r{\A(.*?)((\d+\.)+\d+)}) |
36 shellout(cmd) do |io| | 36 m[2].scan(%r{\d+}).collect(&:to_i) |
37 # Read darcs version in first returned line | 37 end |
38 if m = io.gets.match(%r{((\d+\.)+\d+)}) | 38 end |
39 version = m[0].scan(%r{\d+}).collect(&:to_i) | 39 |
40 end | 40 def darcs_binary_version_from_command_line |
41 end | 41 shellout("#{DARCS_BIN} --version") { |io| io.read }.to_s |
42 return nil if $? && $?.exitstatus != 0 | |
43 version | |
44 end | 42 end |
45 end | 43 end |
46 | 44 |
47 def initialize(url, root_url=nil, login=nil, password=nil) | 45 def initialize(url, root_url=nil, login=nil, password=nil) |
48 @url = url | 46 @url = url |
62 | 60 |
63 # Returns an Entries collection | 61 # Returns an Entries collection |
64 # or nil if the given path doesn't exist in the repository | 62 # or nil if the given path doesn't exist in the repository |
65 def entries(path=nil, identifier=nil) | 63 def entries(path=nil, identifier=nil) |
66 path_prefix = (path.blank? ? '' : "#{path}/") | 64 path_prefix = (path.blank? ? '' : "#{path}/") |
67 path = '.' if path.blank? | 65 if path.blank? |
66 path = ( self.class.client_version_above?([2, 2, 0]) ? @url : '.' ) | |
67 end | |
68 entries = Entries.new | 68 entries = Entries.new |
69 cmd = "#{DARCS_BIN} annotate --repodir #{shell_quote @url} --xml-output" | 69 cmd = "#{DARCS_BIN} annotate --repodir #{shell_quote @url} --xml-output" |
70 cmd << " --match #{shell_quote("hash #{identifier}")}" if identifier | 70 cmd << " --match #{shell_quote("hash #{identifier}")}" if identifier |
71 cmd << " #{shell_quote path}" | 71 cmd << " #{shell_quote path}" |
72 shellout(cmd) do |io| | 72 shellout(cmd) do |io| |
165 :identifier => nil, | 165 :identifier => nil, |
166 :scmid => modified_element.elements['patch'].attributes['hash'] | 166 :scmid => modified_element.elements['patch'].attributes['hash'] |
167 }) | 167 }) |
168 }) | 168 }) |
169 end | 169 end |
170 | |
171 def get_paths_for_patch(hash) | |
172 paths = get_paths_for_patch_raw(hash) | |
173 if self.class.client_version_above?([2, 4]) | |
174 orig_paths = paths | |
175 paths = [] | |
176 add_paths = [] | |
177 add_paths_name = [] | |
178 mod_paths = [] | |
179 other_paths = [] | |
180 orig_paths.each do |path| | |
181 if path[:action] == 'A' | |
182 add_paths << path | |
183 add_paths_name << path[:path] | |
184 elsif path[:action] == 'M' | |
185 mod_paths << path | |
186 else | |
187 other_paths << path | |
188 end | |
189 end | |
190 add_paths_name.each do |add_path| | |
191 mod_paths.delete_if { |m| m[:path] == add_path } | |
192 end | |
193 paths.concat add_paths | |
194 paths.concat mod_paths | |
195 paths.concat other_paths | |
196 end | |
197 paths | |
198 end | |
170 | 199 |
171 # Retrieve changed paths for a single patch | 200 # Retrieve changed paths for a single patch |
172 def get_paths_for_patch(hash) | 201 def get_paths_for_patch_raw(hash) |
173 cmd = "#{DARCS_BIN} annotate --repodir #{shell_quote @url} --summary --xml-output" | 202 cmd = "#{DARCS_BIN} annotate --repodir #{shell_quote @url} --summary --xml-output" |
174 cmd << " --match #{shell_quote("hash #{hash}")} " | 203 cmd << " --match #{shell_quote("hash #{hash}")} " |
175 paths = [] | 204 paths = [] |
176 shellout(cmd) do |io| | 205 shellout(cmd) do |io| |
177 begin | 206 begin |