From 5f5dec16f2ececf806404d497886e9cb5e454281 Mon Sep 17 00:00:00 2001 From: Toshi MARUYAMA Date: Tue, 1 Mar 2011 10:27:30 +0000 Subject: [PATCH] scm: add feature of per project repository log encoding setting (#1735). Subversion, Mercurial and Git supports UTF-8 log. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4982 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/helpers/repositories_helper.rb | 12 ++++++++--- app/models/repository.rb | 2 +- app/models/repository/bazaar.rb | 3 ++- app/models/repository/cvs.rb | 3 ++- app/models/repository/darcs.rb | 3 ++- .../repositories_bazaar_controller_test.rb | 12 +++++++---- .../repositories_cvs_controller_test.rb | 3 ++- .../repositories_darcs_controller_test.rb | 4 +++- test/unit/changeset_test.rb | 21 ++++++++++--------- test/unit/helpers/application_helper_test.rb | 4 +++- test/unit/repository_bazaar_test.rb | 7 +++++-- test/unit/repository_cvs_test.rb | 8 ++++--- test/unit/repository_darcs_test.rb | 4 +++- test/unit/repository_test.rb | 11 ++++++---- 14 files changed, 63 insertions(+), 34 deletions(-) diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index e588fe366..1deb13cd9 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -189,7 +189,9 @@ module RepositoriesHelper def darcs_field_tags(form, repository) content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, - :disabled => (repository && !repository.new_record?))) + :disabled => (repository && !repository.new_record?))) + + content_tag('p', form.select(:log_encoding, [nil] + Setting::ENCODINGS, + :label => 'Commit messages encoding', :required => true)) end def mercurial_field_tags(form, repository) @@ -212,13 +214,17 @@ module RepositoriesHelper :disabled => !repository.new_record?)) + content_tag('p', form.text_field(:url, :label => 'Module', :size => 30, :required => true, - :disabled => !repository.new_record?)) + :disabled => !repository.new_record?)) + + content_tag('p', form.select(:log_encoding, [nil] + Setting::ENCODINGS, + :label => 'Commit messages encoding', :required => true)) end def bazaar_field_tags(form, repository) content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, - :disabled => (repository && !repository.new_record?))) + :disabled => (repository && !repository.new_record?))) + + content_tag('p', form.select(:log_encoding, [nil] + Setting::ENCODINGS, + :label => 'Commit messages encoding', :required => true)) end def filesystem_field_tags(form, repository) diff --git a/app/models/repository.rb b/app/models/repository.rb index bddbbbec4..07e24af29 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -191,7 +191,7 @@ class Repository < ActiveRecord::Base end def repo_log_encoding - encoding = Setting.commit_logs_encoding.to_s.strip + encoding = log_encoding.to_s.strip encoding.blank? ? 'UTF-8' : encoding end diff --git a/app/models/repository/bazaar.rb b/app/models/repository/bazaar.rb index d68fabc9a..3ae8b28fe 100644 --- a/app/models/repository/bazaar.rb +++ b/app/models/repository/bazaar.rb @@ -19,10 +19,11 @@ require 'redmine/scm/adapters/bazaar_adapter' class Repository::Bazaar < Repository attr_protected :root_url - validates_presence_of :url + validates_presence_of :url, :log_encoding ATTRIBUTE_KEY_NAMES = { "url" => "Root directory", + "log_encoding" => "Commit messages encoding", } def self.human_attribute_name(attribute_key_name) ATTRIBUTE_KEY_NAMES[attribute_key_name] || super diff --git a/app/models/repository/cvs.rb b/app/models/repository/cvs.rb index e3dfced69..2ee82a740 100644 --- a/app/models/repository/cvs.rb +++ b/app/models/repository/cvs.rb @@ -19,11 +19,12 @@ require 'redmine/scm/adapters/cvs_adapter' require 'digest/sha1' class Repository::Cvs < Repository - validates_presence_of :url, :root_url + validates_presence_of :url, :root_url, :log_encoding ATTRIBUTE_KEY_NAMES = { "url" => "CVSROOT", "root_url" => "Module", + "log_encoding" => "Commit messages encoding", } def self.human_attribute_name(attribute_key_name) ATTRIBUTE_KEY_NAMES[attribute_key_name] || super diff --git a/app/models/repository/darcs.rb b/app/models/repository/darcs.rb index c6d7cafd0..c8870e299 100644 --- a/app/models/repository/darcs.rb +++ b/app/models/repository/darcs.rb @@ -18,10 +18,11 @@ require 'redmine/scm/adapters/darcs_adapter' class Repository::Darcs < Repository - validates_presence_of :url + validates_presence_of :url, :log_encoding ATTRIBUTE_KEY_NAMES = { "url" => "Root directory", + "log_encoding" => "Commit messages encoding", } def self.human_attribute_name(attribute_key_name) ATTRIBUTE_KEY_NAMES[attribute_key_name] || super diff --git a/test/functional/repositories_bazaar_controller_test.rb b/test/functional/repositories_bazaar_controller_test.rb index 5f7de1de8..576b710ca 100644 --- a/test/functional/repositories_bazaar_controller_test.rb +++ b/test/functional/repositories_bazaar_controller_test.rb @@ -32,9 +32,13 @@ class RepositoriesBazaarControllerTest < ActionController::TestCase @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new User.current = nil - Repository::Bazaar.create(:project => Project.find(3), :url => REPOSITORY_PATH) + @project = Project.find(3) + @repository = Repository::Bazaar.create( + :project => @project, :url => REPOSITORY_PATH, + :log_encoding => 'UTF-8') + assert @repository end - + if File.directory?(REPOSITORY_PATH) def test_show get :show, :id => 3 @@ -43,7 +47,7 @@ class RepositoriesBazaarControllerTest < ActionController::TestCase assert_not_nil assigns(:entries) assert_not_nil assigns(:changesets) end - + def test_browse_root get :show, :id => 3 assert_response :success @@ -53,7 +57,7 @@ class RepositoriesBazaarControllerTest < ActionController::TestCase assert assigns(:entries).detect {|e| e.name == 'directory' && e.kind == 'dir'} assert assigns(:entries).detect {|e| e.name == 'doc-mkdir.txt' && e.kind == 'file'} end - + def test_browse_directory get :show, :id => 3, :path => ['directory'] assert_response :success diff --git a/test/functional/repositories_cvs_controller_test.rb b/test/functional/repositories_cvs_controller_test.rb index ca040e3f2..6a6be3883 100644 --- a/test/functional/repositories_cvs_controller_test.rb +++ b/test/functional/repositories_cvs_controller_test.rb @@ -41,7 +41,8 @@ class RepositoriesCvsControllerTest < ActionController::TestCase @project = Project.find(PRJ_ID) @repository = Repository::Cvs.create(:project => Project.find(PRJ_ID), :root_url => REPOSITORY_PATH, - :url => MODULE_NAME) + :url => MODULE_NAME, + :log_encoding => 'UTF-8') assert @repository end diff --git a/test/functional/repositories_darcs_controller_test.rb b/test/functional/repositories_darcs_controller_test.rb index a315f9fa8..d78149ca5 100644 --- a/test/functional/repositories_darcs_controller_test.rb +++ b/test/functional/repositories_darcs_controller_test.rb @@ -34,7 +34,9 @@ class RepositoriesDarcsControllerTest < ActionController::TestCase @response = ActionController::TestResponse.new User.current = nil @project = Project.find(PRJ_ID) - @repository = Repository::Darcs.create(:project => @project, :url => REPOSITORY_PATH) + @repository = Repository::Darcs.create( + :project => @project, :url => REPOSITORY_PATH, + :log_encoding => 'UTF-8') assert @repository end diff --git a/test/unit/changeset_test.rb b/test/unit/changeset_test.rb index 3884096b6..767192db0 100644 --- a/test/unit/changeset_test.rb +++ b/test/unit/changeset_test.rb @@ -220,12 +220,13 @@ class ChangesetTest < ActiveSupport::TestCase changeset = Changeset.find_by_revision('10') assert_nil changeset.next end - + def test_comments_should_be_converted_to_utf8 - with_settings :commit_logs_encoding => 'ISO-8859-1' do proj = Project.find(3) str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt") - r = Repository::Bazaar.create!(:project => proj, :url => '/tmp/test/bazaar') + r = Repository::Bazaar.create!( + :project => proj, :url => '/tmp/test/bazaar', + :log_encoding => 'ISO-8859-1' ) assert r c = Changeset.new(:repository => r, :committed_on => Time.now, @@ -234,14 +235,14 @@ class ChangesetTest < ActiveSupport::TestCase :comments => str) assert( c.save ) assert_equal "Texte encodé en ISO-8859-1.", c.comments - end end def test_invalid_utf8_sequences_in_comments_should_be_stripped - with_settings :commit_logs_encoding => 'UTF-8' do proj = Project.find(3) str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt") - r = Repository::Bazaar.create!(:project => proj, :url => '/tmp/test/bazaar') + r = Repository::Bazaar.create!( + :project => proj, :url => '/tmp/test/bazaar', + :log_encoding => 'UTF-8' ) assert r c = Changeset.new(:repository => r, :committed_on => Time.now, @@ -254,11 +255,9 @@ class ChangesetTest < ActiveSupport::TestCase else assert_equal "Texte encod en ISO-8859-1.", c.comments end - end end def test_comments_should_be_converted_all_latin1_to_utf8 - with_settings :commit_logs_encoding => 'ISO-8859-1' do s1 = "\xC2\x80" s2 = "\xc3\x82\xc2\x80" if s1.respond_to?(:force_encoding) @@ -271,7 +270,10 @@ class ChangesetTest < ActiveSupport::TestCase assert_equal s3.encode('UTF-8'), s4 end proj = Project.find(3) - r = Repository::Bazaar.create!(:project => proj, :url => '/tmp/test/bazaar') + r = Repository::Bazaar.create!( + :project => proj, :url => '/tmp/test/bazaar', + :log_encoding => 'ISO-8859-1' ) + assert r assert r c = Changeset.new(:repository => r, :committed_on => Time.now, @@ -280,7 +282,6 @@ class ChangesetTest < ActiveSupport::TestCase :comments => s1) assert( c.save ) assert_equal s2, c.comments - end end def test_identifier diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb index 69eaf7456..aa2c62776 100644 --- a/test/unit/helpers/application_helper_test.rb +++ b/test/unit/helpers/application_helper_test.rb @@ -292,7 +292,9 @@ RAW 'commit:20080308225258-98289-abcd456efg.gz' => changeset_link, } @project = Project.find(3) - r = Repository::Darcs.create!(:project => @project, :url => '/tmp/test/darcs') + r = Repository::Darcs.create!( + :project => @project, :url => '/tmp/test/darcs', + :log_encoding => 'UTF-8') assert r c = Changeset.new(:repository => r, :committed_on => Time.now, diff --git a/test/unit/repository_bazaar_test.rb b/test/unit/repository_bazaar_test.rb index 38f2af498..b2515fe30 100644 --- a/test/unit/repository_bazaar_test.rb +++ b/test/unit/repository_bazaar_test.rb @@ -19,14 +19,17 @@ require File.expand_path('../../test_helper', __FILE__) class RepositoryBazaarTest < ActiveSupport::TestCase fixtures :projects - + # No '..' in the repository path REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/bazaar_repository' REPOSITORY_PATH.gsub!(/\/+/, '/') def setup @project = Project.find(3) - assert @repository = Repository::Bazaar.create(:project => @project, :url => "file:///#{REPOSITORY_PATH}") + @repository = Repository::Bazaar.create( + :project => @project, :url => "file:///#{REPOSITORY_PATH}", + :log_encoding => 'UTF-8') + assert @repository end if File.directory?(REPOSITORY_PATH) diff --git a/test/unit/repository_cvs_test.rb b/test/unit/repository_cvs_test.rb index a5da09f55..0fd81615b 100644 --- a/test/unit/repository_cvs_test.rb +++ b/test/unit/repository_cvs_test.rb @@ -28,9 +28,11 @@ class RepositoryCvsTest < ActiveSupport::TestCase def setup @project = Project.find(3) - assert @repository = Repository::Cvs.create(:project => @project, - :root_url => REPOSITORY_PATH, - :url => MODULE_NAME) + @repository = Repository::Cvs.create(:project => @project, + :root_url => REPOSITORY_PATH, + :url => MODULE_NAME, + :log_encoding => 'UTF-8') + assert @repository end if File.directory?(REPOSITORY_PATH) diff --git a/test/unit/repository_darcs_test.rb b/test/unit/repository_darcs_test.rb index ef833e93d..2e16973c5 100644 --- a/test/unit/repository_darcs_test.rb +++ b/test/unit/repository_darcs_test.rb @@ -25,7 +25,9 @@ class RepositoryDarcsTest < ActiveSupport::TestCase def setup @project = Project.find(3) - @repository = Repository::Darcs.create(:project => @project, :url => REPOSITORY_PATH) + @repository = Repository::Darcs.create( + :project => @project, :url => REPOSITORY_PATH, + :log_encoding => 'UTF-8') assert @repository end diff --git a/test/unit/repository_test.rb b/test/unit/repository_test.rb index 8c4146ff0..4e6099e3e 100644 --- a/test/unit/repository_test.rb +++ b/test/unit/repository_test.rb @@ -125,16 +125,19 @@ class RepositoryTest < ActiveSupport::TestCase assert_not_equal( comment, changeset.comments ) assert_equal( 'This is a loooooooooooooooooooooooooooong comment', changeset.comments ) end - + def test_for_urls_strip - repository = Repository::Cvs.create(:project => Project.find(4), :url => ' :pserver:login:password@host:/path/to/the/repository', - :root_url => 'foo ') + repository = Repository::Cvs.create( + :project => Project.find(4), + :url => ' :pserver:login:password@host:/path/to/the/repository', + :root_url => 'foo ', + :log_encoding => 'UTF-8') assert repository.save repository.reload assert_equal ':pserver:login:password@host:/path/to/the/repository', repository.url assert_equal 'foo', repository.root_url end - + def test_manual_user_mapping assert_no_difference "Changeset.count(:conditions => 'user_id <> 2')" do c = Changeset.create!(:repository => @repository, :committer => 'foo', :committed_on => Time.now, :revision => 100, :comments => 'Committed by foo.') -- 2.39.5