Mercurial > hg > soundsoftware-site
comparison lib/redmine/scm/adapters/bazaar_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 | cbce1fd3b1b7 |
children | 433d4f72a19b |
comparison
equal
deleted
inserted
replaced
908:c6c2cbd0afee | 909:cbb26bc654de |
---|---|
29 def client_command | 29 def client_command |
30 @@bin ||= BZR_BIN | 30 @@bin ||= BZR_BIN |
31 end | 31 end |
32 | 32 |
33 def sq_bin | 33 def sq_bin |
34 @@sq_bin ||= shell_quote(BZR_BIN) | 34 @@sq_bin ||= shell_quote_command |
35 end | 35 end |
36 | 36 |
37 def client_version | 37 def client_version |
38 @@client_version ||= (scm_command_version || []) | 38 @@client_version ||= (scm_command_version || []) |
39 end | 39 end |
57 end | 57 end |
58 end | 58 end |
59 | 59 |
60 # Get info about the repository | 60 # Get info about the repository |
61 def info | 61 def info |
62 cmd = "#{self.class.sq_bin} revno #{target('')}" | 62 cmd_args = %w|revno| |
63 cmd_args << bzr_target('') | |
63 info = nil | 64 info = nil |
64 shellout(cmd) do |io| | 65 scm_cmd(*cmd_args) do |io| |
65 if io.read =~ %r{^(\d+)\r?$} | 66 if io.read =~ %r{^(\d+)\r?$} |
66 info = Info.new({:root_url => url, | 67 info = Info.new({:root_url => url, |
67 :lastrev => Revision.new({ | 68 :lastrev => Revision.new({ |
68 :identifier => $1 | 69 :identifier => $1 |
69 }) | 70 }) |
70 }) | 71 }) |
71 end | 72 end |
72 end | 73 end |
73 return nil if $? && $?.exitstatus != 0 | |
74 info | 74 info |
75 rescue CommandFailed | 75 rescue ScmCommandAborted |
76 return nil | 76 return nil |
77 end | 77 end |
78 | 78 |
79 # Returns an Entries collection | 79 # Returns an Entries collection |
80 # or nil if the given path doesn't exist in the repository | 80 # or nil if the given path doesn't exist in the repository |
81 def entries(path=nil, identifier=nil, options={}) | 81 def entries(path=nil, identifier=nil, options={}) |
82 path ||= '' | 82 path ||= '' |
83 entries = Entries.new | 83 entries = Entries.new |
84 cmd = "#{self.class.sq_bin} ls -v --show-ids" | |
85 identifier = -1 unless identifier && identifier.to_i > 0 | 84 identifier = -1 unless identifier && identifier.to_i > 0 |
86 cmd << " -r#{identifier.to_i}" | 85 cmd_args = %w|ls -v --show-ids| |
87 cmd << " #{target(path)}" | 86 cmd_args << "-r#{identifier.to_i}" |
88 shellout(cmd) do |io| | 87 cmd_args << bzr_target(path) |
88 scm_cmd(*cmd_args) do |io| | |
89 prefix = "#{url}/#{path}".gsub('\\', '/') | 89 prefix = "#{url}/#{path}".gsub('\\', '/') |
90 logger.debug "PREFIX: #{prefix}" | 90 logger.debug "PREFIX: #{prefix}" |
91 re = %r{^V\s+(#{Regexp.escape(prefix)})?(\/?)([^\/]+)(\/?)\s+(\S+)\r?$} | 91 re = %r{^V\s+(#{Regexp.escape(prefix)})?(\/?)([^\/]+)(\/?)\s+(\S+)\r?$} |
92 io.each_line do |line| | 92 io.each_line do |line| |
93 next unless line =~ re | 93 next unless line =~ re |
97 :size => nil, | 97 :size => nil, |
98 :lastrev => Revision.new(:revision => $5.strip) | 98 :lastrev => Revision.new(:revision => $5.strip) |
99 }) | 99 }) |
100 end | 100 end |
101 end | 101 end |
102 return nil if $? && $?.exitstatus != 0 | 102 if logger && logger.debug? |
103 logger.debug("Found #{entries.size} entries in the repository for #{target(path)}") if logger && logger.debug? | 103 logger.debug("Found #{entries.size} entries in the repository for #{target(path)}") |
104 end | |
104 entries.sort_by_name | 105 entries.sort_by_name |
106 rescue ScmCommandAborted | |
107 return nil | |
105 end | 108 end |
106 | 109 |
107 def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={}) | 110 def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={}) |
108 path ||= '' | 111 path ||= '' |
109 identifier_from = (identifier_from and identifier_from.to_i > 0) ? identifier_from.to_i : 'last:1' | 112 identifier_from = (identifier_from and identifier_from.to_i > 0) ? identifier_from.to_i : 'last:1' |
110 identifier_to = (identifier_to and identifier_to.to_i > 0) ? identifier_to.to_i : 1 | 113 identifier_to = (identifier_to and identifier_to.to_i > 0) ? identifier_to.to_i : 1 |
111 revisions = Revisions.new | 114 revisions = Revisions.new |
112 cmd = "#{self.class.sq_bin} log -v --show-ids -r#{identifier_to}..#{identifier_from} #{target(path)}" | 115 cmd_args = %w|log -v --show-ids| |
113 shellout(cmd) do |io| | 116 cmd_args << "-r#{identifier_to}..#{identifier_from}" |
117 cmd_args << bzr_target(path) | |
118 scm_cmd(*cmd_args) do |io| | |
114 revision = nil | 119 revision = nil |
115 parsing = nil | 120 parsing = nil |
116 io.each_line do |line| | 121 io.each_line do |line| |
117 if line =~ /^----/ | 122 if line =~ /^----/ |
118 revisions << revision if revision | 123 revisions << revision if revision |
119 revision = Revision.new(:paths => [], :message => '') | 124 revision = Revision.new(:paths => [], :message => '') |
120 parsing = nil | 125 parsing = nil |
158 end | 163 end |
159 end | 164 end |
160 end | 165 end |
161 revisions << revision if revision | 166 revisions << revision if revision |
162 end | 167 end |
163 return nil if $? && $?.exitstatus != 0 | |
164 revisions | 168 revisions |
169 rescue ScmCommandAborted | |
170 return nil | |
165 end | 171 end |
166 | 172 |
167 def diff(path, identifier_from, identifier_to=nil) | 173 def diff(path, identifier_from, identifier_to=nil) |
168 path ||= '' | 174 path ||= '' |
169 if identifier_to | 175 if identifier_to |
172 identifier_to = identifier_from.to_i - 1 | 178 identifier_to = identifier_from.to_i - 1 |
173 end | 179 end |
174 if identifier_from | 180 if identifier_from |
175 identifier_from = identifier_from.to_i | 181 identifier_from = identifier_from.to_i |
176 end | 182 end |
177 cmd = "#{self.class.sq_bin} diff -r#{identifier_to}..#{identifier_from} #{target(path)}" | |
178 diff = [] | 183 diff = [] |
179 shellout(cmd) do |io| | 184 cmd_args = %w|diff| |
185 cmd_args << "-r#{identifier_to}..#{identifier_from}" | |
186 cmd_args << bzr_target(path) | |
187 scm_cmd_no_raise(*cmd_args) do |io| | |
180 io.each_line do |line| | 188 io.each_line do |line| |
181 diff << line | 189 diff << line |
182 end | 190 end |
183 end | 191 end |
184 #return nil if $? && $?.exitstatus != 0 | |
185 diff | 192 diff |
186 end | 193 end |
187 | 194 |
188 def cat(path, identifier=nil) | 195 def cat(path, identifier=nil) |
189 cmd = "#{self.class.sq_bin} cat" | |
190 cmd << " -r#{identifier.to_i}" if identifier && identifier.to_i > 0 | |
191 cmd << " #{target(path)}" | |
192 cat = nil | 196 cat = nil |
193 shellout(cmd) do |io| | 197 cmd_args = %w|cat| |
198 cmd_args << "-r#{identifier.to_i}" if identifier && identifier.to_i > 0 | |
199 cmd_args << bzr_target(path) | |
200 scm_cmd(*cmd_args) do |io| | |
194 io.binmode | 201 io.binmode |
195 cat = io.read | 202 cat = io.read |
196 end | 203 end |
197 return nil if $? && $?.exitstatus != 0 | |
198 cat | 204 cat |
205 rescue ScmCommandAborted | |
206 return nil | |
199 end | 207 end |
200 | 208 |
201 def annotate(path, identifier=nil) | 209 def annotate(path, identifier=nil) |
202 cmd = "#{self.class.sq_bin} annotate --all" | |
203 cmd << " -r#{identifier.to_i}" if identifier && identifier.to_i > 0 | |
204 cmd << " #{target(path)}" | |
205 blame = Annotate.new | 210 blame = Annotate.new |
206 shellout(cmd) do |io| | 211 cmd_args = %w|annotate -q --all| |
207 author = nil | 212 cmd_args << "-r#{identifier.to_i}" if identifier && identifier.to_i > 0 |
213 cmd_args << bzr_target(path) | |
214 scm_cmd(*cmd_args) do |io| | |
215 author = nil | |
208 identifier = nil | 216 identifier = nil |
209 io.each_line do |line| | 217 io.each_line do |line| |
210 next unless line =~ %r{^(\d+) ([^|]+)\| (.*)$} | 218 next unless line =~ %r{^(\d+) ([^|]+)\| (.*)$} |
211 rev = $1 | 219 rev = $1 |
212 blame.add_line($3.rstrip, | 220 blame.add_line($3.rstrip, |
215 :revision => rev, | 223 :revision => rev, |
216 :author => $2.strip | 224 :author => $2.strip |
217 )) | 225 )) |
218 end | 226 end |
219 end | 227 end |
220 return nil if $? && $?.exitstatus != 0 | |
221 blame | 228 blame |
222 end | 229 rescue ScmCommandAborted |
230 return nil | |
231 end | |
232 | |
233 def self.branch_conf_path(path) | |
234 bcp = nil | |
235 m = path.match(%r{^(.*[/\\])\.bzr.*$}) | |
236 if m | |
237 bcp = m[1] | |
238 else | |
239 bcp = path | |
240 end | |
241 bcp.gsub!(%r{[\/\\]$}, "") | |
242 if bcp | |
243 bcp = File.join(bcp, ".bzr", "branch", "branch.conf") | |
244 end | |
245 bcp | |
246 end | |
247 | |
248 def append_revisions_only | |
249 return @aro if ! @aro.nil? | |
250 @aro = false | |
251 bcp = self.class.branch_conf_path(url) | |
252 if bcp && File.exist?(bcp) | |
253 begin | |
254 f = File::open(bcp, "r") | |
255 cnt = 0 | |
256 f.each_line do |line| | |
257 l = line.chomp.to_s | |
258 if l =~ /^\s*append_revisions_only\s*=\s*(\w+)\s*$/ | |
259 str_aro = $1 | |
260 if str_aro.upcase == "TRUE" | |
261 @aro = true | |
262 cnt += 1 | |
263 elsif str_aro.upcase == "FALSE" | |
264 @aro = false | |
265 cnt += 1 | |
266 end | |
267 if cnt > 1 | |
268 @aro = false | |
269 break | |
270 end | |
271 end | |
272 end | |
273 ensure | |
274 f.close | |
275 end | |
276 end | |
277 @aro | |
278 end | |
279 | |
280 def scm_cmd(*args, &block) | |
281 full_args = [] | |
282 full_args += args | |
283 ret = shellout( | |
284 self.class.sq_bin + ' ' + full_args.map { |e| shell_quote e.to_s }.join(' '), | |
285 &block | |
286 ) | |
287 if $? && $?.exitstatus != 0 | |
288 raise ScmCommandAborted, "bzr exited with non-zero status: #{$?.exitstatus}" | |
289 end | |
290 ret | |
291 end | |
292 private :scm_cmd | |
293 | |
294 def scm_cmd_no_raise(*args, &block) | |
295 full_args = [] | |
296 full_args += args | |
297 ret = shellout( | |
298 self.class.sq_bin + ' ' + full_args.map { |e| shell_quote e.to_s }.join(' '), | |
299 &block | |
300 ) | |
301 ret | |
302 end | |
303 private :scm_cmd_no_raise | |
304 | |
305 def bzr_target(path) | |
306 target(path, false) | |
307 end | |
308 private :bzr_target | |
223 end | 309 end |
224 end | 310 end |
225 end | 311 end |
226 end | 312 end |