Merge pull request #1956 from SaitoWu/grit_ext

release a new version of grit_ext, added it into Gitlab.
This commit is contained in:
Dmitriy Zaporozhets 2012-11-09 05:18:15 -08:00
commit 7528b534c6
12 changed files with 21 additions and 78 deletions

View file

@ -27,6 +27,7 @@ gem "grit", git: "https://github.com/gitlabhq/grit.git", ref:
gem "omniauth-ldap", git: "https://github.com/gitlabhq/omniauth-ldap.git", ref: 'f038dd852d7bd473a557e385d5d7c2fd5dc1dc2e' gem "omniauth-ldap", git: "https://github.com/gitlabhq/omniauth-ldap.git", ref: 'f038dd852d7bd473a557e385d5d7c2fd5dc1dc2e'
gem 'yaml_db', git: "https://github.com/gitlabhq/yaml_db.git", ref: '98e9a5dca43e3fedd3268c76a73af40d1bdf1dfd' gem 'yaml_db', git: "https://github.com/gitlabhq/yaml_db.git", ref: '98e9a5dca43e3fedd3268c76a73af40d1bdf1dfd'
gem 'grack', git: "https://github.com/gitlabhq/grack.git", ref: 'ba46f3b0845c6a09d488ae6abdce6ede37e227e8' gem 'grack', git: "https://github.com/gitlabhq/grack.git", ref: 'ba46f3b0845c6a09d488ae6abdce6ede37e227e8'
gem 'grit_ext', git: "https://github.com/SaitoWu/grit_ext.git", ref: '212fd40bea61f3c6a167223768e7295dc32bbc10'
# Gitolite client (for work with gitolite-admin repo) # Gitolite client (for work with gitolite-admin repo)
gem "gitolite", '1.1.0' gem "gitolite", '1.1.0'
@ -83,9 +84,6 @@ gem 'resque_mailer'
# HTTP requests # HTTP requests
gem "httparty" gem "httparty"
# Handle encodings
gem "charlock_holmes"
# Colored output to console # Colored output to console
gem "colored" gem "colored"

View file

@ -1,3 +1,11 @@
GIT
remote: https://github.com/SaitoWu/grit_ext.git
revision: 212fd40bea61f3c6a167223768e7295dc32bbc10
ref: 212fd40bea61f3c6a167223768e7295dc32bbc10
specs:
grit_ext (0.6.0)
charlock_holmes (~> 0.6.9)
GIT GIT
remote: https://github.com/ctran/annotate_models.git remote: https://github.com/ctran/annotate_models.git
revision: 18cd39ad01829deba5aa34634b8540d6675ab978 revision: 18cd39ad01829deba5aa34634b8540d6675ab978
@ -92,7 +100,7 @@ GEM
carrierwave (0.6.2) carrierwave (0.6.2)
activemodel (>= 3.2.0) activemodel (>= 3.2.0)
activesupport (>= 3.2.0) activesupport (>= 3.2.0)
charlock_holmes (0.6.8) charlock_holmes (0.6.9)
childprocess (0.3.2) childprocess (0.3.2)
ffi (~> 1.0.6) ffi (~> 1.0.6)
chosen-rails (0.9.8.3) chosen-rails (0.9.8.3)
@ -415,7 +423,6 @@ DEPENDENCIES
capybara capybara
capybara-webkit capybara-webkit
carrierwave carrierwave
charlock_holmes
chosen-rails chosen-rails
coffee-rails (= 3.2.2) coffee-rails (= 3.2.2)
colored colored
@ -436,6 +443,7 @@ DEPENDENCIES
grack! grack!
grape (~> 0.2.1) grape (~> 0.2.1)
grit! grit!
grit_ext!
growl growl
guard-rspec guard-rspec
guard-spinach guard-spinach

View file

@ -1,7 +1,6 @@
# Controller for viewing a file's blame # Controller for viewing a file's blame
class BlobController < ProjectResourceController class BlobController < ProjectResourceController
include ExtractsPath include ExtractsPath
include Gitlab::Encode
# Authorize # Authorize
before_filter :authorize_read_project! before_filter :authorize_read_project!

View file

@ -1,5 +1,4 @@
class RefsController < ProjectResourceController class RefsController < ProjectResourceController
include Gitlab::Encode
# Authorize # Authorize
before_filter :authorize_read_project! before_filter :authorize_read_project!

View file

