Mercurial > hg > soundsoftware-site
comparison lib/redmine/scm/adapters/mercurial_adapter.rb @ 909:cbb26bc654de redmine-1.3
Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author | Chris Cannam |
---|---|
date | Fri, 24 Feb 2012 19:09:32 +0000 |
parents | 0c939c159af4 |
children | 5e80956cc792 433d4f72a19b |
comparison
equal
deleted
inserted
replaced
908:c6c2cbd0afee | 909:cbb26bc654de |
---|---|
37 def client_command | 37 def client_command |
38 @@bin ||= HG_BIN | 38 @@bin ||= HG_BIN |
39 end | 39 end |
40 | 40 |
41 def sq_bin | 41 def sq_bin |
42 @@sq_bin ||= shell_quote(HG_BIN) | 42 @@sq_bin ||= shell_quote_command |
43 end | 43 end |
44 | 44 |
45 def client_version | 45 def client_version |
46 @@client_version ||= (hgversion || []) | 46 @@client_version ||= (hgversion || []) |
47 end | 47 end |
48 | 48 |
49 def client_available | 49 def client_available |
50 client_version_above?([0, 9, 5]) | 50 client_version_above?([1, 2]) |
51 end | 51 end |
52 | 52 |
53 def hgversion | 53 def hgversion |
54 # The hg version is expressed either as a | 54 # The hg version is expressed either as a |
55 # release number (eg 0.9.5 or 1.0) or as a revision | 55 # release number (eg 0.9.5 or 1.0) or as a revision |
70 def template_path | 70 def template_path |
71 @@template_path ||= template_path_for(client_version) | 71 @@template_path ||= template_path_for(client_version) |
72 end | 72 end |
73 | 73 |
74 def template_path_for(version) | 74 def template_path_for(version) |
75 if ((version <=> [0,9,5]) > 0) || version.empty? | 75 "#{HELPERS_DIR}/#{TEMPLATE_NAME}-1.0.#{TEMPLATE_EXTENSION}" |
76 ver = "1.0" | |
77 else | |
78 ver = "0.9.5" | |
79 end | |
80 "#{HELPERS_DIR}/#{TEMPLATE_NAME}-#{ver}.#{TEMPLATE_EXTENSION}" | |
81 end | 76 end |
82 end | 77 end |
83 | 78 |
84 def initialize(url, root_url=nil, login=nil, password=nil, path_encoding=nil) | 79 def initialize(url, root_url=nil, login=nil, password=nil, path_encoding=nil) |
85 super | 80 super |
112 end | 107 end |
113 Hash[*alist.flatten] | 108 Hash[*alist.flatten] |
114 end | 109 end |
115 | 110 |
116 def branches | 111 def branches |
117 as_ary(summary['repository']['branch']).map { |e| e['name'] } | 112 brs = [] |
113 as_ary(summary['repository']['branch']).each do |e| | |
114 br = Branch.new(e['name']) | |
115 br.revision = e['revision'] | |
116 br.scmid = e['node'] | |
117 brs << br | |
118 end | |
119 brs | |
118 end | 120 end |
119 | 121 |
120 # Returns map of {'branch' => 'nodeid', ...} | 122 # Returns map of {'branch' => 'nodeid', ...} |
121 def branchmap | 123 def branchmap |
122 alist = as_ary(summary['repository']['branch']).map do |e| | 124 alist = as_ary(summary['repository']['branch']).map do |e| |
213 {:action => e['action'], | 215 {:action => e['action'], |
214 :path => with_leading_slash(p), | 216 :path => with_leading_slash(p), |
215 :from_path => (cpmap.member?(p) ? with_leading_slash(cpmap[p]) : nil), | 217 :from_path => (cpmap.member?(p) ? with_leading_slash(cpmap[p]) : nil), |
216 :from_revision => (cpmap.member?(p) ? le['node'] : nil)} | 218 :from_revision => (cpmap.member?(p) ? le['node'] : nil)} |
217 end.sort { |a, b| a[:path] <=> b[:path] } | 219 end.sort { |a, b| a[:path] <=> b[:path] } |
220 parents_ary = [] | |
221 as_ary(le['parents']['parent']).map do |par| | |
222 parents_ary << par['__content__'] if par['__content__'] != "000000000000" | |
223 end | |
218 yield Revision.new(:revision => le['revision'], | 224 yield Revision.new(:revision => le['revision'], |
219 :scmid => le['node'], | 225 :scmid => le['node'], |
220 :author => (le['author']['__content__'] rescue ''), | 226 :author => (le['author']['__content__'] rescue ''), |
221 :time => Time.parse(le['date']['__content__']), | 227 :time => Time.parse(le['date']['__content__']), |
222 :message => le['msg']['__content__'], | 228 :message => le['msg']['__content__'], |
223 :paths => paths) | 229 :paths => paths, |
230 :parents => parents_ary) | |
224 end | 231 end |
225 self | 232 self |
226 end | 233 end |
227 | 234 |
228 # Returns list of nodes in the specified branch | 235 # Returns list of nodes in the specified branch |
292 end | 299 end |
293 | 300 |
294 # Runs 'hg' command with the given args | 301 # Runs 'hg' command with the given args |
295 def hg(*args, &block) | 302 def hg(*args, &block) |
296 repo_path = root_url || url | 303 repo_path = root_url || url |
297 full_args = [HG_BIN, '-R', repo_path, '--encoding', 'utf-8'] | 304 full_args = ['-R', repo_path, '--encoding', 'utf-8'] |
298 full_args << '--config' << "extensions.redminehelper=#{HG_HELPER_EXT}" | 305 full_args << '--config' << "extensions.redminehelper=#{HG_HELPER_EXT}" |
299 full_args << '--config' << 'diff.git=false' | 306 full_args << '--config' << 'diff.git=false' |
300 full_args += args | 307 full_args += args |
301 ret = shellout(full_args.map { |e| shell_quote e.to_s }.join(' '), &block) | 308 ret = shellout( |
309 self.class.sq_bin + ' ' + full_args.map { |e| shell_quote e.to_s }.join(' '), | |
310 &block | |
311 ) | |
302 if $? && $?.exitstatus != 0 | 312 if $? && $?.exitstatus != 0 |
303 raise HgCommandAborted, "hg exited with non-zero status: #{$?.exitstatus}" | 313 raise HgCommandAborted, "hg exited with non-zero status: #{$?.exitstatus}" |
304 end | 314 end |
305 ret | 315 ret |
306 end | 316 end |