diff --git a/app/models/change.rb b/app/models/change.rb index 652fde7d9ada1386ac0b24d4865e83bbcdbfbc19..d6d53f1ea04288f5d894142d97c62820f4d187dd 100644 --- a/app/models/change.rb +++ b/app/models/change.rb @@ -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 diff --git a/app/models/changeset.rb b/app/models/changeset.rb index 623ee41f34ff832aa61f6b8debf5c16da4a8fcb0..68b9d5e71ceb82f663df1559fac44cb09e5505e3 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -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)