Mercurial > hg > soundsoftware-site
comparison app/models/changeset.rb @ 909:cbb26bc654de redmine-1.3
Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author | Chris Cannam |
---|---|
date | Fri, 24 Feb 2012 19:09:32 +0000 |
parents | cbce1fd3b1b7 |
children | 5e80956cc792 5f33065ddc4b |
comparison
equal
deleted
inserted
replaced
908:c6c2cbd0afee | 909:cbb26bc654de |
---|---|
20 class Changeset < ActiveRecord::Base | 20 class Changeset < ActiveRecord::Base |
21 belongs_to :repository | 21 belongs_to :repository |
22 belongs_to :user | 22 belongs_to :user |
23 has_many :changes, :dependent => :delete_all | 23 has_many :changes, :dependent => :delete_all |
24 has_and_belongs_to_many :issues | 24 has_and_belongs_to_many :issues |
25 has_and_belongs_to_many :parents, | |
26 :class_name => "Changeset", | |
27 :join_table => "#{table_name_prefix}changeset_parents#{table_name_suffix}", | |
28 :association_foreign_key => 'parent_id', :foreign_key => 'changeset_id' | |
29 has_and_belongs_to_many :children, | |
30 :class_name => "Changeset", | |
31 :join_table => "#{table_name_prefix}changeset_parents#{table_name_suffix}", | |
32 :association_foreign_key => 'changeset_id', :foreign_key => 'parent_id' | |
25 | 33 |
26 acts_as_event :title => Proc.new {|o| "#{l(:label_revision)} #{o.format_identifier}" + (o.short_comments.blank? ? '' : (': ' + o.short_comments))}, | 34 acts_as_event :title => Proc.new {|o| "#{l(:label_revision)} #{o.format_identifier}" + (o.short_comments.blank? ? '' : (': ' + o.short_comments))}, |
27 :description => :long_comments, | 35 :description => :long_comments, |
28 :datetime => :committed_on, | 36 :datetime => :committed_on, |
29 :url => Proc.new {|o| {:controller => 'repositories', :action => 'revision', :id => o.repository.project, :rev => o.identifier}} | 37 :url => Proc.new {|o| {:controller => 'repositories', :action => 'revision', :id => o.repository.project, :rev => o.identifier}} |
41 validates_uniqueness_of :revision, :scope => :repository_id | 49 validates_uniqueness_of :revision, :scope => :repository_id |
42 validates_uniqueness_of :scmid, :scope => :repository_id, :allow_nil => true | 50 validates_uniqueness_of :scmid, :scope => :repository_id, :allow_nil => true |
43 | 51 |
44 named_scope :visible, lambda {|*args| { :include => {:repository => :project}, | 52 named_scope :visible, lambda {|*args| { :include => {:repository => :project}, |
45 :conditions => Project.allowed_to_condition(args.shift || User.current, :view_changesets, *args) } } | 53 :conditions => Project.allowed_to_condition(args.shift || User.current, :view_changesets, *args) } } |
54 | |
55 after_create :scan_for_issues | |
56 before_create :before_create_cs | |
46 | 57 |
47 def revision=(r) | 58 def revision=(r) |
48 write_attribute :revision, (r.nil? ? nil : r.to_s) | 59 write_attribute :revision, (r.nil? ? nil : r.to_s) |
49 end | 60 end |
50 | 61 |
77 | 88 |
78 def author | 89 def author |
79 user || committer.to_s.split('<').first | 90 user || committer.to_s.split('<').first |
80 end | 91 end |
81 | 92 |
82 def before_create | 93 def before_create_cs |
83 self.committer = self.class.to_utf8(self.committer, repository.repo_log_encoding) | 94 self.committer = self.class.to_utf8(self.committer, repository.repo_log_encoding) |
84 self.comments = self.class.normalize_comments( | 95 self.comments = self.class.normalize_comments( |
85 self.comments, repository.repo_log_encoding) | 96 self.comments, repository.repo_log_encoding) |
86 self.user = repository.find_committer_user(self.committer) | 97 self.user = repository.find_committer_user(self.committer) |
87 end | 98 end |
88 | 99 |
89 def after_create | 100 def scan_for_issues |
90 scan_comment_for_issue_ids | 101 scan_comment_for_issue_ids |
91 end | 102 end |
92 | 103 |
93 TIMELOG_RE = / | 104 TIMELOG_RE = / |
94 ( | 105 ( |
191 end | 202 end |
192 | 203 |
193 def fix_issue(issue) | 204 def fix_issue(issue) |
194 status = IssueStatus.find_by_id(Setting.commit_fix_status_id.to_i) | 205 status = IssueStatus.find_by_id(Setting.commit_fix_status_id.to_i) |
195 if status.nil? | 206 if status.nil? |
196 logger.warn("No status macthes commit_fix_status_id setting (#{Setting.commit_fix_status_id})") if logger | 207 logger.warn("No status matches commit_fix_status_id setting (#{Setting.commit_fix_status_id})") if logger |
197 return issue | 208 return issue |
198 end | 209 end |
199 | 210 |
200 # the issue may have been updated by the closure of another one (eg. duplicate) | 211 # the issue may have been updated by the closure of another one (eg. duplicate) |
201 issue.reload | 212 issue.reload |
251 def self.normalize_comments(str, encoding) | 262 def self.normalize_comments(str, encoding) |
252 Changeset.to_utf8(str.to_s.strip, encoding) | 263 Changeset.to_utf8(str.to_s.strip, encoding) |
253 end | 264 end |
254 | 265 |
255 def self.to_utf8(str, encoding) | 266 def self.to_utf8(str, encoding) |
256 return str if str.nil? | 267 Redmine::CodesetUtil.to_utf8(str, encoding) |
257 str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding) | |
258 if str.empty? | |
259 str.force_encoding("UTF-8") if str.respond_to?(:force_encoding) | |
260 return str | |
261 end | |
262 enc = encoding.blank? ? "UTF-8" : encoding | |
263 if str.respond_to?(:force_encoding) | |
264 if enc.upcase != "UTF-8" | |
265 str.force_encoding(enc) | |
266 str = str.encode("UTF-8", :invalid => :replace, | |
267 :undef => :replace, :replace => '?') | |
268 else | |
269 str.force_encoding("UTF-8") | |
270 if ! str.valid_encoding? | |
271 str = str.encode("US-ASCII", :invalid => :replace, | |
272 :undef => :replace, :replace => '?').encode("UTF-8") | |
273 end | |
274 end | |
275 else | |
276 ic = Iconv.new('UTF-8', enc) | |
277 txtar = "" | |
278 begin | |
279 txtar += ic.iconv(str) | |
280 rescue Iconv::IllegalSequence | |
281 txtar += $!.success | |
282 str = '?' + $!.failed[1,$!.failed.length] | |
283 retry | |
284 rescue | |
285 txtar += $!.success | |
286 end | |
287 str = txtar | |
288 end | |
289 str | |
290 end | 268 end |
291 end | 269 end |