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) %>

<%= l(:text_issues_ref_in_commit_messages) %> diff --git a/config/settings.yml b/config/settings.yml index 9a59d568..ac79edb8 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -122,6 +122,9 @@ default_projects_public: # multiple values accepted, comma separated repositories_encodings: default: '' +# encoding used to convert commit logs to UTF-8 +commit_logs_encoding: + default: 'UTF-8' ui_theme: default: '' emails_footer: diff --git a/lang/bg.yml b/lang/bg.yml index 6a967611..f15ba4da 100644 --- a/lang/bg.yml +++ b/lang/bg.yml @@ -634,3 +634,4 @@ setting_mail_handler_api_key: API key text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." field_parent_title: Parent page label_issue_watchers: Watchers +setting_commit_logs_encoding: Commit messages encoding diff --git a/lang/cs.yml b/lang/cs.yml index cc5847ee..b7b1b9ea 100644 --- a/lang/cs.yml +++ b/lang/cs.yml @@ -639,3 +639,4 @@ setting_mail_handler_api_key: API key text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." field_parent_title: Parent page label_issue_watchers: Watchers +setting_commit_logs_encoding: Commit messages encoding diff --git a/lang/da.yml b/lang/da.yml index 1cb55cc4..3227dc7b 100644 --- a/lang/da.yml +++ b/lang/da.yml @@ -636,3 +636,4 @@ setting_mail_handler_api_key: API key text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." field_parent_title: Parent page label_issue_watchers: Watchers +setting_commit_logs_encoding: Commit messages encoding diff --git a/lang/de.yml b/lang/de.yml index f0be8449..5093c31f 100644 --- a/lang/de.yml +++ b/lang/de.yml @@ -635,3 +635,4 @@ setting_mail_handler_api_key: API key text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." field_parent_title: Parent page label_issue_watchers: Watchers +setting_commit_logs_encoding: Commit messages encoding diff --git a/lang/en.yml b/lang/en.yml index 6c4a7bd8..6cd6d427 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -209,6 +209,7 @@ setting_time_format: Time format setting_cross_project_issue_relations: Allow cross-project issue relations setting_issue_list_default_columns: Default columns displayed on the issue list setting_repositories_encodings: Repositories encodings +setting_commit_logs_encoding: Commit messages encoding setting_emails_footer: Emails footer setting_protocol: Protocol setting_per_page_options: Objects per page options diff --git a/lang/es.yml b/lang/es.yml index 7f27d53e..58d27f28 100644 --- a/lang/es.yml +++ b/lang/es.yml @@ -637,3 +637,4 @@ setting_mail_handler_api_key: API key text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." field_parent_title: Parent page label_issue_watchers: Watchers +setting_commit_logs_encoding: Commit messages encoding diff --git a/lang/fi.yml b/lang/fi.yml index 031d59d6..394ff23f 100644 --- a/lang/fi.yml +++ b/lang/fi.yml @@ -634,3 +634,4 @@ setting_mail_handler_api_key: API key text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." field_parent_title: Parent page label_issue_watchers: Watchers +setting_commit_logs_encoding: Commit messages encoding diff --git a/lang/fr.yml b/lang/fr.yml index 5b621eba..e6c4b334 100644 --- a/lang/fr.yml +++ b/lang/fr.yml @@ -210,6 +210,7 @@ setting_time_format: Format d'heure setting_cross_project_issue_relations: Autoriser les relations entre demandes de différents projets setting_issue_list_default_columns: Colonnes affichées par défaut sur la liste des demandes setting_repositories_encodings: Encodages des dépôts +setting_commit_logs_encoding: Encodage des messages de commit setting_emails_footer: Pied-de-page des emails setting_protocol: Protocole setting_per_page_options: Options d'objets affichés par page diff --git a/lang/he.yml b/lang/he.yml index 9c8fbae7..652b0ed8 100644 --- a/lang/he.yml +++ b/lang/he.yml @@ -634,3 +634,4 @@ setting_mail_handler_api_key: API key text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." field_parent_title: Parent page label_issue_watchers: Watchers +setting_commit_logs_encoding: Commit messages encoding diff --git a/lang/hu.yml b/lang/hu.yml index a5d208cb..15c42053 100644 --- a/lang/hu.yml +++ b/lang/hu.yml @@ -635,3 +635,4 @@ setting_mail_handler_api_key: API kulcs text_email_delivery_not_configured: "Az E-mail küldés nincs konfigurálva, és az értesítések ki vannak kapcsolva.\nÁllítsd be az SMTP szervert a config/email.yml fájlban és indítsd újra az alkalmazást, hogy érvénybe lépjen." field_parent_title: Parent page label_issue_watchers: Watchers +setting_commit_logs_encoding: Commit messages encoding diff --git a/lang/it.yml b/lang/it.yml index 5d62e325..3e1c1d53 100644 --- a/lang/it.yml +++ b/lang/it.yml @@ -634,3 +634,4 @@ setting_mail_handler_api_key: chiave API text_email_delivery_not_configured: "La consegna via e-mail non è configurata e le notifiche sono disabilitate.\nConfigura il tuo server SMTP in config/email.yml e riavvia l'applicazione per abilitarle." field_parent_title: Parent page label_issue_watchers: Watchers +setting_commit_logs_encoding: Commit messages encoding diff --git a/lang/ja.yml b/lang/ja.yml index f3ade750..e7805393 100644 --- a/lang/ja.yml +++ b/lang/ja.yml @@ -635,3 +635,4 @@ setting_mail_handler_api_key: API key text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." field_parent_title: Parent page label_issue_watchers: Watchers +setting_commit_logs_encoding: Commit messages encoding diff --git a/lang/ko.yml b/lang/ko.yml index 961255e0..c85ce72e 100644 --- a/lang/ko.yml +++ b/lang/ko.yml @@ -634,3 +634,4 @@ setting_mail_handler_api_key: API key text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." field_parent_title: Parent page label_issue_watchers: Watchers +setting_commit_logs_encoding: Commit messages encoding diff --git a/lang/lt.yml b/lang/lt.yml index 58f79850..188faf21 100644 --- a/lang/lt.yml +++ b/lang/lt.yml @@ -637,3 +637,4 @@ setting_mail_handler_api_key: API raktas text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." field_parent_title: Parent page label_issue_watchers: Watchers +setting_commit_logs_encoding: Commit messages encoding diff --git a/lang/nl.yml b/lang/nl.yml index 08e30014..fd5bff1f 100644 --- a/lang/nl.yml +++ b/lang/nl.yml @@ -635,3 +635,4 @@ setting_mail_handler_api_key: API key text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." field_parent_title: Parent page label_issue_watchers: Watchers +setting_commit_logs_encoding: Commit messages encoding diff --git a/lang/no.yml b/lang/no.yml index 7af029db..2cdc0bcd 100644 --- a/lang/no.yml +++ b/lang/no.yml @@ -635,3 +635,4 @@ setting_mail_handler_api_key: API key text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." field_parent_title: Parent page label_issue_watchers: Watchers +setting_commit_logs_encoding: Commit messages encoding diff --git a/lang/pl.yml b/lang/pl.yml index 0a29b7c4..69e04e4d 100644 --- a/lang/pl.yml +++ b/lang/pl.yml @@ -634,3 +634,4 @@ setting_mail_handler_api_key: API key text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." field_parent_title: Parent page label_issue_watchers: Watchers +setting_commit_logs_encoding: Commit messages encoding diff --git a/lang/pt-br.yml b/lang/pt-br.yml index 3ab24aeb..2b25e023 100644 --- a/lang/pt-br.yml +++ b/lang/pt-br.yml @@ -634,3 +634,4 @@ setting_mail_handler_api_key: API key text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." field_parent_title: Parent page label_issue_watchers: Watchers +setting_commit_logs_encoding: Commit messages encoding diff --git a/lang/pt.yml b/lang/pt.yml index bd32cd14..6505b762 100644 --- a/lang/pt.yml +++ b/lang/pt.yml @@ -634,3 +634,4 @@ setting_mail_handler_api_key: API key text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." field_parent_title: Parent page label_issue_watchers: Watchers +setting_commit_logs_encoding: Commit messages encoding diff --git a/lang/ro.yml b/lang/ro.yml index 2e562e23..4887bcf9 100644 --- a/lang/ro.yml +++ b/lang/ro.yml @@ -634,3 +634,4 @@ setting_mail_handler_api_key: API key text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." field_parent_title: Parent page label_issue_watchers: Watchers +setting_commit_logs_encoding: Commit messages encoding diff --git a/lang/ru.yml b/lang/ru.yml index 61e71369..095e4db3 100644 --- a/lang/ru.yml +++ b/lang/ru.yml @@ -638,3 +638,4 @@ setting_mail_handler_api_key: API ключ text_email_delivery_not_configured: "Параметры работы с почтовым сервером не настроены и функция уведомления по email не активна.\nНастроить параметры для вашего SMTP сервера вы можете в файле config/email.yml. Для применения изменений перезапустите приложение." field_parent_title: Parent page label_issue_watchers: Watchers +setting_commit_logs_encoding: Commit messages encoding diff --git a/lang/sr.yml b/lang/sr.yml index ba79d4ef..f81d0e05 100644 --- a/lang/sr.yml +++ b/lang/sr.yml @@ -635,3 +635,4 @@ setting_mail_handler_api_key: API key text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." field_parent_title: Parent page label_issue_watchers: Watchers +setting_commit_logs_encoding: Commit messages encoding diff --git a/lang/sv.yml b/lang/sv.yml index 9505759c..5e120b3f 100644 --- a/lang/sv.yml +++ b/lang/sv.yml @@ -635,3 +635,4 @@ setting_mail_handler_api_key: API key text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." field_parent_title: Parent page label_issue_watchers: Watchers +setting_commit_logs_encoding: Commit messages encoding diff --git a/lang/th.yml b/lang/th.yml index 6c4ce30d..3ae37e55 100644 --- a/lang/th.yml +++ b/lang/th.yml @@ -637,3 +637,4 @@ setting_mail_handler_api_key: API key text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." field_parent_title: Parent page label_issue_watchers: Watchers +setting_commit_logs_encoding: Commit messages encoding diff --git a/lang/uk.yml b/lang/uk.yml index 4fa27f7d..cf5f384b 100644 --- a/lang/uk.yml +++ b/lang/uk.yml @@ -636,3 +636,4 @@ setting_mail_handler_api_key: API key text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." field_parent_title: Parent page label_issue_watchers: Watchers +setting_commit_logs_encoding: Commit messages encoding diff --git a/lang/zh-tw.yml b/lang/zh-tw.yml index 1e648363..f13331df 100644 --- a/lang/zh-tw.yml +++ b/lang/zh-tw.yml @@ -635,3 +635,4 @@ enumeration_doc_categories: 文件分類 enumeration_activities: 活動 (時間追蹤) field_parent_title: Parent page label_issue_watchers: Watchers +setting_commit_logs_encoding: Commit messages encoding diff --git a/lang/zh.yml b/lang/zh.yml index 7158a7f8..682b59eb 100644 --- a/lang/zh.yml +++ b/lang/zh.yml @@ -635,3 +635,4 @@ enumeration_activities: 活动(时间跟踪) text_email_delivery_not_configured: "Email delivery is not configured, and notifications are disabled.\nConfigure your SMTP server in config/email.yml and restart the application to enable them." field_parent_title: Parent page label_issue_watchers: Watchers +setting_commit_logs_encoding: Commit messages encoding