From bbb4f63ae45d13c2336f807461089240cbd91b08 Mon Sep 17 00:00:00 2001
From: Eric Davis <edavis@littlestreamsoftware.com>
Date: Fri, 22 Jul 2011 10:41:34 -0700
Subject: [PATCH] Brute force fix for Change#path #from_path on Ruby 1.9.2

Some database adapters are returning strings unencoded correctly (sqlite3-ruby)
---
 app/models/change.rb    | 12 ++++++++++++
 app/models/changeset.rb | 10 ++++++++++
 2 files changed, 22 insertions(+)

diff --git a/app/models/change.rb b/app/models/change.rb
index 652fde7d9..d6d53f1ea 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 623ee41f3..68b9d5e71 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)
-- 
GitLab