Commit 7002b9ff117298a5f8cd5150ef69e01628096d3e
Exists in
master
and in
4 other branches
Merge branch 'chardet'
Showing
7 changed files
with
58 additions
and
40 deletions
Show diff stats
Gemfile
| 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 | 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 | 17 | gem "inifile" |
| 18 | 18 | gem "pygments.rb", "0.2.3" |
| 19 | 19 | gem "thin" |
| 20 | 20 | gem "git" |
| 21 | 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 | 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 | 31 | end |
| 31 | 32 | |
| 32 | 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 | 37 | end |
| 37 | 38 | |
| 38 | 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 | 44 | unless ENV["CI"] |
| 44 | - gem 'ruby-debug19', :require => 'ruby-debug' | |
| 45 | + gem "ruby-debug19", :require => "ruby-debug" | |
| 45 | 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 | 50 | end |
| 50 | 51 | |
| 51 | 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 | 55 | gem "shoulda", "~> 3.0.0.beta2" |
| 55 | 56 | end | ... | ... |
Gemfile.lock
| ... | ... | @@ -157,6 +157,7 @@ GEM |
| 157 | 157 | rdoc (~> 3.4) |
| 158 | 158 | thor (~> 0.14.6) |
| 159 | 159 | rake (0.9.2.2) |
| 160 | + rchardet19 (1.3.5) | |
| 160 | 161 | rdiscount (1.6.8) |
| 161 | 162 | rdoc (3.11) |
| 162 | 163 | json (~> 1.4) |
| ... | ... | @@ -268,6 +269,7 @@ DEPENDENCIES |
| 268 | 269 | pygments.rb (= 0.2.3) |
| 269 | 270 | rails (= 3.1.1) |
| 270 | 271 | rails-footnotes (~> 3.7.5) |
| 272 | + rchardet19 (~> 1.3.5) | |
| 271 | 273 | rdiscount |
| 272 | 274 | rspec-rails |
| 273 | 275 | ruby-debug19 | ... | ... |
app/helpers/commits_helper.rb
app/models/commit.rb
| 1 | 1 | class Commit |
| 2 | + include Utils::CharEncode | |
| 3 | + | |
| 2 | 4 | attr_accessor :commit |
| 3 | 5 | attr_accessor :head |
| 4 | 6 | |
| ... | ... | @@ -20,7 +22,7 @@ class Commit |
| 20 | 22 | end |
| 21 | 23 | |
| 22 | 24 | def safe_message |
| 23 | - message.force_encoding(Encoding::UTF_8) | |
| 25 | + encode(message) | |
| 24 | 26 | end |
| 25 | 27 | |
| 26 | 28 | def created_at |
| ... | ... | @@ -28,10 +30,10 @@ class Commit |
| 28 | 30 | end |
| 29 | 31 | |
| 30 | 32 | def author_email |
| 31 | - author.email.force_encoding(Encoding::UTF_8) | |
| 33 | + encode(author.email) | |
| 32 | 34 | end |
| 33 | 35 | |
| 34 | 36 | def author_name |
| 35 | - author.name.force_encoding(Encoding::UTF_8) | |
| 37 | + encode(author.name) | |
| 36 | 38 | end |
| 37 | 39 | end | ... | ... |
app/views/commits/_text_file.html.haml
| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | - line_new = 0 |
| 3 | 3 | - lines_arr = diff.diff.lines.to_a |
| 4 | 4 | - lines_arr.each do |line| |
| 5 | - - line.force_encoding(Encoding::UTF_8) | |
| 5 | + - encode(line) | |
| 6 | 6 | - next if line.match(/^--- \/dev\/null/) |
| 7 | 7 | - next if line.match(/^--- a/) |
| 8 | 8 | - next if line.match(/^\+\+\+ b/) | ... | ... |
lib/graph_commit.rb
| 1 | 1 | require "grit" |
| 2 | 2 | |
| 3 | 3 | class GraphCommit |
| 4 | + include Utils::CharEncode | |
| 4 | 5 | attr_accessor :time, :space |
| 5 | 6 | attr_accessor :refs |
| 6 | 7 | |
| ... | ... | @@ -65,7 +66,7 @@ class GraphCommit |
| 65 | 66 | # @param [GraphCommit] the commit object. |
| 66 | 67 | # @param [Hash<String,GraphCommit>] map of commits |
| 67 | 68 | # |
| 68 | - # @return [Fixnum] max space used. | |
| 69 | + # @return [Fixnum] max space used. | |
| 69 | 70 | def self.mark_chain(mark, commit, map) |
| 70 | 71 | commit.space = mark if commit.space == 0 |
| 71 | 72 | m1 = mark - 1 |
| ... | ... | @@ -96,13 +97,13 @@ class GraphCommit |
| 96 | 97 | h[:parents] = self.parents.collect do |p| |
| 97 | 98 | [p.id,0,0] |
| 98 | 99 | end |
| 99 | - h[:author] = author.name.force_encoding("UTF-8") | |
| 100 | + h[:author] = encode(author.name) | |
| 100 | 101 | h[:time] = time |
| 101 | 102 | h[:space] = space |
| 102 | 103 | h[:refs] = refs.collect{|r|r.name}.join(" ") unless refs.nil? |
| 103 | 104 | h[:id] = sha |
| 104 | 105 | h[:date] = date |
| 105 | - h[:message] = message.force_encoding("UTF-8") | |
| 106 | + h[:message] = encode(message) | |
| 106 | 107 | h[:login] = author.email |
| 107 | 108 | h |
| 108 | 109 | end | ... | ... |
lib/utils.rb
| ... | ... | @@ -16,9 +16,20 @@ module Utils |
| 16 | 16 | end |
| 17 | 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 | 29 | module Colorize |
| 30 | + include CharEncode | |
| 20 | 31 | def colorize |
| 21 | - system_colorize(data, name) | |
| 32 | + system_colorize(encode(data), name) | |
| 22 | 33 | end |
| 23 | 34 | |
| 24 | 35 | def system_colorize(data, file_name) | ... | ... |