From 98b5c3647bae81fcc010a6f95dc557b7ea6135f6 Mon Sep 17 00:00:00 2001 From: Saito Date: Fri, 30 Dec 2011 22:26:13 +0800 Subject: [PATCH] use monkey patch to trancoding content --- config/initializers/gitlabhq/20_grit_ext.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/config/initializers/gitlabhq/20_grit_ext.rb b/config/initializers/gitlabhq/20_grit_ext.rb index 35684453..d9f2c001 100644 --- a/config/initializers/gitlabhq/20_grit_ext.rb +++ b/config/initializers/gitlabhq/20_grit_ext.rb @@ -7,5 +7,23 @@ Grit::Blob.class_eval do include Utils::Colorize end +#monkey patch raw_object from string +Grit::GitRuby::Internal::RawObject.class_eval do + def content + transcoding(@content) + 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 + content + end +end + + Grit::Git.git_timeout = GIT_OPTS["git_timeout"] Grit::Git.git_max_size = GIT_OPTS["git_max_size"]