Commit d34904b86c07f6a408bbd4496ea23a23f1208ec5

Authored by Dmitriy Zaporozhets
2 parents e33aab0b 31f3d6ef

Merge branch 'grit_ext'

  1 +before_install: sudo apt-get install libicu-dev -y
1 branches: 2 branches:
2 only: 3 only:
3 - 'master' 4 - 'master'
@@ -22,9 +22,9 @@ gem "acts_as_list" @@ -22,9 +22,9 @@ gem "acts_as_list"
22 gem "rdiscount" 22 gem "rdiscount"
23 gem "acts-as-taggable-on", "~> 2.1.0" 23 gem "acts-as-taggable-on", "~> 2.1.0"
24 gem "drapper" 24 gem "drapper"
25 -gem "rchardet19", "~> 1.3.5"  
26 gem "resque" 25 gem "resque"
27 gem "httparty" 26 gem "httparty"
  27 +gem "charlock_holmes"
28 28
29 group :assets do 29 group :assets do
30 gem "sass-rails", "~> 3.1.0" 30 gem "sass-rails", "~> 3.1.0"
@@ -77,6 +77,7 @@ GEM @@ -77,6 +77,7 @@ GEM
77 xpath (~> 0.1.4) 77 xpath (~> 0.1.4)
78 carrierwave (0.5.8) 78 carrierwave (0.5.8)
79 activesupport (~> 3.0) 79 activesupport (~> 3.0)
  80 + charlock_holmes (0.6.8)
80 childprocess (0.2.2) 81 childprocess (0.2.2)
81 ffi (~> 1.0.6) 82 ffi (~> 1.0.6)
82 coffee-rails (3.1.1) 83 coffee-rails (3.1.1)
@@ -172,7 +173,6 @@ GEM @@ -172,7 +173,6 @@ GEM
172 rdoc (~> 3.4) 173 rdoc (~> 3.4)
173 thor (~> 0.14.6) 174 thor (~> 0.14.6)
174 rake (0.9.2.2) 175 rake (0.9.2.2)
175 - rchardet19 (1.3.5)  
176 rdiscount (1.6.8) 176 rdiscount (1.6.8)
177 rdoc (3.11) 177 rdoc (3.11)
178 json (~> 1.4) 178 json (~> 1.4)
@@ -285,6 +285,7 @@ DEPENDENCIES @@ -285,6 +285,7 @@ DEPENDENCIES
285 awesome_print 285 awesome_print
286 capybara 286 capybara
287 carrierwave 287 carrierwave
  288 + charlock_holmes