@ -1,6 +1,5 @@
class Commit class Commit
include ActiveModel::Conversion include ActiveModel::Conversion
include Gitlab::Encode
include StaticModel include StaticModel
extend ActiveModel::Naming extend ActiveModel::Naming
@ -112,7 +111,7 @@ class Commit
end end
def safe_message def safe_message
@safe_message ||= utf8 message @safe_message ||= message
end end
def created_at def created_at
@ -124,7 +123,7 @@ class Commit
end end
def author_name def author_name
utf8 author.name author.name
end end
# Was this commit committed by a different person than the original author? # Was this commit committed by a different person than the original author?
@ -133,7 +132,7 @@ class Commit
end end
def committer_name def committer_name
utf8 committer.name committer.name
end end
def committer_email def committer_email

View file

@ -8,7 +8,7 @@ class Tree
def initialize(raw_tree, project, ref = nil, path = nil) def initialize(raw_tree, project, ref = nil, path = nil)
@project, @ref, @path = project, ref, path @project, @ref, @path = project, ref, path
@tree = if path.present? @tree = if path.present?
raw_tree / path.dup.force_encoding('ascii-8bit') raw_tree / path
else else
raw_tree raw_tree
end end

View file

@ -15,7 +15,7 @@
.file_title .file_title
%i.icon-file %i.icon-file
%span.file_name %span.file_name
= @tree.name.force_encoding('utf-8') = @tree.name
%small= number_to_human_size @tree.size %small= number_to_human_size @tree.size
%span.options= render "tree/blob_actions" %span.options= render "tree/blob_actions"
.file_content.blame .file_content.blame
@ -32,4 +32,4 @@
%td.lines %td.lines
= preserve do = preserve do
%pre %pre
= Gitlab::Encode.utf8 lines.join("\n") = lines.join("\n")

View file

@ -2,7 +2,7 @@
.file_title .file_title
%i.icon-file %i.icon-file
%span.file_name %span.file_name
= blob.name.force_encoding('utf-8') = blob.name
%small= number_to_human_size blob.size %small= number_to_human_size blob.size
%span.options= render "tree/blob_actions" %span.options= render "tree/blob_actions"
- if blob.text? - if blob.text?

View file

@ -4,7 +4,7 @@
.file_title .file_title
%i.icon-file %i.icon-file
%span.file_name %span.file_name
= "#{@tree.path.force_encoding('utf-8')} (#{@ref})" = "#{@tree.path} (#{@ref})"
.file_content.code .file_content.code
#editor= @tree.data #editor= @tree.data

View file

@ -6,23 +6,4 @@ Grit::Git.git_max_size = Gitlab.config.git_max_size
Grit::Blob.class_eval do Grit::Blob.class_eval do
include Linguist::BlobHelper include Linguist::BlobHelper
def data
@data ||= @repo.git.cat_file({:p => true}, id)
Gitlab::Encode.utf8 @data
end
end
Grit::Diff.class_eval do
def old_path
Gitlab::Encode.utf8 @a_path
end
def new_path
Gitlab::Encode.utf8 @b_path
end
def diff
Gitlab::Encode.utf8 @diff
end
end end

View file

@ -1,41 +0,0 @@
# Patch Strings to enable detect_encoding! on views
require 'charlock_holmes/string'
module Gitlab
module Encode
extend self
def utf8 message
# return nil if message is nil
return nil unless message
message.force_encoding("utf-8")
# return message if message type is binary
detect = CharlockHolmes::EncodingDetector.detect(message)
return message if detect[:type] == :binary
# if message is utf-8 encoding, just return it
return message if message.valid_encoding?
# if message is not utf-8 encoding, convert it
if detect[:encoding]
message.force_encoding(detect[:encoding])
message.encode!("utf-8", detect[:encoding], undef: :replace, replace: "", invalid: :replace)
end
# ensure message encoding is utf8
message.valid_encoding? ? message : raise
# Prevent app from crash cause of encoding errors
rescue
encoding = detect ? detect[:encoding] : "unknown"
"--broken encoding: #{encoding}"
end
def detect_encoding message
return nil unless message
hash = CharlockHolmes::EncodingDetector.detect(message) rescue {}
return hash[:encoding] ? hash[:encoding] : nil
end
end
end

View file

@ -22,13 +22,13 @@ module Gitlab
h[:parents] = self.parents.collect do |p| h[:parents] = self.parents.collect do |p|
[p.id,0,0] [p.id,0,0]
end end
h[:author] = Gitlab::Encode.utf8(author.name) h[:author] = author.name
h[:time] = time h[:time] = time
h[:space] = space h[:space] = space
h[:refs] = refs.collect{|r|r.name}.join(" ") unless refs.nil? h[:refs] = refs.collect{|r|r.name}.join(" ") unless refs.nil?
h[:id] = sha h[:id] = sha
h[:date] = date h[:date] = date
h[:message] = escape_once(Gitlab::Encode.utf8(message)) h[:message] = escape_once(message)
h[:login] = author.email h[:login] = author.email
h h
end end