Commit 7528b534c6dcb9124a1045f50eb94ce6dae3f1a7
Exists in
master
and in
4 other branches
Merge pull request #1956 from SaitoWu/grit_ext
release a new version of grit_ext, added it into Gitlab.
Showing
12 changed files
with
21 additions
and
78 deletions
Show diff stats
Gemfile
| ... | ... | @@ -27,6 +27,7 @@ gem "grit", git: "https://github.com/gitlabhq/grit.git", ref: |
| 27 | 27 | gem "omniauth-ldap", git: "https://github.com/gitlabhq/omniauth-ldap.git", ref: 'f038dd852d7bd473a557e385d5d7c2fd5dc1dc2e' |
| 28 | 28 | gem 'yaml_db', git: "https://github.com/gitlabhq/yaml_db.git", ref: '98e9a5dca43e3fedd3268c76a73af40d1bdf1dfd' |
| 29 | 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 | 32 | # Gitolite client (for work with gitolite-admin repo) |
| 32 | 33 | gem "gitolite", '1.1.0' |
| ... | ... | @@ -83,9 +84,6 @@ gem 'resque_mailer' |
| 83 | 84 | # HTTP requests |
| 84 | 85 | gem "httparty" |
| 85 | 86 | |
| 86 | -# Handle encodings | |
| 87 | -gem "charlock_holmes" | |
| 88 | - | |
| 89 | 87 | # Colored output to console |
| 90 | 88 | gem "colored" |
| 91 | 89 | ... | ... |
Gemfile.lock
| 1 | 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 | 10 | remote: https://github.com/ctran/annotate_models.git |
| 3 | 11 | revision: 18cd39ad01829deba5aa34634b8540d6675ab978 |
| 4 | 12 | specs: |
| ... | ... | @@ -92,7 +100,7 @@ GEM |
| 92 | 100 | carrierwave (0.6.2) |
| 93 | 101 | activemodel (>= 3.2.0) |
| 94 | 102 | activesupport (>= 3.2.0) |
| 95 | - charlock_holmes (0.6.8) | |
| 103 | + charlock_holmes (0.6.9) | |
| 96 | 104 | childprocess (0.3.2) |
| 97 | 105 | ffi (~> 1.0.6) |
| 98 | 106 | chosen-rails (0.9.8.3) |
| ... | ... | @@ -415,7 +423,6 @@ DEPENDENCIES |
| 415 | 423 | capybara |
| 416 | 424 | capybara-webkit |
| 417 | 425 | carrierwave |
| 418 | - charlock_holmes | |
| 419 | 426 | chosen-rails |
| 420 | 427 | coffee-rails (= 3.2.2) |
| 421 | 428 | colored |
| ... | ... | @@ -436,6 +443,7 @@ DEPENDENCIES |
| 436 | 443 | grack! |
| 437 | 444 | grape (~> 0.2.1) |
| 438 | 445 | grit! |
| 446 | + grit_ext! | |
| 439 | 447 | growl |
| 440 | 448 | guard-rspec |
| 441 | 449 | guard-spinach | ... | ... |
app/controllers/blob_controller.rb
app/controllers/refs_controller.rb
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
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
app/views/tree/edit.html.haml
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 | ... | ... |