diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0516338f..ca4555c2 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -129,4 +129,8 @@ module ApplicationHelper "ui_mars" end end + + def string_to_utf8 str + Gitlabhq::Encode.utf8 str + end end diff --git a/app/models/commit.rb b/app/models/commit.rb index 8e0681f0..76064b05 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -1,5 +1,6 @@ class Commit include ActiveModel::Conversion + include Gitlabhq::Encode extend ActiveModel::Naming attr_accessor :commit @@ -90,7 +91,7 @@ class Commit end def safe_message - message + utf8 message end def created_at @@ -102,11 +103,11 @@ class Commit end def author_name - author.name.force_encoding("UTF-8") + utf8 author.name end def committer_name - committer.name + utf8 committer.name end def committer_email diff --git a/app/views/commits/_diff_head.html.haml b/app/views/commits/_diff_head.html.haml index b7913160..11d6ca16 100644 --- a/app/views/commits/_diff_head.html.haml +++ b/app/views/commits/_diff_head.html.haml @@ -3,24 +3,24 @@ %li - if diff.deleted_file %span.removed_file - %a{:href => "##{diff.a_path}"} - = diff.a_path + %a{:href => "##{diff.old_path}"} + = diff.old_path = image_tag "diff_file_delete.png" - elsif diff.renamed_file %span.moved_file - %a{:href => "##{diff.b_path}"} - = diff.a_path + %a{:href => "##{diff.new_path}"} + = diff.old_path = "->" - = diff.b_path + = diff.new_path = image_tag "diff_file_notice.png" - elsif diff.new_file %span.new_file - %a{:href => "##{diff.b_path}"} - = diff.b_path + %a{:href => "##{diff.new_path}"} + = diff.new_path = image_tag "diff_file_add.png" - else %span.edit_file - %a{:href => "##{diff.b_path}"} - = diff.b_path + %a{:href => "##{diff.new_path}"} + = diff.new_path = image_tag "diff_file_info.png" diff --git a/app/views/commits/_diffs.html.haml b/app/views/commits/_diffs.html.haml index 96aed24c..63baaad5 100644 --- a/app/views/commits/_diffs.html.haml +++ b/app/views/commits/_diffs.html.haml @@ -17,16 +17,16 @@ - unless @suppress_diff - diffs.each_with_index do |diff, i| - next if diff.diff.empty? - - file = (@commit.tree / diff.b_path) - - file = (@commit.prev_commit.tree / diff.a_path) unless file + - file = (@commit.tree / diff.new_path) + - file = (@commit.prev_commit.tree / diff.old_path) unless file - next unless file .diff_file .diff_file_header - if diff.deleted_file - %strong{:id => "#{diff.a_path}"}= diff.a_path + %strong{:id => "#{diff.old_path}"}= diff.old_path - else - = link_to tree_file_project_ref_path(@project, @commit.id, diff.b_path) do - %strong{:id => "#{diff.b_path}"}= diff.b_path + = link_to tree_file_project_ref_path(@project, @commit.id, diff.new_path) do + %strong{:id => "#{diff.new_path}"}= diff.new_path %br/ .diff_file_content - if file.text? diff --git a/config/initializers/gitlabhq/20_grit_ext.rb b/config/initializers/gitlabhq/20_grit_ext.rb index 13ee77b7..50b57d5e 100644 --- a/config/initializers/gitlabhq/20_grit_ext.rb +++ b/config/initializers/gitlabhq/20_grit_ext.rb @@ -10,38 +10,20 @@ end #monkey patch raw_object from string Grit::GitRuby::Internal::RawObject.class_eval do def content - transcoding(@content) - rescue Exception => ex - Rails.logger.error ex.message @content end - - private - - def transcoding(content) - content ||= "" - hash = CharlockHolmes::EncodingDetector.detect(content) - - if hash - return content if hash[:type] == :binary - - if hash[:encoding] == "UTF-8" - content = if hash[:confidence] < 100 - content - else - content.force_encoding("UTF-8") - end - - return content - end - - CharlockHolmes::Converter.convert(content, hash[:encoding], 'UTF-8') if hash[:encoding] - else - content.force_encoding("UTF-8") - end - end end +Grit::Diff.class_eval do + def old_path + Gitlabhq::Encode.utf8 a_path + end + + def new_path + Gitlabhq::Encode.utf8 b_path + end +end + Grit::Git.git_timeout = GIT_OPTS["git_timeout"] Grit::Git.git_max_size = GIT_OPTS["git_max_size"] diff --git a/lib/gitlabhq/encode.rb b/lib/gitlabhq/encode.rb new file mode 100644 index 00000000..a493fb21 --- /dev/null +++ b/lib/gitlabhq/encode.rb @@ -0,0 +1,14 @@ +module Gitlabhq + module Encode + extend self + + def utf8 message + hash = CharlockHolmes::EncodingDetector.detect(message) + if hash[:encoding] + CharlockHolmes::Converter.convert(message, hash[:encoding], 'UTF-8') + else + message + end.force_encoding("utf-8") + end + end +end