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.

0001-Automatic-character-encoding-detection-in-repos.patch

Patch in Git format. - Nickolay Shashkin, 2012-02-13 09:55 am

Download (3.4 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

  
15 17
group :test do
16 18
  gem 'shoulda', '~> 2.10.3'
b/lib/redmine/scm/adapters/mercurial_adapter.rb
14 14

  
15 15
require 'redmine/scm/adapters/abstract_adapter'
16 16
require 'cgi'
17
require 'rubygems'
18
require 'UniversalDetector'
17 19

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