@@ -57,10 +57,6 class Changeset < ActiveRecord::Base | |||||
57 | end |
|
57 | end | |
58 | end |
|
58 | end | |
59 |
|
59 | |||
60 | def comments=(comment) |
|
|||
61 | write_attribute(:comments, Changeset.normalize_comments(comment)) |
|
|||
62 | end |
|
|||
63 |
|
||||
64 | def committed_on=(date) |
|
60 | def committed_on=(date) | |
65 | self.commit_date = date |
|
61 | self.commit_date = date | |
66 | super |
|
62 | super | |
@@ -75,10 +71,6 class Changeset < ActiveRecord::Base | |||||
75 | end |
|
71 | end | |
76 | end |
|
72 | end | |
77 |
|
73 | |||
78 | def committer=(arg) |
|
|||
79 | write_attribute(:committer, self.class.to_utf8(arg.to_s)) |
|
|||
80 | end |
|
|||
81 |
|
||||
82 | def project |
|
74 | def project | |
83 | repository.project |
|
75 | repository.project | |
84 | end |
|
76 | end | |
@@ -88,7 +80,9 class Changeset < ActiveRecord::Base | |||||
88 | end |
|
80 | end | |
89 |
|
81 | |||
90 | def before_create |
|
82 | def before_create | |
91 | self.user = repository.find_committer_user(committer) |
|
83 | self.committer = self.class.to_utf8(self.committer, repository.repo_log_encoding) | |
|
84 | self.comments = self.class.normalize_comments(self.comments, repository.repo_log_encoding) | |||
|
85 | self.user = repository.find_committer_user(self.committer) | |||
92 | end |
|
86 | end | |
93 |
|
87 | |||
94 | def after_create |
|
88 | def after_create | |
@@ -163,11 +157,6 class Changeset < ActiveRecord::Base | |||||
163 | @next ||= Changeset.find(:first, :conditions => ['id > ? AND repository_id = ?', self.id, self.repository_id], :order => 'id ASC') |
|
157 | @next ||= Changeset.find(:first, :conditions => ['id > ? AND repository_id = ?', self.id, self.repository_id], :order => 'id ASC') | |
164 | end |
|
158 | end | |
165 |
|
159 | |||
166 | # Strips and reencodes a commit log before insertion into the database |
|
|||
167 | def self.normalize_comments(str) |
|
|||
168 | to_utf8(str.to_s.strip) |
|
|||
169 | end |
|
|||
170 |
|
||||
171 | # Creates a new Change from it's common parameters |
|
160 | # Creates a new Change from it's common parameters | |
172 | def create_change(change) |
|
161 | def create_change(change) | |
173 | Change.create(:changeset => self, |
|
162 | Change.create(:changeset => self, | |
@@ -246,9 +235,17 class Changeset < ActiveRecord::Base | |||||
246 | return @short_comments, @long_comments |
|
235 | return @short_comments, @long_comments | |
247 | end |
|
236 | end | |
248 |
|
237 | |||
249 | def self.to_utf8(str) |
|
238 | public | |
|
239 | ||||
|
240 | # Strips and reencodes a commit log before insertion into the database | |||
|
241 | def self.normalize_comments(str, encoding) | |||
|
242 | Changeset.to_utf8(str.to_s.strip, encoding) | |||
|
243 | end | |||
|
244 | ||||
|
245 | private | |||
|
246 | ||||
|
247 | def self.to_utf8(str, encoding) | |||
250 | return str if str.blank? |
|
248 | return str if str.blank? | |
251 | encoding = Setting.commit_logs_encoding.to_s.strip |
|
|||
252 | unless encoding.blank? || encoding == 'UTF-8' |
|
249 | unless encoding.blank? || encoding == 'UTF-8' | |
253 | begin |
|
250 | begin | |
254 | str = Iconv.conv('UTF-8', encoding, str) |
|
251 | str = Iconv.conv('UTF-8', encoding, str) |
@@ -190,6 +190,11 class Repository < ActiveRecord::Base | |||||
190 | end |
|
190 | end | |
191 | end |
|
191 | end | |
192 |
|
192 | |||
|
193 | def repo_log_encoding | |||
|
194 | encoding = Setting.commit_logs_encoding.to_s.strip | |||
|
195 | encoding.blank? ? 'UTF-8' : encoding | |||
|
196 | end | |||
|
197 | ||||
193 | # Fetches new changesets for all repositories of active projects |
|
198 | # Fetches new changesets for all repositories of active projects | |
194 | # Can be called periodically by an external script |
|
199 | # Can be called periodically by an external script | |
195 | # eg. ruby script/runner "Repository.fetch_changesets" |
|
200 | # eg. ruby script/runner "Repository.fetch_changesets" |
@@ -107,10 +107,11 class Repository::Cvs < Repository | |||||
107 | tmp_time = revision.time.clone |
|
107 | tmp_time = revision.time.clone | |
108 | unless changes.find_by_path_and_revision( |
|
108 | unless changes.find_by_path_and_revision( | |
109 | scm.with_leading_slash(revision.paths[0][:path]), revision.paths[0][:revision]) |
|
109 | scm.with_leading_slash(revision.paths[0][:path]), revision.paths[0][:revision]) | |
|
110 | cmt = Changeset.normalize_comments(revision.message, repo_log_encoding) | |||
110 | cs = changesets.find(:first, :conditions=>{ |
|
111 | cs = changesets.find(:first, :conditions=>{ | |
111 | :committed_on=>tmp_time - time_delta .. tmp_time + time_delta, |
|
112 | :committed_on=>tmp_time - time_delta .. tmp_time + time_delta, | |
112 | :committer=>revision.author, |
|
113 | :committer=>revision.author, | |
113 | :comments=>Changeset.normalize_comments(revision.message) |
|
114 | :comments=>cmt | |
114 | }) |
|
115 | }) | |
115 |
|
116 | |||
116 | # create a new changeset.... |
|
117 | # create a new changeset.... |
@@ -34,6 +34,10 class Repository::Mercurial < Repository | |||||
34 | 'Mercurial' |
|
34 | 'Mercurial' | |
35 | end |
|
35 | end | |
36 |
|
36 | |||
|
37 | def repo_log_encoding | |||
|
38 | 'UTF-8' | |||
|
39 | end | |||
|
40 | ||||
37 | # Returns the readable identifier for the given mercurial changeset |
|
41 | # Returns the readable identifier for the given mercurial changeset | |
38 | def self.format_changeset_identifier(changeset) |
|
42 | def self.format_changeset_identifier(changeset) | |
39 | "#{changeset.revision}:#{changeset.scmid}" |
|
43 | "#{changeset.revision}:#{changeset.scmid}" |
@@ -30,6 +30,10 class Repository::Subversion < Repository | |||||
30 | 'Subversion' |
|
30 | 'Subversion' | |
31 | end |
|
31 | end | |
32 |
|
32 | |||
|
33 | def repo_log_encoding | |||
|
34 | 'UTF-8' | |||
|
35 | end | |||
|
36 | ||||
33 | def latest_changesets(path, rev, limit=10) |
|
37 | def latest_changesets(path, rev, limit=10) | |
34 | revisions = scm.revisions(path, rev, nil, :limit => limit) |
|
38 | revisions = scm.revisions(path, rev, nil, :limit => limit) | |
35 | revisions ? changesets.find_all_by_revision(revisions.collect(&:identifier), :order => "committed_on DESC", :include => :user) : [] |
|
39 | revisions ? changesets.find_all_by_revision(revisions.collect(&:identifier), :order => "committed_on DESC", :include => :user) : [] |
@@ -137,6 +137,28 class RepositorySubversionTest < ActiveSupport::TestCase | |||||
137 | assert c.event_title.include?('123456789:') |
|
137 | assert c.event_title.include?('123456789:') | |
138 | assert_equal '123456789', c.event_url[:rev] |
|
138 | assert_equal '123456789', c.event_url[:rev] | |
139 | end |
|
139 | end | |
|
140 | ||||
|
141 | def test_log_encoding_ignore_setting | |||
|
142 | with_settings :commit_logs_encoding => 'windows-1252' do | |||
|
143 | s1 = "\xC2\x80" | |||
|
144 | s2 = "\xc3\x82\xc2\x80" | |||
|
145 | if s1.respond_to?(:force_encoding) | |||
|
146 | s3 = s1 | |||
|
147 | s4 = s2 | |||
|
148 | s1.force_encoding('ASCII-8BIT') | |||
|
149 | s2.force_encoding('ASCII-8BIT') | |||
|
150 | s3.force_encoding('ISO-8859-1') | |||
|
151 | s4.force_encoding('UTF-8') | |||
|
152 | assert_equal s3.encode('UTF-8'), s4 | |||
|
153 | end | |||
|
154 | c = Changeset.new(:repository => @repository, | |||
|
155 | :comments=>s2, | |||
|
156 | :revision=>'123', | |||
|
157 | :committed_on => Time.now) | |||
|
158 | assert c.save | |||
|
159 | assert_equal s2, c.comments | |||
|
160 | end | |||
|
161 | end | |||
140 | else |
|
162 | else | |
141 | puts "Subversion test repository NOT FOUND. Skipping unit tests !!!" |
|
163 | puts "Subversion test repository NOT FOUND. Skipping unit tests !!!" | |
142 | def test_fake; assert true end |
|
164 | def test_fake; assert true end |
General Comments 0
You need to be logged in to leave comments.
Login now