From f1ac2a616bedc2941bc7f67e2ac25e915da2ddb2 Mon Sep 17 00:00:00 2001 From: Saito Date: Fri, 9 Nov 2012 01:41:07 +0800 Subject: [PATCH] remove encode lib, clean all encoded area. --- app/controllers/blob_controller.rb | 1 - app/controllers/refs_controller.rb | 1 - app/models/commit.rb | 7 +++-- app/models/tree.rb | 2 +- app/views/blame/show.html.haml | 4 +-- app/views/tree/_blob.html.haml | 2 +- app/views/tree/edit.html.haml | 2 +- config/initializers/3_grit_ext.rb | 19 -------------- lib/gitlab/encode.rb | 41 ------------------------------ lib/gitlab/graph/commit.rb | 4 +-- 10 files changed, 10 insertions(+), 73 deletions(-) delete mode 100644 lib/gitlab/encode.rb diff --git a/app/controllers/blob_controller.rb b/app/controllers/blob_controller.rb index 30069d19965..d68754d072a 100644 --- a/app/controllers/blob_controller.rb +++ b/app/controllers/blob_controller.rb @@ -1,7 +1,6 @@ # Controller for viewing a file's blame class BlobController < ProjectResourceController include ExtractsPath - include Gitlab::Encode # Authorize before_filter :authorize_read_project! diff --git a/app/controllers/refs_controller.rb b/app/controllers/refs_controller.rb index 977ccea7cd8..b48d5ec7027 100644 --- a/app/controllers/refs_controller.rb +++ b/app/controllers/refs_controller.rb @@ -1,5 +1,4 @@ class RefsController < ProjectResourceController - include Gitlab::Encode # Authorize before_filter :authorize_read_project! diff --git a/app/models/commit.rb b/app/models/commit.rb index e6a87dd9217..5efb20cea3b 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -1,6 +1,5 @@ class Commit include ActiveModel::Conversion - include Gitlab::Encode include StaticModel extend ActiveModel::Naming @@ -112,7 +111,7 @@ class Commit end def safe_message - @safe_message ||= utf8 message + @safe_message ||= message end def created_at @@ -124,7 +123,7 @@ class Commit end def author_name - utf8 author.name + author.name end # Was this commit committed by a different person than the original author? @@ -133,7 +132,7 @@ class Commit end def committer_name - utf8 committer.name + committer.name end def committer_email diff --git a/app/models/tree.rb b/app/models/tree.rb index e4297a71a52..c3dfd4c718c 100644 --- a/app/models/tree.rb +++ b/app/models/tree.rb @@ -8,7 +8,7 @@ class Tree def initialize(raw_tree, project, ref = nil, path = nil) @project, @ref, @path = project, ref, path @tree = if path.present? - raw_tree / path.dup.force_encoding('ascii-8bit') + raw_tree / path else raw_tree end diff --git a/app/views/blame/show.html.haml b/app/views/blame/show.html.haml index 29fac7a4880..c5192c53cc3 100644 --- a/app/views/blame/show.html.haml +++ b/app/views/blame/show.html.haml @@ -15,7 +15,7 @@ .file_title %i.icon-file %span.file_name - = @tree.name.force_encoding('utf-8') + = @tree.name %small= number_to_human_size @tree.size %span.options= render "tree/blob_actions" .file_content.blame @@ -32,4 +32,4 @@ %td.lines = preserve do %pre - = Gitlab::Encode.utf8 lines.join("\n") + = lines.join("\n") diff --git a/app/views/tree/_blob.html.haml b/app/views/tree/_blob.html.haml index 9ede3f8eb20..ebf1ee2c678 100644 --- a/app/views/tree/_blob.html.haml +++ b/app/views/tree/_blob.html.haml @@ -2,7 +2,7 @@ .file_title %i.icon-file %span.file_name - = blob.name.force_encoding('utf-8') + = blob.name %small= number_to_human_size blob.size %span.options= render "tree/blob_actions" - if blob.text? diff --git a/app/views/tree/edit.html.haml b/app/views/tree/edit.html.haml index fdd334a3abe..a14a15b03ca 100644 --- a/app/views/tree/edit.html.haml +++ b/app/views/tree/edit.html.haml @@ -4,7 +4,7 @@ .file_title %i.icon-file %span.file_name - = "#{@tree.path.force_encoding('utf-8')} (#{@ref})" + = "#{@tree.path} (#{@ref})" .file_content.code #editor= @tree.data diff --git a/config/initializers/3_grit_ext.rb b/config/initializers/3_grit_ext.rb index fd7e288a2ba..d114ea6cc8b 100644 --- a/config/initializers/3_grit_ext.rb +++ b/config/initializers/3_grit_ext.rb @@ -6,23 +6,4 @@ Grit::Git.git_max_size = Gitlab.config.git_max_size Grit::Blob.class_eval do include Linguist::BlobHelper - - def data - @data ||= @repo.git.cat_file({:p => true}, id) - Gitlab::Encode.utf8 @data - end -end - -Grit::Diff.class_eval do - def old_path - Gitlab::Encode.utf8 @a_path - end - - def new_path - Gitlab::Encode.utf8 @b_path - end - - def diff - Gitlab::Encode.utf8 @diff - end end diff --git a/lib/gitlab/encode.rb b/lib/gitlab/encode.rb deleted file mode 100644 index 7e37442ea32..00000000000 --- a/lib/gitlab/encode.rb +++ /dev/null @@ -1,41 +0,0 @@ -# Patch Strings to enable detect_encoding! on views -require 'charlock_holmes/string' -module Gitlab - module Encode - extend self - - def utf8 message - # return nil if message is nil - return nil unless message - - message.force_encoding("utf-8") - # return message if message type is binary - detect = CharlockHolmes::EncodingDetector.detect(message) - return message if detect[:type] == :binary - - # if message is utf-8 encoding, just return it - return message if message.valid_encoding? - - # if message is not utf-8 encoding, convert it - if detect[:encoding] - message.force_encoding(detect[:encoding]) - message.encode!("utf-8", detect[:encoding], undef: :replace, replace: "", invalid: :replace) - end - - # ensure message encoding is utf8 - message.valid_encoding? ? message : raise - - # Prevent app from crash cause of encoding errors - rescue - encoding = detect ? detect[:encoding] : "unknown" - "--broken encoding: #{encoding}" - end - - def detect_encoding message - return nil unless message - - hash = CharlockHolmes::EncodingDetector.detect(message) rescue {} - return hash[:encoding] ? hash[:encoding] : nil - end - end -end diff --git a/lib/gitlab/graph/commit.rb b/lib/gitlab/graph/commit.rb index e26dd4a6ab4..af8d7828ce9 100644 --- a/lib/gitlab/graph/commit.rb +++ b/lib/gitlab/graph/commit.rb @@ -22,13 +22,13 @@ module Gitlab h[:parents] = self.parents.collect do |p| [p.id,0,0] end - h[:author] = Gitlab::Encode.utf8(author.name) + h[:author] = author.name h[:time] = time h[:space] = space h[:refs] = refs.collect{|r|r.name}.join(" ") unless refs.nil? h[:id] = sha h[:date] = date - h[:message] = escape_once(Gitlab::Encode.utf8(message)) + h[:message] = escape_once(message) h[:login] = author.email h end