Commit 7528b534c6dcb9124a1045f50eb94ce6dae3f1a7

Authored by Dmitriy Zaporozhets
2 parents fb663bd9 8fbac65d

Merge pull request #1956 from SaitoWu/grit_ext

release a new version of grit_ext, added it into Gitlab.
@@ -27,6 +27,7 @@ gem "grit", git: "https://github.com/gitlabhq/grit.git", ref: @@ -27,6 +27,7 @@ gem "grit", git: "https://github.com/gitlabhq/grit.git", ref:
27 gem "omniauth-ldap", git: "https://github.com/gitlabhq/omniauth-ldap.git", ref: 'f038dd852d7bd473a557e385d5d7c2fd5dc1dc2e' 27 gem "omniauth-ldap", git: "https://github.com/gitlabhq/omniauth-ldap.git", ref: 'f038dd852d7bd473a557e385d5d7c2fd5dc1dc2e'
28 gem 'yaml_db', git: "https://github.com/gitlabhq/yaml_db.git", ref: '98e9a5dca43e3fedd3268c76a73af40d1bdf1dfd' 28 gem 'yaml_db', git: "https://github.com/gitlabhq/yaml_db.git", ref: '98e9a5dca43e3fedd3268c76a73af40d1bdf1dfd'
29 gem 'grack', git: "https://github.com/gitlabhq/grack.git", ref: 'ba46f3b0845c6a09d488ae6abdce6ede37e227e8' 29 gem 'grack', git: "https://github.com/gitlabhq/grack.git", ref: 'ba46f3b0845c6a09d488ae6abdce6ede37e227e8'
  30 +gem 'grit_ext', git: "https://github.com/SaitoWu/grit_ext.git", ref: '212fd40bea61f3c6a167223768e7295dc32bbc10'
30 31
31 # Gitolite client (for work with gitolite-admin repo) 32 # Gitolite client (for work with gitolite-admin repo)
32 gem "gitolite", '1.1.0' 33 gem "gitolite", '1.1.0'
@@ -83,9 +84,6 @@ gem 'resque_mailer' @@ -83,9 +84,6 @@ gem 'resque_mailer'
83 # HTTP requests 84 # HTTP requests
84 gem "httparty" 85 gem "httparty"
85 86
86 -# Handle encodings  
87 -gem "charlock_holmes"  
88 -  
89 # Colored output to console 87 # Colored output to console
90 gem "colored" 88 gem "colored"
91 89
1 GIT 1 GIT
  2 + remote: https://github.com/SaitoWu/grit_ext.git
  3 + revision: 212fd40bea61f3c6a167223768e7295dc32bbc10
  4 + ref: 212fd40bea61f3c6a167223768e7295dc32bbc10
  5 + specs:
  6 + grit_ext (0.6.0)
  7 + charlock_holmes (~> 0.6.9)
  8 +
  9 +GIT
2 remote: https://github.com/ctran/annotate_models.git 10 remote: https://github.com/ctran/annotate_models.git
3 revision: 18cd39ad01829deba5aa34634b8540d6675ab978 11 revision: 18cd39ad01829deba5aa34634b8540d6675ab978
4 specs: 12 specs:
@@ -92,7 +100,7 @@ GEM @@ -92,7 +100,7 @@ GEM
92 carrierwave (0.6.2) 100 carrierwave (0.6.2)
93 activemodel (>= 3.2.0) 101 activemodel (>= 3.2.0)
94 activesupport (>= 3.2.0) 102 activesupport (>= 3.2.0)
95 - charlock_holmes (0.6.8) 103 + charlock_holmes (0.6.9)
96 childprocess (0.3.2) 104 childprocess (0.3.2)
97 ffi (~> 1.0.6) 105 ffi (~> 1.0.6)
98 chosen-rails (0.9.8.3) 106 chosen-rails (0.9.8.3)
@@ -415,7 +423,6 @@ DEPENDENCIES @@ -415,7 +423,6 @@ DEPENDENCIES
415 capybara 423 capybara
416 capybara-webkit 424 capybara-webkit
417 carrierwave 425 carrierwave
418 - charlock_holmes  
419 chosen-rails 426 chosen-rails
420 coffee-rails (= 3.2.2) 427 coffee-rails (= 3.2.2)
421 colored 428 colored
@@ -436,6 +443,7 @@ DEPENDENCIES @@ -436,6 +443,7 @@ DEPENDENCIES
436 grack! 443 grack!
437 grape (~> 0.2.1) 444 grape (~> 0.2.1)
438 grit! 445 grit!
  446 + grit_ext!