288 coffee-rails (~> 3.1.0) 289 coffee-rails (~> 3.1.0)
289 database_cleaner 290 database_cleaner
290 devise (= 1.5.0) 291 devise (= 1.5.0)
@@ -302,7 +303,6 @@ DEPENDENCIES @@ -302,7 +303,6 @@ DEPENDENCIES
302 pygments.rb (= 0.2.3) 303 pygments.rb (= 0.2.3)
303 rails (= 3.1.1) 304 rails (= 3.1.1)
304 rails-footnotes (~> 3.7.5) 305 rails-footnotes (~> 3.7.5)
305 - rchardet19 (~> 1.3.5)  
306 rdiscount 306 rdiscount
307 resque 307 resque
308 rspec-rails 308 rspec-rails
app/helpers/application_helper.rb
1 require 'digest/md5' 1 require 'digest/md5'
2 module ApplicationHelper 2 module ApplicationHelper
3 - include Utils::CharEncode  
4 3
5 def gravatar_icon(user_email, size = 40) 4 def gravatar_icon(user_email, size = 40)
6 gravatar_host = request.ssl? ? "https://secure.gravatar.com" : "http://www.gravatar.com" 5 gravatar_host = request.ssl? ? "https://secure.gravatar.com" : "http://www.gravatar.com"
app/models/commit.rb
1 class Commit 1 class Commit
2 - include Utils::CharEncode  
3 2
4 attr_accessor :commit 3 attr_accessor :commit
5 attr_accessor :head 4 attr_accessor :head
@@ -22,7 +21,7 @@ class Commit @@ -22,7 +21,7 @@ class Commit
22 end 21 end
23 22
24 def safe_message 23 def safe_message
25 - encode(message) 24 + message
26 end 25 end
27 26
28 def created_at 27 def created_at
@@ -30,11 +29,11 @@ class Commit @@ -30,11 +29,11 @@ class Commit
30 end 29 end
31 30
32 def author_email 31 def author_email
33 - encode(author.email) 32 + author.email
34 end 33 end
35 34
36 def author_name 35 def author_name
37 - encode(author.name) 36 + author.name
38 end 37 end
39 38
40 def prev_commit 39 def prev_commit
app/views/commits/_text_file.html.haml
1 %table 1 %table
2 - line_old = 0 2 - line_old = 0
3 - line_new = 0 3 - line_new = 0
4 - - diff_str = encode(diff.diff) 4 + - diff_str = diff.diff
5 - lines_arr = diff_str.lines.to_a 5 - lines_arr = diff_str.lines.to_a
6 - lines_arr.each do |line| 6 - lines_arr.each do |line|
7 - next if line.match(/^--- \/dev\/null/) 7 - next if line.match(/^--- \/dev\/null/)
app/views/refs/_tree.html.haml
@@ -40,9 +40,9 @@ @@ -40,9 +40,9 @@
40 %h3= content.name 40 %h3= content.name
41 .readme 41 .readme
42 - if content.name =~ /\.(md|markdown)$/i 42 - if content.name =~ /\.(md|markdown)$/i
43 - = markdown(encode content.data) 43 + = markdown(content.data)
44 - else 44 - else
45 - = simple_format(encode content.data) 45 + = simple_format(content.data)
46 46
47 :javascript 47 :javascript
48 $(function(){ 48 $(function(){
config/initializers/gitlabhq/20_grit_ext.rb
@@ -7,5 +7,23 @@ Grit::Blob.class_eval do @@ -7,5 +7,23 @@ Grit::Blob.class_eval do
7 include Utils::Colorize 7 include Utils::Colorize
8 end 8 end
9 9
  10 +#monkey patch raw_object from string
  11 +Grit::GitRuby::Internal::RawObject.class_eval do
  12 + def content
  13 + transcoding(@content)
  14 + end
  15 +
  16 + private
  17 + def transcoding(content)
  18 + content ||= ""
  19 + detection = CharlockHolmes::EncodingDetector.detect(content)
  20 + if hash = detection
  21 + content = CharlockHolmes::Converter.convert(content, hash[:encoding], 'UTF-8') if hash[:encoding]
  22 + end
  23 + content
  24 + end
  25 +end
  26 +
  27 +
10 Grit::Git.git_timeout = GIT_OPTS["git_timeout"] 28 Grit::Git.git_timeout = GIT_OPTS["git_timeout"]
11 Grit::Git.git_max_size = GIT_OPTS["git_max_size"] 29 Grit::Git.git_max_size = GIT_OPTS["git_max_size"]
lib/graph_commit.rb
1 require "grit" 1 require "grit"
2 2
3 class GraphCommit 3 class GraphCommit
4 - include Utils::CharEncode  
5 attr_accessor :time, :space 4 attr_accessor :time, :space
6 attr_accessor :refs 5 attr_accessor :refs
7 6
@@ -97,13 +96,13 @@ class GraphCommit @@ -97,13 +96,13 @@ class GraphCommit
97 h[:parents] = self.parents.collect do |p| 96 h[:parents] = self.parents.collect do |p|
98 [p.id,0,0] 97 [p.id,0,0]
99 end 98 end
100 - h[:author] = encode(author.name) 99 + h[:author] = author.name
101 h[:time] = time 100 h[:time] = time
102 h[:space] = space 101 h[:space] = space
103 h[:refs] = refs.collect{|r|r.name}.join(" ") unless refs.nil? 102 h[:refs] = refs.collect{|r|r.name}.join(" ") unless refs.nil?
104 h[:id] = sha 103 h[:id] = sha
105 h[:date] = date 104 h[:date] = date
106 - h[:message] = encode(message) 105 + h[:message] = message
107 h[:login] = author.email 106 h[:login] = author.email
108 h 107 h
109 end 108 end
@@ -16,28 +16,14 @@ module Utils @@ -16,28 +16,14 @@ module Utils
16 end 16 end
17 end 17 end
18 18
19 - module CharEncode  
20 - def encode(string)  
21 - return '' unless string  
22 - cd = CharDet.detect(string)  
23 - if cd.confidence > 0.6  
24 - string.force_encoding(cd.encoding)  
25 - end  
26 - string.encode("utf-8", :undef => :replace, :replace => "?", :invalid => :replace)  
27 - rescue  
28 - "Invalid Encoding"  
29 - end  
30 - end  
31 -  
32 module Colorize 19 module Colorize
33 - include CharEncode  
34 def colorize 20 def colorize
35 system_colorize(data, name) 21 system_colorize(data, name)
36 end 22 end
37 23
38 def system_colorize(data, file_name) 24 def system_colorize(data, file_name)
39 ft = handle_file_type(file_name) 25 ft = handle_file_type(file_name)
40 - Pygments.highlight(encode(data), :lexer => ft, :options => { :encoding => 'utf-8', :linenos => 'True' }) 26 + Pygments.highlight(data, :lexer => ft, :options => { :encoding => 'utf-8', :linenos => 'True' })
41 end 27 end
42 28
43 def handle_file_type(file_name, mime_type = nil) 29 def handle_file_type(file_name, mime_type = nil)