Better encoding handling. Updated grit

This commit is contained in:
Dmitriy Zaporozhets 2012-04-05 01:51:49 +03:00
parent 3706a9744d
commit 80ddd2c09d
3 changed files with 29 additions and 6 deletions

View file

@ -14,7 +14,7 @@ GIT
GIT
remote: https://github.com/gitlabhq/grit.git
revision: ff015074ef35bd94cba943f9c0f98e161ab5851c
revision: 3fc864f3c637e06e2fa7a81f6b48a5df58a9bc5b
specs:
grit (2.4.1)
diff-lcs (~> 1.1)
@ -148,7 +148,7 @@ GEM
mime-types (~> 1.16)
treetop (~> 1.4.8)
method_source (0.7.0)
mime-types (1.17.2)
mime-types (1.18)
modularity (0.6.1)
multi_json (1.0.4)
multi_xml (0.4.1)

View file

@ -1,3 +1,4 @@
require 'benchmark'
require "base64"
class CommitsController < ApplicationController

View file

@ -17,13 +17,35 @@ Grit::GitRuby::Internal::RawObject.class_eval do
end
private
def transcoding(content)
content ||= ""
detection = CharlockHolmes::EncodingDetector.detect(content)
if hash = detection
content = CharlockHolmes::Converter.convert(content, hash[:encoding], 'UTF-8') if hash[:encoding]
end
hash = CharlockHolmes::EncodingDetector.detect(content)
if hash
return content if hash[:type] == :binary
if hash[:encoding] == "UTF-8"
content = if hash[:confidence] < 100
content
else
content.force_encoding("UTF-8")
end
return content
end
CharlockHolmes::Converter.convert(content, hash[:encoding], 'UTF-8') if hash[:encoding]
else
content.force_encoding("UTF-8")
end
end
def z_binary?(string)
string.each_byte do |x|
x.nonzero? or return true
end
false
end
end