Commit bbb4f63a authored by Eric Davis's avatar Eric Davis

Brute force fix for Change#path #from_path on Ruby 1.9.2

Some database adapters are returning strings unencoded correctly (sqlite3-ruby)
parent d2724ef8
......@@ -17,10 +17,22 @@ class Change < ActiveRecord::Base
validates_presence_of :changeset_id, :action, :path
before_save :init_path
delegate :repository_encoding, :to => :changeset, :allow_nil => true, :prefix => true
def relative_path
changeset.repository.relative_path(path)
end
def path
# TODO: shouldn't access Changeset#to_utf8 directly
self.path = Changeset.to_utf8(read_attribute(:path), changeset_repository_encoding)
end
def from_path
# TODO: shouldn't access Changeset#to_utf8 directly
self.path = Changeset.to_utf8(read_attribute(:from_path), changeset_repository_encoding)
end
def init_path
self.path ||= ""
end
......
......@@ -74,6 +74,15 @@ class Changeset < ActiveRecord::Base
user || committer.to_s.split('<').first
end
# Delegate to a Repository's log encoding
def repository_encoding
if repository.present?
repository.repo_log_encoding
else
nil
end
end
# Committer of the Changeset
#
# Attribute reader for committer that encodes the committer string to
......@@ -247,6 +256,7 @@ class Changeset < ActiveRecord::Base
private
# TODO: refactor to a standard helper method
def self.to_utf8(str, encoding)
return str if str.nil?
str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment