Commit 7002b9ff117298a5f8cd5150ef69e01628096d3e

Authored by Saito
2 parents 22442039 46cbe541

Merge branch 'chardet'

1 -source 'http://rubygems.org' 1 +source "http://rubygems.org"
2 2
3 -gem 'rails', '3.1.1' 3 +gem "rails", "3.1.1"
4 4
5 -gem 'sqlite3'  
6 -gem 'devise', "1.5.0"  
7 -gem 'stamp'  
8 -gem 'kaminari'  
9 -gem 'haml-rails'  
10 -gem 'jquery-rails'  
11 -gem 'grit', :git => 'https://github.com/gitlabhq/grit.git' 5 +gem "sqlite3"
  6 +gem "devise", "1.5.0"
  7 +gem "stamp"
  8 +gem "kaminari"
  9 +gem "haml-rails"
  10 +gem "jquery-rails"
  11 +gem "grit", :git => "https://github.com/gitlabhq/grit.git"
12 gem "carrierwave" 12 gem "carrierwave"
13 -gem 'six'  
14 -gem 'therubyracer'  
15 -gem 'faker'  
16 -gem 'seed-fu', '~> 2.1.0' 13 +gem "six"
  14 +gem "therubyracer"
  15 +gem "faker"
  16 +gem "seed-fu", "~> 2.1.0"
17 gem "inifile" 17 gem "inifile"
18 gem "pygments.rb", "0.2.3" 18 gem "pygments.rb", "0.2.3"
19 gem "thin" 19 gem "thin"
20 gem "git" 20 gem "git"
21 gem "acts_as_list" 21 gem "acts_as_list"
22 -gem 'rdiscount'  
23 -gem 'acts-as-taggable-on', '~> 2.1.0'  
24 -gem 'drapper' 22 +gem "rdiscount"
  23 +gem "acts-as-taggable-on", "~> 2.1.0"
  24 +gem "drapper"
  25 +gem "rchardet19", "~> 1.3.5"
25 26
26 group :assets do 27 group :assets do
27 - gem 'sass-rails', "~> 3.1.0"  
28 - gem 'coffee-rails', "~> 3.1.0"  
29 - gem 'uglifier' 28 + gem "sass-rails", "~> 3.1.0"
  29 + gem "coffee-rails", "~> 3.1.0"
  30 + gem "uglifier"
30 end 31 end
31 32
32 group :development do 33 group :development do
33 - gem 'letter_opener'  
34 - gem 'rails-footnotes', '~> 3.7.5'  
35 - gem 'annotate', :git => 'https://github.com/ctran/annotate_models.git' 34 + gem "letter_opener"
  35 + gem "rails-footnotes", "~> 3.7.5"
  36 + gem "annotate", :git => "https://github.com/ctran/annotate_models.git"
36 end 37 end
37 38
38 group :development, :test do 39 group :development, :test do
39 - gem 'rspec-rails'  
40 - gem 'capybara'  
41 - gem 'autotest'  
42 - gem 'autotest-rails' 40 + gem "rspec-rails"
  41 + gem "capybara"
  42 + gem "autotest"
  43 + gem "autotest-rails"
43 unless ENV["CI"] 44 unless ENV["CI"]
44 - gem 'ruby-debug19', :require => 'ruby-debug' 45 + gem "ruby-debug19", :require => "ruby-debug"
45 end 46 end
46 - gem 'awesome_print'  
47 - gem 'database_cleaner'  
48 - gem 'launchy' 47 + gem "awesome_print"
  48 + gem "database_cleaner"
  49 + gem "launchy"
49 end 50 end
50 51
51 group :test do 52 group :test do
52 - gem 'turn', :require => false  
53 - gem 'simplecov', :require => false 53 + gem "turn", :require => false
  54 + gem "simplecov", :require => false
54 gem "shoulda", "~> 3.0.0.beta2" 55 gem "shoulda", "~> 3.0.0.beta2"
55 end 56 end
@@ -157,6 +157,7 @@ GEM @@ -157,6 +157,7 @@ GEM
157 rdoc (~> 3.4) 157 rdoc (~> 3.4)
158 thor (~> 0.14.6) 158 thor (~> 0.14.6)
159 rake (0.9.2.2) 159 rake (0.9.2.2)
  160 + rchardet19 (1.3.5)
160 rdiscount (1.6.8) 161 rdiscount (1.6.8)
161 rdoc (3.11) 162 rdoc (3.11)
162 json (~> 1.4) 163 json (~> 1.4)
@@ -268,6 +269,7 @@ DEPENDENCIES @@ -268,6 +269,7 @@ DEPENDENCIES
268 pygments.rb (= 0.2.3) 269 pygments.rb (= 0.2.3)
269 rails (= 3.1.1) 270 rails (= 3.1.1)
270 rails-footnotes (~> 3.7.5) 271 rails-footnotes (~> 3.7.5)
  272 + rchardet19 (~> 1.3.5)
