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 | class Commit | 1 | class Commit |
2 | include ActiveModel::Conversion | 2 | include ActiveModel::Conversion |
3 | + include Gitlabhq::Encode | ||
3 | extend ActiveModel::Naming | 4 | extend ActiveModel::Naming |
4 | 5 | ||
5 | attr_accessor :commit | 6 | attr_accessor :commit |
@@ -90,7 +91,7 @@ class Commit | @@ -90,7 +91,7 @@ class Commit | ||
90 | end | 91 | end |
91 | 92 | ||
92 | def safe_message | 93 | def safe_message |
93 | - message | 94 | + utf8 message |
94 | end | 95 | end |
95 | 96 | ||
96 | def created_at | 97 | def created_at |
@@ -102,11 +103,11 @@ class Commit | @@ -102,11 +103,11 @@ class Commit | ||
102 | end | 103 | end |
103 | 104 | ||
104 | def author_name | 105 | def author_name |
105 | - author.name.force_encoding("UTF-8") | 106 | + utf8 author.name |
106 | end | 107 | end |
107 | 108 | ||
108 | def committer_name | 109 | def committer_name |
109 | - committer.name | 110 | + utf8 committer.name |
110 | end | 111 | end |
111 | 112 | ||
112 | def committer_email | 113 | def committer_email |
app/views/commits/_diff_head.html.haml
@@ -3,24 +3,24 @@ | @@ -3,24 +3,24 @@ | ||
3 | %li | 3 | %li |
4 | - if diff.deleted_file | 4 | - if diff.deleted_file |
5 | %span.removed_file | 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 | = image_tag "diff_file_delete.png" | 8 | = image_tag "diff_file_delete.png" |
9 | - elsif diff.renamed_file | 9 | - elsif diff.renamed_file |
10 | %span.moved_file | 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 | = image_tag "diff_file_notice.png" | 15 | = image_tag "diff_file_notice.png" |
16 | - elsif diff.new_file | 16 | - elsif diff.new_file |
17 | %span.new_file | 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 | = image_tag "diff_file_add.png" | 20 | = image_tag "diff_file_add.png" |
21 | - else | 21 | - else |
22 | %span.edit_file | 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 | = image_tag "diff_file_info.png" | 25 | = image_tag "diff_file_info.png" |
26 | 26 |
app/views/commits/_diffs.html.haml
@@ -17,16 +17,16 @@ | @@ -17,16 +17,16 @@ | ||
17 | - unless @suppress_diff | 17 | - unless @suppress_diff |
18 | - diffs.each_with_index do |diff, i| | 18 | - diffs.each_with_index do |diff, i| |
19 | - next if diff.diff.empty? | 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 | - next unless file | 22 | - next unless file |
23 | .diff_file | 23 | .diff_file |
24 | .diff_file_header | 24 | .diff_file_header |
25 | - if diff.deleted_file | 25 | - if diff.deleted_file |
26 | - %strong{:id => "#{diff.a_path}"}= diff.a_path | 26 | + %strong{:id => "#{diff.old_path}"}= diff.old_path |
27 | - else | 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 | %br/ | 30 | %br/ |
31 | .diff_file_content | 31 | .diff_file_content |
32 | - if file.text? | 32 | - if file.text? |
config/initializers/gitlabhq/20_grit_ext.rb
@@ -10,38 +10,20 @@ end | @@ -10,38 +10,20 @@ end | ||
10 | #monkey patch raw_object from string | 10 | #monkey patch raw_object from string |
11 | Grit::GitRuby::Internal::RawObject.class_eval do | 11 | Grit::GitRuby::Internal::RawObject.class_eval do |
12 | def content | 12 | def content |
13 | - transcoding(@content) | ||
14 | - rescue Exception => ex | ||
15 | - Rails.logger.error ex.message | ||
16 | @content | 13 | @content |
17 | end | 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 | end | 25 | end |
43 | end | 26 | end |
44 | 27 | ||
45 | - | ||
46 | Grit::Git.git_timeout = GIT_OPTS["git_timeout"] | 28 | Grit::Git.git_timeout = GIT_OPTS["git_timeout"] |
47 | Grit::Git.git_max_size = GIT_OPTS["git_max_size"] | 29 | Grit::Git.git_max_size = GIT_OPTS["git_max_size"] |
@@ -0,0 +1,14 @@ | @@ -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 |