comparison lib/redmine/scm/adapters/bazaar_adapter.rb @ 1115:433d4f72a19b redmine-2.2

Update to Redmine SVN revision 11137 on 2.2-stable branch
author Chris Cannam
date Mon, 07 Jan 2013 12:01:42 +0000
parents cbb26bc654de
children 51d7f3e06556 622f24f53b42
comparison
equal deleted inserted replaced
929:5f33065ddc4b 1115:433d4f72a19b
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
55 def scm_version_from_command_line 55 def scm_version_from_command_line
56 shellout("#{sq_bin} --version") { |io| io.read }.to_s 56 shellout("#{sq_bin} --version") { |io| io.read }.to_s
57 end 57 end
58 end 58 end
59 59
60 def initialize(url, root_url=nil, login=nil, password=nil, path_encoding=nil)
61 @url = url
62 @root_url = url
63 @path_encoding = 'UTF-8'
64 # do not call *super* for non ASCII repository path
65 end
66
67 def bzr_path_encodig=(encoding)
68 @path_encoding = encoding
69 end
70
60 # Get info about the repository 71 # Get info about the repository
61 def info 72 def info
62 cmd_args = %w|revno| 73 cmd_args = %w|revno|
63 cmd_args << bzr_target('') 74 cmd_args << bzr_target('')
64 info = nil 75 info = nil
84 identifier = -1 unless identifier && identifier.to_i > 0 95 identifier = -1 unless identifier && identifier.to_i > 0
85 cmd_args = %w|ls -v --show-ids| 96 cmd_args = %w|ls -v --show-ids|
86 cmd_args << "-r#{identifier.to_i}" 97 cmd_args << "-r#{identifier.to_i}"
87 cmd_args << bzr_target(path) 98 cmd_args << bzr_target(path)
88 scm_cmd(*cmd_args) do |io| 99 scm_cmd(*cmd_args) do |io|
89 prefix = "#{url}/#{path}".gsub('\\', '/') 100 prefix_utf8 = "#{url}/#{path}".gsub('\\', '/')
90 logger.debug "PREFIX: #{prefix}" 101 logger.debug "PREFIX: #{prefix_utf8}"
102 prefix = scm_iconv(@path_encoding, 'UTF-8', prefix_utf8)
103 prefix.force_encoding('ASCII-8BIT') if prefix.respond_to?(:force_encoding)
91 re = %r{^V\s+(#{Regexp.escape(prefix)})?(\/?)([^\/]+)(\/?)\s+(\S+)\r?$} 104 re = %r{^V\s+(#{Regexp.escape(prefix)})?(\/?)([^\/]+)(\/?)\s+(\S+)\r?$}
92 io.each_line do |line| 105 io.each_line do |line|
93 next unless line =~ re 106 next unless line =~ re
94 entries << Entry.new({:name => $3.strip, 107 name_locale = $3.strip
95 :path => ((path.empty? ? "" : "#{path}/") + $3.strip), 108 name = scm_iconv('UTF-8', @path_encoding, name_locale)
109 entries << Entry.new({:name => name,
110 :path => ((path.empty? ? "" : "#{path}/") + name),
96 :kind => ($4.blank? ? 'file' : 'dir'), 111 :kind => ($4.blank? ? 'file' : 'dir'),
97 :size => nil, 112 :size => nil,
98 :lastrev => Revision.new(:revision => $5.strip) 113 :lastrev => Revision.new(:revision => $5.strip)
99 }) 114 })
100 end 115 end
141 elsif line =~ /^ (.*)$/ 156 elsif line =~ /^ (.*)$/
142 if parsing == 'message' 157 if parsing == 'message'
143 revision.message << "#{$1}\n" 158 revision.message << "#{$1}\n"
144 else 159 else
145 if $1 =~ /^(.*)\s+(\S+)$/ 160 if $1 =~ /^(.*)\s+(\S+)$/
146 path = $1.strip 161 path_locale = $1.strip
162 path = scm_iconv('UTF-8', @path_encoding, path_locale)
147 revid = $2 163 revid = $2
148 case parsing 164 case parsing
149 when 'added' 165 when 'added'
150 revision.paths << {:action => 'A', :path => "/#{path}", :revision => revid} 166 revision.paths << {:action => 'A', :path => "/#{path}", :revision => revid}
151 when 'modified' 167 when 'modified'
152 revision.paths << {:action => 'M', :path => "/#{path}", :revision => revid} 168 revision.paths << {:action => 'M', :path => "/#{path}", :revision => revid}
153 when 'removed' 169 when 'removed'
154 revision.paths << {:action => 'D', :path => "/#{path}", :revision => revid} 170 revision.paths << {:action => 'D', :path => "/#{path}", :revision => revid}
155 when 'renamed' 171 when 'renamed'
156 new_path = path.split('=>').last 172 new_path = path.split('=>').last
157 revision.paths << {:action => 'M', :path => "/#{new_path.strip}", :revision => revid} if new_path 173 if new_path
174 revision.paths << {:action => 'M', :path => "/#{new_path.strip}",
175 :revision => revid}
176 end
158 end 177 end
159 end 178 end
160 end 179 end
161 else 180 else
162 parsing = nil 181 parsing = nil
278 end 297 end
279 298
280 def scm_cmd(*args, &block) 299 def scm_cmd(*args, &block)
281 full_args = [] 300 full_args = []
282 full_args += args 301 full_args += args
302 full_args_locale = []
303 full_args.map do |e|
304 full_args_locale << scm_iconv(@path_encoding, 'UTF-8', e)
305 end
283 ret = shellout( 306 ret = shellout(
284 self.class.sq_bin + ' ' + full_args.map { |e| shell_quote e.to_s }.join(' '), 307 self.class.sq_bin + ' ' +
308 full_args_locale.map { |e| shell_quote e.to_s }.join(' '),
285 &block 309 &block
286 ) 310 )
287 if $? && $?.exitstatus != 0 311 if $? && $?.exitstatus != 0
288 raise ScmCommandAborted, "bzr exited with non-zero status: #{$?.exitstatus}" 312 raise ScmCommandAborted, "bzr exited with non-zero status: #{$?.exitstatus}"
289 end 313 end
292 private :scm_cmd 316 private :scm_cmd
293 317
294 def scm_cmd_no_raise(*args, &block) 318 def scm_cmd_no_raise(*args, &block)
295 full_args = [] 319 full_args = []
296 full_args += args 320 full_args += args
321 full_args_locale = []
322 full_args.map do |e|
323 full_args_locale << scm_iconv(@path_encoding, 'UTF-8', e)
324 end
297 ret = shellout( 325 ret = shellout(
298 self.class.sq_bin + ' ' + full_args.map { |e| shell_quote e.to_s }.join(' '), 326 self.class.sq_bin + ' ' +
327 full_args_locale.map { |e| shell_quote e.to_s }.join(' '),
299 &block 328 &block
300 ) 329 )
301 ret 330 ret
302 end 331 end
303 private :scm_cmd_no_raise 332 private :scm_cmd_no_raise