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
This commit is contained in:
Toshi MARUYAMA 2011-03-01 10:27:30 +00:00 committed by Eric Davis
parent 231fcf6fd8
commit e383414c31
14 changed files with 63 additions and 34 deletions

View File

@ -186,7 +186,9 @@ module RepositoriesHelper
end end
def darcs_field_tags(form, repository) def darcs_field_tags(form, repository)
content_tag('p', form.text_field(:url, :label => :label_darcs_path, :size => 60, :required => true, :disabled => (repository && !repository.new_record?))) content_tag('p', form.text_field(:url, :label => :label_darcs_path, :size => 60, :required => true, :disabled => (repository && !repository.new_record?))) +
content_tag('p', form.select(:log_encoding, [nil] + Setting::ENCODINGS,
:label => 'Commit messages encoding', :required => true))
end end
def mercurial_field_tags(form, repository) def mercurial_field_tags(form, repository)
@ -201,11 +203,15 @@ module RepositoriesHelper
def cvs_field_tags(form, repository) def cvs_field_tags(form, repository)
content_tag('p', form.text_field(:root_url, :label => :label_cvs_path, :size => 60, :required => true, :disabled => !repository.new_record?)) + content_tag('p', form.text_field(:root_url, :label => :label_cvs_path, :size => 60, :required => true, :disabled => !repository.new_record?)) +
content_tag('p', form.text_field(:url, :label => :label_cvs_module, :size => 30, :required => true, :disabled => !repository.new_record?)) content_tag('p', form.text_field(:url, :label => :label_cvs_module, :size => 30, :required => true, :disabled => !repository.new_record?)) +
content_tag('p', form.select(:log_encoding, [nil] + Setting::ENCODINGS,
:label => 'Commit messages encoding', :required => true))
end end
def bazaar_field_tags(form, repository) def bazaar_field_tags(form, repository)
content_tag('p', form.text_field(:url, :label => :label_bazaar_path, :size => 60, :required => true, :disabled => (repository && !repository.new_record?))) content_tag('p', form.text_field(:url, :label => :label_bazaar_path, :size => 60, :required => true, :disabled => (repository && !repository.new_record?))) +
content_tag('p', form.select(:log_encoding, [nil] + Setting::ENCODINGS,
:label => 'Commit messages encoding', :required => true))
end end
def filesystem_field_tags(form, repository) def filesystem_field_tags(form, repository)

View File

@ -191,7 +191,7 @@ class Repository < ActiveRecord::Base
end end
def repo_log_encoding def repo_log_encoding
encoding = Setting.commit_logs_encoding.to_s.strip encoding = log_encoding.to_s.strip
encoding.blank? ? 'UTF-8' : encoding encoding.blank? ? 'UTF-8' : encoding
end end

View File

@ -19,10 +19,11 @@ require 'redmine/scm/adapters/bazaar_adapter'
class Repository::Bazaar < Repository class Repository::Bazaar < Repository
attr_protected :root_url attr_protected :root_url
validates_presence_of :url validates_presence_of :url, :log_encoding
ATTRIBUTE_KEY_NAMES = { ATTRIBUTE_KEY_NAMES = {
"url" => "Root directory", "url" => "Root directory",
"log_encoding" => "Commit messages encoding",
} }
def self.human_attribute_name(attribute_key_name) def self.human_attribute_name(attribute_key_name)
ATTRIBUTE_KEY_NAMES[attribute_key_name] || super ATTRIBUTE_KEY_NAMES[attribute_key_name] || super

View File

@ -19,11 +19,12 @@ require 'redmine/scm/adapters/cvs_adapter'
require 'digest/sha1' require 'digest/sha1'
class Repository::Cvs < Repository class Repository::Cvs < Repository
validates_presence_of :url, :root_url validates_presence_of :url, :root_url, :log_encoding
ATTRIBUTE_KEY_NAMES = { ATTRIBUTE_KEY_NAMES = {
"url" => "CVSROOT", "url" => "CVSROOT",
"root_url" => "Module", "root_url" => "Module",
"log_encoding" => "Commit messages encoding",
} }
def self.human_attribute_name(attribute_key_name) def self.human_attribute_name(attribute_key_name)
ATTRIBUTE_KEY_NAMES[attribute_key_name] || super ATTRIBUTE_KEY_NAMES[attribute_key_name] || super

View File

@ -18,10 +18,11 @@
require 'redmine/scm/adapters/darcs_adapter' require 'redmine/scm/adapters/darcs_adapter'
class Repository::Darcs < Repository class Repository::Darcs < Repository
validates_presence_of :url validates_presence_of :url, :log_encoding
ATTRIBUTE_KEY_NAMES = { ATTRIBUTE_KEY_NAMES = {
"url" => "Root directory", "url" => "Root directory",
"log_encoding" => "Commit messages encoding",
} }
def self.human_attribute_name(attribute_key_name) def self.human_attribute_name(attribute_key_name)
ATTRIBUTE_KEY_NAMES[attribute_key_name] || super ATTRIBUTE_KEY_NAMES[attribute_key_name] || super

View File

@ -32,7 +32,11 @@ class RepositoriesBazaarControllerTest < ActionController::TestCase
@request = ActionController::TestRequest.new @request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new @response = ActionController::TestResponse.new
User.current = nil 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 end
if File.directory?(REPOSITORY_PATH) if File.directory?(REPOSITORY_PATH)

View File

