diff --git a/app/models/changeset.rb b/app/models/changeset.rb
index 0663af34..656c6754 100644
--- a/app/models/changeset.rb
+++ b/app/models/changeset.rb
@@ -15,6 +15,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+require 'iconv'
+
class Changeset < ActiveRecord::Base
belongs_to :repository
has_many :changes, :dependent => :delete_all
@@ -43,7 +45,7 @@ class Changeset < ActiveRecord::Base
end
def comments=(comment)
- write_attribute(:comments, comment.strip)
+ write_attribute(:comments, to_utf8(comment.to_s.strip))
end
def committed_on=(date)
@@ -131,4 +133,19 @@ class Changeset < ActiveRecord::Base
def next
@next ||= Changeset.find(:first, :conditions => ['id > ? AND repository_id = ?', self.id, self.repository_id], :order => 'id ASC')
end
+
+ private
+
+ def to_utf8(str)
+ return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii
+ encoding = Setting.commit_logs_encoding.to_s.strip
+ unless encoding.blank? || encoding == 'UTF-8'
+ begin
+ return Iconv.conv('UTF-8', encoding, str)
+ rescue Iconv::Failure
+ # do nothing here
+ end
+ end
+ str
+ end
end
diff --git a/app/models/setting.rb b/app/models/setting.rb
index 185991d9..072afa0d 100644
--- a/app/models/setting.rb
+++ b/app/models/setting.rb
@@ -33,6 +33,45 @@ class Setting < ActiveRecord::Base
'%H:%M',
'%I:%M %p'
]
+
+ ENCODINGS = %w(US-ASCII
+ windows-1250
+ windows-1251
+ windows-1252
+ windows-1253
+ windows-1254
+ windows-1255
+ windows-1256
+ windows-1257
+ windows-1258
+ windows-31j
+ ISO-2022-JP
+ ISO-2022-KR
+ ISO-8859-1
+ ISO-8859-2
+ ISO-8859-3
+ ISO-8859-4
+ ISO-8859-5
+ ISO-8859-6
+ ISO-8859-7
+ ISO-8859-8
+ ISO-8859-9
+ ISO-8859-13
+ ISO-8859-15
+ KOI8-R
+ UTF-8
+ UTF-16
+ UTF-16BE
+ UTF-16LE
+ EUC-JP
+ Shift_JIS
+ GB18030
+ GBK
+ ISCII91
+ EUC-KR
+ Big5
+ Big5-HKSCS
+ TIS-620)
cattr_accessor :available_settings
@@available_settings = YAML::load(File.open("#{RAILS_ROOT}/config/settings.yml"))
diff --git a/app/views/settings/_repositories.rhtml b/app/views/settings/_repositories.rhtml
index 127801be..a8c92443 100644
--- a/app/views/settings/_repositories.rhtml
+++ b/app/views/settings/_repositories.rhtml
@@ -16,6 +16,9 @@
<%= text_field_tag 'settings[repositories_encodings]', Setting.repositories_encodings, :size => 60 %>
<%= l(:text_comma_separated) %>
+
+
+<%= select_tag 'settings[commit_logs_encoding]', options_for_select(Setting::ENCODINGS, Setting.commit_logs_encoding) %>