439 growl 447 growl
440 guard-rspec 448 guard-rspec
441 guard-spinach 449 guard-spinach
app/controllers/blob_controller.rb
1 # Controller for viewing a file's blame 1 # Controller for viewing a file's blame
2 class BlobController < ProjectResourceController 2 class BlobController < ProjectResourceController
3 include ExtractsPath 3 include ExtractsPath
4 - include Gitlab::Encode  
5 4
6 # Authorize 5 # Authorize
7 before_filter :authorize_read_project! 6 before_filter :authorize_read_project!
app/controllers/refs_controller.rb
1 class RefsController < ProjectResourceController 1 class RefsController < ProjectResourceController
2 - include Gitlab::Encode  
3 2
4 # Authorize 3 # Authorize
5 before_filter :authorize_read_project! 4 before_filter :authorize_read_project!
app/models/commit.rb
1 class Commit 1 class Commit
2 include ActiveModel::Conversion 2 include ActiveModel::Conversion
3 - include Gitlab::Encode  
4 include StaticModel 3 include StaticModel
5 extend ActiveModel::Naming 4 extend ActiveModel::Naming
6 5
@@ -112,7 +111,7 @@ class Commit @@ -112,7 +111,7 @@ class Commit
112 end 111 end
113 112
114 def safe_message 113 def safe_message
115 - @safe_message ||= utf8 message 114 + @safe_message ||= message
116 end 115 end
117 116
118 def created_at 117 def created_at
@@ -124,7 +123,7 @@ class Commit @@ -124,7 +123,7 @@ class Commit
124 end 123 end
125 124
126 def author_name 125 def author_name
127 - utf8 author.name 126 + author.name
128 end 127 end
129 128
130 # Was this commit committed by a different person than the original author? 129 # Was this commit committed by a different person than the original author?
@@ -133,7 +132,7 @@ class Commit @@ -133,7 +132,7 @@ class Commit
133 end 132 end
134 133
135 def committer_name 134 def committer_name
136 - utf8 committer.name 135 + committer.name
137 end 136 end
138 137
139 def committer_email 138 def committer_email
app/models/tree.rb
@@ -8,7 +8,7 @@ class Tree @@ -8,7 +8,7 @@ class Tree
8 def initialize(raw_tree, project, ref = nil, path = nil) 8 def initialize(raw_tree, project, ref = nil, path = nil)
9 @project, @ref, @path = project, ref, path 9 @project, @ref, @path = project, ref, path
10 @tree = if path.present? 10 @tree = if path.present?
11 - raw_tree / path.dup.force_encoding('ascii-8bit') 11 + raw_tree / path
12 else 12 else
13 raw_tree 13 raw_tree
14 end 14 end
app/views/blame/show.html.haml
@@ -15,7 +15,7 @@ @@ -15,7 +15,7 @@
15 .file_title 15 .file_title
16 %i.icon-file 16 %i.icon-file
17 %span.file_name 17 %span.file_name
18 - = @tree.name.force_encoding('utf-8') 18 + = @tree.name
19 %small= number_to_human_size @tree.size 19 %small= number_to_human_size @tree.size
20 %span.options= render "tree/blob_actions" 20 %span.options= render "tree/blob_actions"
21 .file_content.blame 21 .file_content.blame
@@ -32,4 +32,4 @@ @@ -32,4 +32,4 @@
32 %td.lines 32 %td.lines
33 = preserve do 33 = preserve do
34 %pre 34 %pre
35 - = Gitlab::Encode.utf8 lines.join("\n") 35 + = lines.join("\n")
app/views/tree/_blob.html.haml
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 .file_title 2 .file_title
3 %i.icon-file 3 %i.icon-file
4 %span.file_name 4 %span.file_name
5 - = blob.name.force_encoding('utf-8') 5 + = blob.name
6 %small= number_to_human_size blob.size 6 %small= number_to_human_size blob.size
7 %span.options= render "tree/blob_actions" 7 %span.options= render "tree/blob_actions"
8 - if blob.text? 8 - if blob.text?
app/views/tree/edit.html.haml
@@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
4 .file_title 4 .file_title
5 %i.icon-file 5 %i.icon-file
6 %span.file_name 6 %span.file_name
7 - = "#{@tree.path.force_encoding('utf-8')} (#{@ref})" 7 + = "#{@tree.path} (#{@ref})"
8 .file_content.code 8 .file_content.code
9 #editor= @tree.data 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,23 +6,4 @@ Grit::Git.git_max_size = Gitlab.config.git_max_size
6 6
7 Grit::Blob.class_eval do 7 Grit::Blob.class_eval do
8 include Linguist::BlobHelper 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 end 9 end
lib/gitlab/encode.rb
@@ -1,41 +0,0 @@ @@ -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,13 +22,13 @@ module Gitlab
22 h[:parents] = self.parents.collect do |p| 22 h[:parents] = self.parents.collect do |p|
23 [p.id,0,0] 23 [p.id,0,0]
24 end 24 end
25 - h[:author] = Gitlab::Encode.utf8(author.name) 25 + h[:author] = author.name
26 h[:time] = time 26 h[:time] = time
27 h[:space] = space 27 h[:space] = space
28 h[:refs] = refs.collect{|r|r.name}.join(" ") unless refs.nil? 28 h[:refs] = refs.collect{|r|r.name}.join(" ") unless refs.nil?
29 h[:id] = sha 29 h[:id] = sha
30 h[:date] = date 30 h[:date] = date
31 - h[:message] = escape_once(Gitlab::Encode.utf8(message)) 31 + h[:message] = escape_once(message)
32 h[:login] = author.email 32 h[:login] = author.email
33 h 33 h
34 end 34 end