Commit b7558a2063a35778e226156ff7b5ab41d83be753
1 parent
52f6df72
Exists in
master
and in
4 other branches
Removed encoding monkey patch
Showing
6 changed files
with
43 additions
and
42 deletions
Show diff stats
app/helpers/application_helper.rb
app/models/commit.rb
| 1 | 1 | class Commit |
| 2 | 2 | include ActiveModel::Conversion |
| 3 | + include Gitlabhq::Encode | |
| 3 | 4 | extend ActiveModel::Naming |
| 4 | 5 | |
| 5 | 6 | attr_accessor :commit |
| ... | ... | @@ -90,7 +91,7 @@ class Commit |
| 90 | 91 | end |
| 91 | 92 | |
| 92 | 93 | def safe_message |
| 93 | - message | |
| 94 | + utf8 message | |
| 94 | 95 | end |
| 95 | 96 | |
| 96 | 97 | def created_at |
| ... | ... | @@ -102,11 +103,11 @@ class Commit |
| 102 | 103 | end |
| 103 | 104 | |
| 104 | 105 | def author_name |
| 105 | - author.name.force_encoding("UTF-8") | |
| 106 | + utf8 author.name | |
| 106 | 107 | end |
| 107 | 108 | |
| 108 | 109 | def committer_name |
| 109 | - committer.name | |
| 110 | + utf8 committer.name | |
| 110 | 111 | end |
| 111 | 112 | |
| 112 | 113 | def committer_email | ... | ... |
app/views/commits/_diff_head.html.haml
| ... | ... | @@ -3,24 +3,24 @@ |
| 3 | 3 | %li |
| 4 | 4 | - if diff.deleted_file |
| 5 | 5 | %span.removed_file |
| 6 | - %a{:href => "##{diff.a_path}"} | |
| 7 | - = diff.a_path | |
| 6 | + %a{:href => "##{diff.old_path}"} | |
| 7 | + = diff.old_path | |
| 8 | 8 | = image_tag "diff_file_delete.png" |
| 9 | 9 | - elsif diff.renamed_file |
| 10 | 10 | %span.moved_file |
| 11 | - %a{:href => "##{diff.b_path}"} | |
| 12 | - = diff.a_path | |
| 11 | + %a{:href => "##{diff.new_path}"} | |
| 12 | + = diff.old_path | |
| 13 | 13 | = "->" |
| 14 | - = diff.b_path | |
| 14 | + = diff.new_path | |
| 15 | 15 | = image_tag "diff_file_notice.png" |
| 16 | 16 | - elsif diff.new_file |
| 17 | 17 | %span.new_file |
| 18 | - %a{:href => "##{diff.b_path}"} | |
| 19 | - = diff.b_path | |
| 18 | + %a{:href => "##{diff.new_path}"} | |
| 19 | + = diff.new_path | |
| 20 | 20 | = image_tag "diff_file_add.png" |
| 21 | 21 | - else |
| 22 | 22 | %span.edit_file |
| 23 | - %a{:href => "##{diff.b_path}"} | |
| 24 | - = diff.b_path | |
| 23 | + %a{:href => "##{diff.new_path}"} | |
| 24 | + = diff.new_path | |
| 25 | 25 | = image_tag "diff_file_info.png" |
| 26 | 26 | ... | ... |
app/views/commits/_diffs.html.haml
| ... | ... | @@ -17,16 +17,16 @@ |
| 17 | 17 | - unless @suppress_diff |
| 18 | 18 | - diffs.each_with_index do |diff, i| |
| 19 | 19 | - next if diff.diff.empty? |
| 20 | - - file = (@commit.tree / diff.b_path) | |
| 21 | - - file = (@commit.prev_commit.tree / diff.a_path) unless file | |
| 20 | + - file = (@commit.tree / diff.new_path) | |
| 21 | + - file = (@commit.prev_commit.tree / diff.old_path) unless file | |
| 22 | 22 | - next unless file |
| 23 | 23 | .diff_file |
| 24 | 24 | .diff_file_header |
| 25 | 25 | - if diff.deleted_file |
| 26 | - %strong{:id => "#{diff.a_path}"}= diff.a_path | |
| 26 | + %strong{:id => "#{diff.old_path}"}= diff.old_path | |
| 27 | 27 | - else |
| 28 | - = link_to tree_file_project_ref_path(@project, @commit.id, diff.b_path) do | |
| 29 | - %strong{:id => "#{diff.b_path}"}= diff.b_path | |
| 28 | + = link_to tree_file_project_ref_path(@project, @commit.id, diff.new_path) do | |
| 29 | + %strong{:id => "#{diff.new_path}"}= diff.new_path | |
| 30 | 30 | %br/ |
| 31 | 31 | .diff_file_content |
| 32 | 32 | - if file.text? | ... | ... |
config/initializers/gitlabhq/20_grit_ext.rb
| ... | ... | @@ -10,38 +10,20 @@ end |
| 10 | 10 | #monkey patch raw_object from string |
| 11 | 11 | Grit::GitRuby::Internal::RawObject.class_eval do |
| 12 | 12 | def content |
| 13 | - transcoding(@content) | |
| 14 | - rescue Exception => ex | |
| 15 | - Rails.logger.error ex.message | |
| 16 | 13 | @content |
| 17 | 14 | end |
| 15 | +end | |
| 18 | 16 | |
| 19 | - private | |
| 20 | - | |
| 21 | - def transcoding(content) | |
| 22 | - content ||= "" | |
| 23 | - hash = CharlockHolmes::EncodingDetector.detect(content) | |
| 24 | - | |
| 25 | - if hash | |
| 26 | - return content if hash[:type] == :binary | |
| 27 | - | |
| 28 | - if hash[:encoding] == "UTF-8" | |
| 29 | - content = if hash[:confidence] < 100 | |
| 30 | - content | |
| 31 | - else | |
| 32 | - content.force_encoding("UTF-8") | |
| 33 | - end | |
| 34 | 17 | |
| 35 | - return content | |
| 36 | - end | |
| 18 | +Grit::Diff.class_eval do | |
| 19 | + def old_path | |
| 20 | + Gitlabhq::Encode.utf8 a_path | |
| 21 | + end | |
| 37 | 22 | |
| 38 | - CharlockHolmes::Converter.convert(content, hash[:encoding], 'UTF-8') if hash[:encoding] | |
| 39 | - else | |
| 40 | - content.force_encoding("UTF-8") | |
| 41 | - end | |
| 23 | + def new_path | |
| 24 | + Gitlabhq::Encode.utf8 b_path | |
| 42 | 25 | end |
| 43 | 26 | end |
| 44 | 27 | |
| 45 | - | |
| 46 | 28 | Grit::Git.git_timeout = GIT_OPTS["git_timeout"] |
| 47 | 29 | Grit::Git.git_max_size = GIT_OPTS["git_max_size"] | ... | ... |
| ... | ... | @@ -0,0 +1,14 @@ |
| 1 | +module Gitlabhq | |
| 2 | + module Encode | |
| 3 | + extend self | |
| 4 | + | |
| 5 | + def utf8 message | |
| 6 | + hash = CharlockHolmes::EncodingDetector.detect(message) | |
| 7 | + if hash[:encoding] | |
| 8 | + CharlockHolmes::Converter.convert(message, hash[:encoding], 'UTF-8') | |
| 9 | + else | |
| 10 | + message | |
| 11 | + end.force_encoding("utf-8") | |
| 12 | + end | |
| 13 | + end | |
| 14 | +end | ... | ... |