271 rdiscount 273 rdiscount
272 rspec-rails 274 rspec-rails
273 ruby-debug19 275 ruby-debug19
app/helpers/commits_helper.rb
1 module CommitsHelper 1 module CommitsHelper
  2 + include Utils::CharEncode
2 def diff_line(line, line_new = 0, line_old = 0) 3 def diff_line(line, line_new = 0, line_old = 0)
3 full_line = html_escape(line.gsub(/\n/, '')) 4 full_line = html_escape(line.gsub(/\n/, ''))
4 color = if line[0] == "+" 5 color = if line[0] == "+"
app/models/commit.rb
1 class Commit 1 class Commit
  2 + include Utils::CharEncode
  3 +
2 attr_accessor :commit 4 attr_accessor :commit
3 attr_accessor :head 5 attr_accessor :head
4 6
@@ -20,7 +22,7 @@ class Commit @@ -20,7 +22,7 @@ class Commit
20 end 22 end
21 23
22 def safe_message 24 def safe_message
23 - message.force_encoding(Encoding::UTF_8) 25 + encode(message)
24 end 26 end
25 27
26 def created_at 28 def created_at
@@ -28,10 +30,10 @@ class Commit @@ -28,10 +30,10 @@ class Commit
28 end 30 end
29 31
30 def author_email 32 def author_email
31 - author.email.force_encoding(Encoding::UTF_8) 33 + encode(author.email)
32 end 34 end
33 35
34 def author_name 36 def author_name
35 - author.name.force_encoding(Encoding::UTF_8) 37 + encode(author.name)
36 end 38 end
37 end 39 end
app/views/commits/_text_file.html.haml
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 - line_new = 0 2 - line_new = 0
3 - lines_arr = diff.diff.lines.to_a 3 - lines_arr = diff.diff.lines.to_a
4 - lines_arr.each do |line| 4 - lines_arr.each do |line|
5 - - line.force_encoding(Encoding::UTF_8) 5 + - encode(line)
6 - next if line.match(/^--- \/dev\/null/) 6 - next if line.match(/^--- \/dev\/null/)
7 - next if line.match(/^--- a/) 7 - next if line.match(/^--- a/)
8 - next if line.match(/^\+\+\+ b/) 8 - next if line.match(/^\+\+\+ b/)
lib/graph_commit.rb
1 require "grit" 1 require "grit"
2 2
3 class GraphCommit 3 class GraphCommit
  4 + include Utils::CharEncode
4 attr_accessor :time, :space 5 attr_accessor :time, :space
5 attr_accessor :refs 6 attr_accessor :refs
6 7
@@ -65,7 +66,7 @@ class GraphCommit @@ -65,7 +66,7 @@ class GraphCommit
65 # @param [GraphCommit] the commit object. 66 # @param [GraphCommit] the commit object.
66 # @param [Hash<String,GraphCommit>] map of commits 67 # @param [Hash<String,GraphCommit>] map of commits
67 # 68 #
68 - # @return [Fixnum] max space used. 69 + # @return [Fixnum] max space used.
69 def self.mark_chain(mark, commit, map) 70 def self.mark_chain(mark, commit, map)
70 commit.space = mark if commit.space == 0 71 commit.space = mark if commit.space == 0
71 m1 = mark - 1 72 m1 = mark - 1
@@ -96,13 +97,13 @@ class GraphCommit @@ -96,13 +97,13 @@ class GraphCommit
96 h[:parents] = self.parents.collect do |p| 97 h[:parents] = self.parents.collect do |p|
97 [p.id,0,0] 98 [p.id,0,0]
98 end 99 end
99 - h[:author] = author.name.force_encoding("UTF-8") 100 + h[:author] = encode(author.name)
100 h[:time] = time 101 h[:time] = time
101 h[:space] = space 102 h[:space] = space
102 h[:refs] = refs.collect{|r|r.name}.join(" ") unless refs.nil? 103 h[:refs] = refs.collect{|r|r.name}.join(" ") unless refs.nil?
103 h[:id] = sha 104 h[:id] = sha
104 h[:date] = date 105 h[:date] = date
105 - h[:message] = message.force_encoding("UTF-8") 106 + h[:message] = encode(message)
106 h[:login] = author.email 107 h[:login] = author.email
107 h 108 h
108 end 109 end
@@ -16,9 +16,20 @@ module Utils @@ -16,9 +16,20 @@ module Utils
16 end 16 end
17 end 17 end
18 18
  19 + module CharEncode
  20 + def encode(string)
  21 + cd = CharDet.detect(string)
  22 + if cd.confidence > 0.6
  23 + string.force_encoding(cd.encoding)
  24 + end
  25 + string.encode("utf-8", :undef => :replace, :replace => "?", :invalid => :replace)
  26 + end
  27 + end
  28 +
19 module Colorize 29 module Colorize
  30 + include CharEncode
20 def colorize 31 def colorize
21 - system_colorize(data, name) 32 + system_colorize(encode(data), name)
22 end 33 end
23 34
24 def system_colorize(data, file_name) 35 def system_colorize(data, file_name)