ChiliProject is not maintained anymore. Please be advised that there will be no more updates.

We do not recommend that you setup new ChiliProject instances and we urge all existing users to migrate their data to a maintained system, e.g. Redmine. We will provide a migration script later. In the meantime, you can use the instructions by Christian Daehn.

chili_chardet.patch

Nickolay Shashkin, 2012-02-12 03:17 pm

Download (3 kB)

 
b/Gemfile
11 11
gem "acts-as-taggable-on", "= 2.1.0"
12 12
# Needed only on RUBY_VERSION = 1.8, ruby 1.9+ compatible interpreters should bring their csv
13 13
gem "fastercsv", "~> 1.5.0", :platforms => [:ruby_18, :jruby, :mingw_18]
14
# need for automatic encoding detection in diff,annotate and cat
15
gem "chardet", ">= 0.9.0"
14 16
group :test do
15 17
 gem 'shoulda', '~> 2.10.3'
b/lib/redmine/scm/adapters/mercurial_adapter.rb
15 15
require 'redmine/scm/adapters/abstract_adapter'
16 16
require 'cgi'
17
# need for automatic character detection in diff, annotate and cat
18
require 'rubygems'
19
require 'UniversalDetector'
20

  
17 21
module Redmine
18 22
 module Scm
19 23
   module Adapters
......
239 243
         diff = []
240 244
         hg *hg_args do |io|
241 245
           io.each_line do |line|
242
              diff << line
246
              iconv_line = line
247
              if !line.nil?
248
                detected = UniversalDetector::chardet(line)
249
                enc = detected['encoding']
250
                if !enc.nil?
251
                  begin
252
                    iconv_line = Iconv.conv('UTF-8', enc, line)
253
                  rescue Iconv::Failure => err
254
                  end
255
                end
256
              end
257
              diff << iconv_line
243 258
           end
244 259
         end
245 260
         diff
......
251 266
         p = CGI.escape(scm_iconv(@path_encoding, 'UTF-8', path))
252 267
         hg 'rhcat', '-r', CGI.escape(hgrev(identifier)), hgtarget(p) do |io|
253 268
           io.binmode
254
            io.read
269
            str = io.read
270
            return nil if str.nil?
271
            iconv_str = str
272
            detected = UniversalDetector::chardet(str)
273
            enc = detected['encoding']
274
            if !enc.nil?
275
              begin
276
                iconv_str = Iconv.conv('UTF-8', enc, str)
277
              rescue Iconv::Failure => err
278
              end
279
            end
280
            return iconv_str
255 281
         end
256 282
       rescue HgCommandAborted
257 283
         nil  # means not found
......
266 292
             next unless line =~ %r{^([^:]+)\s(\d+)\s([0-9a-f]+):\s(.*)$}
267 293
             r = Revision.new(:author => $1.strip, :revision => $2, :scmid => $3,
268 294
                              :identifier => $3)
269
              blame.add_line($4.rstrip, r)
295
              str = $4.rstrip
296
              iconv_str = str
297
              if !str.nil?
298
                detected = UniversalDetector::chardet(str)
299
                enc = detected['encoding']
300
                if !enc.nil?
301
                  begin
302
                    iconv_str = Iconv.conv('UTF-8', enc, str)
303
                  rescue Iconv::Failure => err
304
                  end
305
                end
306
              end
307
              blame.add_line(iconv_str, r)
270 308
           end
271 309
         end
272 310
         blame