@ -41,7 +41,8 @@ class RepositoriesCvsControllerTest < ActionController::TestCase
@project = Project.find(PRJ_ID) @project = Project.find(PRJ_ID)
@repository = Repository::Cvs.create(:project => Project.find(PRJ_ID), @repository = Repository::Cvs.create(:project => Project.find(PRJ_ID),
:root_url => REPOSITORY_PATH, :root_url => REPOSITORY_PATH,
:url => MODULE_NAME) :url => MODULE_NAME,
:log_encoding => 'UTF-8')
assert @repository assert @repository
end end

View File

@ -34,7 +34,9 @@ class RepositoriesDarcsControllerTest < ActionController::TestCase
@response = ActionController::TestResponse.new @response = ActionController::TestResponse.new
User.current = nil User.current = nil
@project = Project.find(PRJ_ID) @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 assert @repository
end end

View File

@ -222,10 +222,11 @@ class ChangesetTest < ActiveSupport::TestCase
end end
def test_comments_should_be_converted_to_utf8 def test_comments_should_be_converted_to_utf8
with_settings :commit_logs_encoding => 'ISO-8859-1' do
proj = Project.find(3) proj = Project.find(3)
str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt") 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 assert r
c = Changeset.new(:repository => r, c = Changeset.new(:repository => r,
:committed_on => Time.now, :committed_on => Time.now,
@ -235,13 +236,13 @@ class ChangesetTest < ActiveSupport::TestCase
assert( c.save ) assert( c.save )
assert_equal "Texte encodé en ISO-8859-1.", c.comments assert_equal "Texte encodé en ISO-8859-1.", c.comments
end end
end
def test_invalid_utf8_sequences_in_comments_should_be_stripped def test_invalid_utf8_sequences_in_comments_should_be_stripped
with_settings :commit_logs_encoding => 'UTF-8' do
proj = Project.find(3) proj = Project.find(3)
str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt") 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 assert r
c = Changeset.new(:repository => r, c = Changeset.new(:repository => r,
:committed_on => Time.now, :committed_on => Time.now,
@ -255,10 +256,8 @@ class ChangesetTest < ActiveSupport::TestCase
assert_equal "Texte encod en ISO-8859-1.", c.comments assert_equal "Texte encod en ISO-8859-1.", c.comments
end end
end end
end
def test_comments_should_be_converted_all_latin1_to_utf8 def test_comments_should_be_converted_all_latin1_to_utf8
with_settings :commit_logs_encoding => 'ISO-8859-1' do
s1 = "\xC2\x80" s1 = "\xC2\x80"
s2 = "\xc3\x82\xc2\x80" s2 = "\xc3\x82\xc2\x80"
if s1.respond_to?(:force_encoding) if s1.respond_to?(:force_encoding)
@ -271,7 +270,10 @@ class ChangesetTest < ActiveSupport::TestCase
assert_equal s3.encode('UTF-8'), s4 assert_equal s3.encode('UTF-8'), s4
end end
proj = Project.find(3) 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 assert r
c = Changeset.new(:repository => r, c = Changeset.new(:repository => r,
:committed_on => Time.now, :committed_on => Time.now,
@ -281,7 +283,6 @@ class ChangesetTest < ActiveSupport::TestCase
assert( c.save ) assert( c.save )
assert_equal s2, c.comments assert_equal s2, c.comments
end end
end
def test_identifier def test_identifier
c = Changeset.find_by_revision('1') c = Changeset.find_by_revision('1')

View File

@ -292,7 +292,9 @@ RAW
'commit:20080308225258-98289-abcd456efg.gz' => changeset_link, 'commit:20080308225258-98289-abcd456efg.gz' => changeset_link,
} }
@project = Project.find(3) @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 assert r
c = Changeset.new(:repository => r, c = Changeset.new(:repository => r,
:committed_on => Time.now, :committed_on => Time.now,

View File

@ -26,7 +26,10 @@ class RepositoryBazaarTest < ActiveSupport::TestCase
def setup def setup
@project = Project.find(3) @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 end
if File.directory?(REPOSITORY_PATH) if File.directory?(REPOSITORY_PATH)

View File

@ -28,9 +28,11 @@ class RepositoryCvsTest < ActiveSupport::TestCase
def setup def setup
@project = Project.find(3) @project = Project.find(3)
assert @repository = Repository::Cvs.create(:project => @project, @repository = Repository::Cvs.create(:project => @project,
:root_url => REPOSITORY_PATH, :root_url => REPOSITORY_PATH,
:url => MODULE_NAME) :url => MODULE_NAME,
:log_encoding => 'UTF-8')
assert @repository
end end
if File.directory?(REPOSITORY_PATH) if File.directory?(REPOSITORY_PATH)

View File

@ -25,7 +25,9 @@ class RepositoryDarcsTest < ActiveSupport::TestCase
def setup def setup
@project = Project.find(3) @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 assert @repository
end end

View File

@ -128,8 +128,11 @@ class RepositoryTest < ActiveSupport::TestCase
end end
def test_for_urls_strip def test_for_urls_strip
repository = Repository::Cvs.create(:project => Project.find(4), :url => ' :pserver:login:password@host:/path/to/the/repository', repository = Repository::Cvs.create(
:root_url => 'foo ') :project => Project.find(4),
:url => ' :pserver:login:password@host:/path/to/the/repository',
:root_url => 'foo ',
:log_encoding => 'UTF-8')
assert repository.save assert repository.save
repository.reload repository.reload
assert_equal ':pserver:login:password@host:/path/to/the/repository', repository.url assert_equal ':pserver:login:password@host:/path/to/the/repository', repository.url