Commit f1ac2a616bedc2941bc7f67e2ac25e915da2ddb2

Authored by Saito
1 parent 96211b01

remove encode lib, clean all encoded area.

app/controllers/blob_controller.rb
1 1 # Controller for viewing a file's blame
2 2 class BlobController < ProjectResourceController
3 3 include ExtractsPath
4   - include Gitlab::Encode
5 4  
6 5 # Authorize
7 6 before_filter :authorize_read_project!
... ...
app/controllers/refs_controller.rb
1 1 class RefsController < ProjectResourceController
2   - include Gitlab::Encode
3 2  
4 3 # Authorize
5 4 before_filter :authorize_read_project!
... ...
app/models/commit.rb
1 1 class Commit
2 2 include ActiveModel::Conversion
3   - include Gitlab::Encode
4 3 include StaticModel
5 4 extend ActiveModel::Naming
6 5  
... ... @@ -112,7 +111,7 @@ class Commit
112 111 end
113 112  
114 113 def safe_message
115   - @safe_message ||= utf8 message
  114 + @safe_message ||= message
116 115 end
117 116  
118 117 def created_at
... ... @@ -124,7 +123,7 @@ class Commit
124 123 end
125 124  
126 125 def author_name
127   - utf8 author.name
  126 + author.name
128 127 end
129 128  
130 129 # Was this commit committed by a different person than the original author?
... ... @@ -133,7 +132,7 @@ class Commit
133 132 end
134 133  
135 134 def committer_name
136   - utf8 committer.name
  135 + committer.name
137 136 end
138 137  
139 138 def committer_email
... ...
app/models/tree.rb
... ... @@ -8,7 +8,7 @@ class Tree
8 8 def initialize(raw_tree, project, ref = nil, path = nil)
9 9 @project, @ref, @path = project, ref, path
10 10 @tree = if path.present?
11   - raw_tree / path.dup.force_encoding('ascii-8bit')
  11 + raw_tree / path
12 12 else
13 13 raw_tree
14 14 end
... ...
app/views/blame/show.html.haml
... ... @@ -15,7 +15,7 @@
15 15 .file_title
16 16 %i.icon-file
17 17 %span.file_name
18   - = @tree.name.force_encoding('utf-8')
  18 + = @tree.name
19 19 %small= number_to_human_size @tree.size
20 20 %span.options= render "tree/blob_actions"
21 21 .file_content.blame
... ... @@ -32,4 +32,4 @@
32 32 %td.lines
33 33 = preserve do
34 34 %pre
35   - = Gitlab::Encode.utf8 lines.join("\n")
  35 + = lines.join("\n")
... ...
app/views/tree/_blob.html.haml
... ... @@ -2,7 +2,7 @@
2 2 .file_title
3 3 %i.icon-file
4 4 %span.file_name
5   - = blob.name.force_encoding('utf-8')
  5 + = blob.name
6 6 %small= number_to_human_size blob.size
7 7 %span.options= render "tree/blob_actions"
8 8 - if blob.text?
... ...
app/views/tree/edit.html.haml
... ... @@ -4,7 +4,7 @@
4 4 .file_title
5 5 %i.icon-file
6 6 %span.file_name
7   - = "#{@tree.path.force_encoding('utf-8')} (#{@ref})"
  7 + = "#{@tree.path} (#{@ref})"
8 8 .file_content.code
9 9 #editor= @tree.data
10 10  
... ...
config/initializers/3_grit_ext.rb
... ... @@ -6,23 +6,4 @@ Grit::Git.git_max_size = Gitlab.config.git_max_size
6 6  
7 7 Grit::Blob.class_eval do
8 8 include Linguist::BlobHelper
9   -
10   - def data
11   - @data ||= @repo.git.cat_file({:p => true}, id)
12   - Gitlab::Encode.utf8 @data
13   - end
14   -end
15   -
16   -Grit::Diff.class_eval do
17   - def old_path
18   - Gitlab::Encode.utf8 @a_path
19   - end
20   -
21   - def new_path
22   - Gitlab::Encode.utf8 @b_path
23   - end
24   -
25   - def diff
26   - Gitlab::Encode.utf8 @diff
27   - end
28 9 end
... ...
lib/gitlab/encode.rb
... ... @@ -1,41 +0,0 @@
1   -# Patch Strings to enable detect_encoding! on views
2   -require 'charlock_holmes/string'
3   -module Gitlab
4   - module Encode
5   - extend self
6   -
7   - def utf8 message
8   - # return nil if message is nil
9   - return nil unless message
10   -
11   - message.force_encoding("utf-8")
12   - # return message if message type is binary
13   - detect = CharlockHolmes::EncodingDetector.detect(message)
14   - return message if detect[:type] == :binary
15   -
16   - # if message is utf-8 encoding, just return it
17   - return message if message.valid_encoding?
18   -
19   - # if message is not utf-8 encoding, convert it
20   - if detect[:encoding]
21   - message.force_encoding(detect[:encoding])
22   - message.encode!("utf-8", detect[:encoding], undef: :replace, replace: "", invalid: :replace)
23   - end
24   -
25   - # ensure message encoding is utf8
26   - message.valid_encoding? ? message : raise
27   -
28   - # Prevent app from crash cause of encoding errors
29   - rescue
30   - encoding = detect ? detect[:encoding] : "unknown"
31   - "--broken encoding: #{encoding}"
32   - end
33   -
34   - def detect_encoding message
35   - return nil unless message
36   -
37   - hash = CharlockHolmes::EncodingDetector.detect(message) rescue {}
38   - return hash[:encoding] ? hash[:encoding] : nil
39   - end
40   - end
41   -end
lib/gitlab/graph/commit.rb
... ... @@ -22,13 +22,13 @@ module Gitlab
22 22 h[:parents] = self.parents.collect do |p|
23 23 [p.id,0,0]
24 24 end
25   - h[:author] = Gitlab::Encode.utf8(author.name)
  25 + h[:author] = author.name
26 26 h[:time] = time
27 27 h[:space] = space
28 28 h[:refs] = refs.collect{|r|r.name}.join(" ") unless refs.nil?
29 29 h[:id] = sha
30 30 h[:date] = date
31   - h[:message] = escape_once(Gitlab::Encode.utf8(message))
  31 + h[:message] = escape_once(message)
32 32 h[:login] = author.email
33 33 h
34 34 end
... ...