scm: ignore log encoding setting in Subversion and Mercurial (#7597).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4962 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
7664892b5d
commit
06f078a813
|
@ -56,10 +56,6 @@ class Changeset < ActiveRecord::Base
|
||||||
revision.to_s
|
revision.to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def comments=(comment)
|
|
||||||
write_attribute(:comments, Changeset.normalize_comments(comment))
|
|
||||||
end
|
|
||||||
|
|
||||||
def committed_on=(date)
|
def committed_on=(date)
|
||||||
self.commit_date = date
|
self.commit_date = date
|
||||||
|
@ -75,10 +71,6 @@ class Changeset < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def committer=(arg)
|
|
||||||
write_attribute(:committer, self.class.to_utf8(arg.to_s))
|
|
||||||
end
|
|
||||||
|
|
||||||
def project
|
def project
|
||||||
repository.project
|
repository.project
|
||||||
end
|
end
|
||||||
|
@ -88,9 +80,11 @@ class Changeset < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def before_create
|
def before_create
|
||||||
self.user = repository.find_committer_user(committer)
|
self.committer = self.class.to_utf8(self.committer, repository.repo_log_encoding)
|
||||||
|
self.comments = self.class.normalize_comments(self.comments, repository.repo_log_encoding)
|
||||||
|
self.user = repository.find_committer_user(self.committer)
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_create
|
def after_create
|
||||||
scan_comment_for_issue_ids
|
scan_comment_for_issue_ids
|
||||||
end
|
end
|
||||||
|
@ -163,11 +157,6 @@ class Changeset < ActiveRecord::Base
|
||||||
@next ||= Changeset.find(:first, :conditions => ['id > ? AND repository_id = ?', self.id, self.repository_id], :order => 'id ASC')
|
@next ||= Changeset.find(:first, :conditions => ['id > ? AND repository_id = ?', self.id, self.repository_id], :order => 'id ASC')
|
||||||
end
|
end
|
||||||
|
|
||||||
# Strips and reencodes a commit log before insertion into the database
|
|
||||||
def self.normalize_comments(str)
|
|
||||||
to_utf8(str.to_s.strip)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Creates a new Change from it's common parameters
|
# Creates a new Change from it's common parameters
|
||||||
def create_change(change)
|
def create_change(change)
|
||||||
Change.create(:changeset => self,
|
Change.create(:changeset => self,
|
||||||
|
@ -176,7 +165,7 @@ class Changeset < ActiveRecord::Base
|
||||||
:from_path => change[:from_path],
|
:from_path => change[:from_path],
|
||||||
:from_revision => change[:from_revision])
|
:from_revision => change[:from_revision])
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Finds an issue that can be referenced by the commit message
|
# Finds an issue that can be referenced by the commit message
|
||||||
|
@ -246,9 +235,17 @@ class Changeset < ActiveRecord::Base
|
||||||
return @short_comments, @long_comments
|
return @short_comments, @long_comments
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.to_utf8(str)
|
public
|
||||||
|
|
||||||
|
# Strips and reencodes a commit log before insertion into the database
|
||||||
|
def self.normalize_comments(str, encoding)
|
||||||
|
Changeset.to_utf8(str.to_s.strip, encoding)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def self.to_utf8(str, encoding)
|
||||||
return str if str.blank?
|
return str if str.blank?
|
||||||
encoding = Setting.commit_logs_encoding.to_s.strip
|
|
||||||
unless encoding.blank? || encoding == 'UTF-8'
|
unless encoding.blank? || encoding == 'UTF-8'
|
||||||
begin
|
begin
|
||||||
str = Iconv.conv('UTF-8', encoding, str)
|
str = Iconv.conv('UTF-8', encoding, str)
|
||||||
|
|
|
@ -190,6 +190,11 @@ class Repository < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def repo_log_encoding
|
||||||
|
encoding = Setting.commit_logs_encoding.to_s.strip
|
||||||
|
encoding.blank? ? 'UTF-8' : encoding
|
||||||
|
end
|
||||||
|
|
||||||
# Fetches new changesets for all repositories of active projects
|
# Fetches new changesets for all repositories of active projects
|
||||||
# Can be called periodically by an external script
|
# Can be called periodically by an external script
|
||||||
# eg. ruby script/runner "Repository.fetch_changesets"
|
# eg. ruby script/runner "Repository.fetch_changesets"
|
||||||
|
@ -217,7 +222,7 @@ class Repository < ActiveRecord::Base
|
||||||
def self.available_scm
|
def self.available_scm
|
||||||
subclasses.collect {|klass| [klass.scm_name, klass.name]}
|
subclasses.collect {|klass| [klass.scm_name, klass.name]}
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.factory(klass_name, *args)
|
def self.factory(klass_name, *args)
|
||||||
klass = "Repository::#{klass_name}".constantize
|
klass = "Repository::#{klass_name}".constantize
|
||||||
klass.new(*args)
|
klass.new(*args)
|
||||||
|
|
|
@ -107,10 +107,11 @@ class Repository::Cvs < Repository
|
||||||
tmp_time = revision.time.clone
|
tmp_time = revision.time.clone
|
||||||
unless changes.find_by_path_and_revision(
|
unless changes.find_by_path_and_revision(
|
||||||
scm.with_leading_slash(revision.paths[0][:path]), revision.paths[0][:revision])
|
scm.with_leading_slash(revision.paths[0][:path]), revision.paths[0][:revision])
|
||||||
|
cmt = Changeset.normalize_comments(revision.message, repo_log_encoding)
|
||||||
cs = changesets.find(:first, :conditions=>{
|
cs = changesets.find(:first, :conditions=>{
|
||||||
:committed_on=>tmp_time - time_delta .. tmp_time + time_delta,
|
:committed_on=>tmp_time - time_delta .. tmp_time + time_delta,
|
||||||
:committer=>revision.author,
|
:committer=>revision.author,
|
||||||
:comments=>Changeset.normalize_comments(revision.message)
|
:comments=>cmt
|
||||||
})
|
})
|
||||||
|
|
||||||
# create a new changeset....
|
# create a new changeset....
|
||||||
|
|
|
@ -34,6 +34,10 @@ class Repository::Mercurial < Repository
|
||||||
'Mercurial'
|
'Mercurial'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def repo_log_encoding
|
||||||
|
'UTF-8'
|
||||||
|
end
|
||||||
|
|
||||||
# Returns the readable identifier for the given mercurial changeset
|
# Returns the readable identifier for the given mercurial changeset
|
||||||
def self.format_changeset_identifier(changeset)
|
def self.format_changeset_identifier(changeset)
|
||||||
"#{changeset.revision}:#{changeset.scmid}"
|
"#{changeset.revision}:#{changeset.scmid}"
|
||||||
|
|
|
@ -30,6 +30,10 @@ class Repository::Subversion < Repository
|
||||||
'Subversion'
|
'Subversion'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def repo_log_encoding
|
||||||
|
'UTF-8'
|
||||||
|
end
|
||||||
|
|
||||||
def latest_changesets(path, rev, limit=10)
|
def latest_changesets(path, rev, limit=10)
|
||||||
revisions = scm.revisions(path, rev, nil, :limit => limit)
|
revisions = scm.revisions(path, rev, nil, :limit => limit)
|
||||||
revisions ? changesets.find_all_by_revision(revisions.collect(&:identifier), :order => "committed_on DESC", :include => :user) : []
|
revisions ? changesets.find_all_by_revision(revisions.collect(&:identifier), :order => "committed_on DESC", :include => :user) : []
|
||||||
|
|
|
@ -137,6 +137,28 @@ class RepositorySubversionTest < ActiveSupport::TestCase
|
||||||
assert c.event_title.include?('123456789:')
|
assert c.event_title.include?('123456789:')
|
||||||
assert_equal '123456789', c.event_url[:rev]
|
assert_equal '123456789', c.event_url[:rev]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_log_encoding_ignore_setting
|
||||||
|
with_settings :commit_logs_encoding => 'windows-1252' do
|
||||||
|
s1 = "\xC2\x80"
|
||||||
|
s2 = "\xc3\x82\xc2\x80"
|
||||||
|
if s1.respond_to?(:force_encoding)
|
||||||
|
s3 = s1
|
||||||
|
s4 = s2
|
||||||
|
s1.force_encoding('ASCII-8BIT')
|
||||||
|
s2.force_encoding('ASCII-8BIT')
|
||||||
|
s3.force_encoding('ISO-8859-1')
|
||||||
|
s4.force_encoding('UTF-8')
|
||||||
|
assert_equal s3.encode('UTF-8'), s4
|
||||||
|
end
|
||||||
|
c = Changeset.new(:repository => @repository,
|
||||||
|
:comments=>s2,
|
||||||
|
:revision=>'123',
|
||||||
|
:committed_on => Time.now)
|
||||||
|
assert c.save
|
||||||
|
assert_equal s2, c.comments
|
||||||
|
end
|
||||||
|
end
|
||||||
else
|
else
|
||||||
puts "Subversion test repository NOT FOUND. Skipping unit tests !!!"
|
puts "Subversion test repository NOT FOUND. Skipping unit tests !!!"
|
||||||
def test_fake; assert true end
|
def test_fake; assert true end
|
||||||
|
|
Loading…
Reference in New Issue