@@ -1,327 +1,327 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require 'SVG/Graph/Bar' |
|
19 | 19 | require 'SVG/Graph/BarHorizontal' |
|
20 | 20 | require 'digest/sha1' |
|
21 | 21 | |
|
22 | 22 | class ChangesetNotFound < Exception; end |
|
23 | 23 | class InvalidRevisionParam < Exception; end |
|
24 | 24 | |
|
25 | 25 | class RepositoriesController < ApplicationController |
|
26 | 26 | menu_item :repository |
|
27 | 27 | before_filter :find_repository, :except => :edit |
|
28 | 28 | before_filter :find_project, :only => :edit |
|
29 | 29 | before_filter :authorize |
|
30 | 30 | accept_key_auth :revisions |
|
31 | 31 | |
|
32 | 32 | rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed |
|
33 | 33 | |
|
34 | 34 | def edit |
|
35 | 35 | @repository = @project.repository |
|
36 | 36 | if !@repository |
|
37 | 37 | @repository = Repository.factory(params[:repository_scm]) |
|
38 | 38 | @repository.project = @project if @repository |
|
39 | 39 | end |
|
40 | 40 | if request.post? && @repository |
|
41 | 41 | @repository.attributes = params[:repository] |
|
42 | 42 | @repository.save |
|
43 | 43 | end |
|
44 | 44 | render(:update) {|page| page.replace_html "tab-content-repository", :partial => 'projects/settings/repository'} |
|
45 | 45 | end |
|
46 | 46 | |
|
47 | 47 | def committers |
|
48 | 48 | @committers = @repository.committers |
|
49 | 49 | @users = @project.users |
|
50 | 50 | additional_user_ids = @committers.collect(&:last).collect(&:to_i) - @users.collect(&:id) |
|
51 | 51 | @users += User.find_all_by_id(additional_user_ids) unless additional_user_ids.empty? |
|
52 | 52 | @users.compact! |
|
53 | 53 | @users.sort! |
|
54 | 54 | if request.post? && params[:committers].is_a?(Hash) |
|
55 | 55 | # Build a hash with repository usernames as keys and corresponding user ids as values |
|
56 | 56 | @repository.committer_ids = params[:committers].values.inject({}) {|h, c| h[c.first] = c.last; h} |
|
57 | 57 | flash[:notice] = l(:notice_successful_update) |
|
58 | 58 | redirect_to :action => 'committers', :id => @project |
|
59 | 59 | end |
|
60 | 60 | end |
|
61 | 61 | |
|
62 | 62 | def destroy |
|
63 | 63 | @repository.destroy |
|
64 | 64 | redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'repository' |
|
65 | 65 | end |
|
66 | 66 | |
|
67 | 67 | def show |
|
68 | 68 | # check if new revisions have been committed in the repository |
|
69 | 69 | @repository.fetch_changesets if Setting.autofetch_changesets? |
|
70 | 70 | # root entries |
|
71 | 71 | @entries = @repository.entries('', @rev) |
|
72 | 72 | # latest changesets |
|
73 | 73 | @changesets = @repository.changesets.find(:all, :limit => 10, :order => "committed_on DESC") |
|
74 | 74 | show_error_not_found unless @entries || @changesets.any? |
|
75 | 75 | end |
|
76 | 76 | |
|
77 | 77 | def browse |
|
78 | 78 | @entries = @repository.entries(@path, @rev) |
|
79 | 79 | if request.xhr? |
|
80 | 80 | @entries ? render(:partial => 'dir_list_content') : render(:nothing => true) |
|
81 | 81 | else |
|
82 | 82 | show_error_not_found and return unless @entries |
|
83 | 83 | @properties = @repository.properties(@path, @rev) |
|
84 | 84 | render :action => 'browse' |
|
85 | 85 | end |
|
86 | 86 | end |
|
87 | 87 | |
|
88 | 88 | def changes |
|
89 | 89 | @entry = @repository.entry(@path, @rev) |
|
90 | 90 | show_error_not_found and return unless @entry |
|
91 | 91 | @changesets = @repository.changesets_for_path(@path, :limit => Setting.repository_log_display_limit.to_i) |
|
92 | 92 | @properties = @repository.properties(@path, @rev) |
|
93 | 93 | end |
|
94 | 94 | |
|
95 | 95 | def revisions |
|
96 | 96 | @changeset_count = @repository.changesets.count |
|
97 | 97 | @changeset_pages = Paginator.new self, @changeset_count, |
|
98 | 98 | per_page_option, |
|
99 | 99 | params['page'] |
|
100 | 100 | @changesets = @repository.changesets.find(:all, |
|
101 | 101 | :limit => @changeset_pages.items_per_page, |
|
102 | 102 | :offset => @changeset_pages.current.offset, |
|
103 | :include => :user) | |
|
103 | :include => [:user, :repository]) | |
|
104 | 104 | |
|
105 | 105 | respond_to do |format| |
|
106 | 106 | format.html { render :layout => false if request.xhr? } |
|
107 | 107 | format.atom { render_feed(@changesets, :title => "#{@project.name}: #{l(:label_revision_plural)}") } |
|
108 | 108 | end |
|
109 | 109 | end |
|
110 | 110 | |
|
111 | 111 | def entry |
|
112 | 112 | @entry = @repository.entry(@path, @rev) |
|
113 | 113 | show_error_not_found and return unless @entry |
|
114 | 114 | |
|
115 | 115 | # If the entry is a dir, show the browser |
|
116 | 116 | browse and return if @entry.is_dir? |
|
117 | 117 | |
|
118 | 118 | @content = @repository.cat(@path, @rev) |
|
119 | 119 | show_error_not_found and return unless @content |
|
120 | 120 | if 'raw' == params[:format] || @content.is_binary_data? || (@entry.size && @entry.size > Setting.file_max_size_displayed.to_i.kilobyte) |
|
121 | 121 | # Force the download |
|
122 | 122 | send_data @content, :filename => @path.split('/').last |
|
123 | 123 | else |
|
124 | 124 | # Prevent empty lines when displaying a file with Windows style eol |
|
125 | 125 | @content.gsub!("\r\n", "\n") |
|
126 | 126 | end |
|
127 | 127 | end |
|
128 | 128 | |
|
129 | 129 | def annotate |
|
130 | 130 | @entry = @repository.entry(@path, @rev) |
|
131 | 131 | show_error_not_found and return unless @entry |
|
132 | 132 | |
|
133 | 133 | @annotate = @repository.scm.annotate(@path, @rev) |
|
134 | 134 | render_error l(:error_scm_annotate) and return if @annotate.nil? || @annotate.empty? |
|
135 | 135 | end |
|
136 | 136 | |
|
137 | 137 | def revision |
|
138 | 138 | @changeset = @repository.changesets.find_by_revision(@rev) |
|
139 | 139 | raise ChangesetNotFound unless @changeset |
|
140 | 140 | |
|
141 | 141 | respond_to do |format| |
|
142 | 142 | format.html |
|
143 | 143 | format.js {render :layout => false} |
|
144 | 144 | end |
|
145 | 145 | rescue ChangesetNotFound |
|
146 | 146 | show_error_not_found |
|
147 | 147 | end |
|
148 | 148 | |
|
149 | 149 | def diff |
|
150 | 150 | if params[:format] == 'diff' |
|
151 | 151 | @diff = @repository.diff(@path, @rev, @rev_to) |
|
152 | 152 | show_error_not_found and return unless @diff |
|
153 | 153 | filename = "changeset_r#{@rev}" |
|
154 | 154 | filename << "_r#{@rev_to}" if @rev_to |
|
155 | 155 | send_data @diff.join, :filename => "#{filename}.diff", |
|
156 | 156 | :type => 'text/x-patch', |
|
157 | 157 | :disposition => 'attachment' |
|
158 | 158 | else |
|
159 | 159 | @diff_type = params[:type] || User.current.pref[:diff_type] || 'inline' |
|
160 | 160 | @diff_type = 'inline' unless %w(inline sbs).include?(@diff_type) |
|
161 | 161 | |
|
162 | 162 | # Save diff type as user preference |
|
163 | 163 | if User.current.logged? && @diff_type != User.current.pref[:diff_type] |
|
164 | 164 | User.current.pref[:diff_type] = @diff_type |
|
165 | 165 | User.current.preference.save |
|
166 | 166 | end |
|
167 | 167 | |
|
168 | 168 | @cache_key = "repositories/diff/#{@repository.id}/" + Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}") |
|
169 | 169 | unless read_fragment(@cache_key) |
|
170 | 170 | @diff = @repository.diff(@path, @rev, @rev_to) |
|
171 | 171 | show_error_not_found unless @diff |
|
172 | 172 | end |
|
173 | 173 | end |
|
174 | 174 | end |
|
175 | 175 | |
|
176 | 176 | def stats |
|
177 | 177 | end |
|
178 | 178 | |
|
179 | 179 | def graph |
|
180 | 180 | data = nil |
|
181 | 181 | case params[:graph] |
|
182 | 182 | when "commits_per_month" |
|
183 | 183 | data = graph_commits_per_month(@repository) |
|
184 | 184 | when "commits_per_author" |
|
185 | 185 | data = graph_commits_per_author(@repository) |
|
186 | 186 | end |
|
187 | 187 | if data |
|
188 | 188 | headers["Content-Type"] = "image/svg+xml" |
|
189 | 189 | send_data(data, :type => "image/svg+xml", :disposition => "inline") |
|
190 | 190 | else |
|
191 | 191 | render_404 |
|
192 | 192 | end |
|
193 | 193 | end |
|
194 | 194 | |
|
195 | 195 | private |
|
196 | 196 | def find_project |
|
197 | 197 | @project = Project.find(params[:id]) |
|
198 | 198 | rescue ActiveRecord::RecordNotFound |
|
199 | 199 | render_404 |
|
200 | 200 | end |
|
201 | 201 | |
|
202 | 202 | REV_PARAM_RE = %r{^[a-f0-9]*$} |
|
203 | 203 | |
|
204 | 204 | def find_repository |
|
205 | 205 | @project = Project.find(params[:id]) |
|
206 | 206 | @repository = @project.repository |
|
207 | 207 | render_404 and return false unless @repository |
|
208 | 208 | @path = params[:path].join('/') unless params[:path].nil? |
|
209 | 209 | @path ||= '' |
|
210 | 210 | @rev = params[:rev] |
|
211 | 211 | @rev_to = params[:rev_to] |
|
212 | 212 | raise InvalidRevisionParam unless @rev.to_s.match(REV_PARAM_RE) && @rev.to_s.match(REV_PARAM_RE) |
|
213 | 213 | rescue ActiveRecord::RecordNotFound |
|
214 | 214 | render_404 |
|
215 | 215 | rescue InvalidRevisionParam |
|
216 | 216 | show_error_not_found |
|
217 | 217 | end |
|
218 | 218 | |
|
219 | 219 | def show_error_not_found |
|
220 | 220 | render_error l(:error_scm_not_found) |
|
221 | 221 | end |
|
222 | 222 | |
|
223 | 223 | # Handler for Redmine::Scm::Adapters::CommandFailed exception |
|
224 | 224 | def show_error_command_failed(exception) |
|
225 | 225 | render_error l(:error_scm_command_failed, exception.message) |
|
226 | 226 | end |
|
227 | 227 | |
|
228 | 228 | def graph_commits_per_month(repository) |
|
229 | 229 | @date_to = Date.today |
|
230 | 230 | @date_from = @date_to << 11 |
|
231 | 231 | @date_from = Date.civil(@date_from.year, @date_from.month, 1) |
|
232 | 232 | commits_by_day = repository.changesets.count(:all, :group => :commit_date, :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to]) |
|
233 | 233 | commits_by_month = [0] * 12 |
|
234 | 234 | commits_by_day.each {|c| commits_by_month[c.first.to_date.months_ago] += c.last } |
|
235 | 235 | |
|
236 | 236 | changes_by_day = repository.changes.count(:all, :group => :commit_date, :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to]) |
|
237 | 237 | changes_by_month = [0] * 12 |
|
238 | 238 | changes_by_day.each {|c| changes_by_month[c.first.to_date.months_ago] += c.last } |
|
239 | 239 | |
|
240 | 240 | fields = [] |
|
241 | 241 | 12.times {|m| fields << month_name(((Date.today.month - 1 - m) % 12) + 1)} |
|
242 | 242 | |
|
243 | 243 | graph = SVG::Graph::Bar.new( |
|
244 | 244 | :height => 300, |
|
245 | 245 | :width => 800, |
|
246 | 246 | :fields => fields.reverse, |
|
247 | 247 | :stack => :side, |
|
248 | 248 | :scale_integers => true, |
|
249 | 249 | :step_x_labels => 2, |
|
250 | 250 | :show_data_values => false, |
|
251 | 251 | :graph_title => l(:label_commits_per_month), |
|
252 | 252 | :show_graph_title => true |
|
253 | 253 | ) |
|
254 | 254 | |
|
255 | 255 | graph.add_data( |
|
256 | 256 | :data => commits_by_month[0..11].reverse, |
|
257 | 257 | :title => l(:label_revision_plural) |
|
258 | 258 | ) |
|
259 | 259 | |
|
260 | 260 | graph.add_data( |
|
261 | 261 | :data => changes_by_month[0..11].reverse, |
|
262 | 262 | :title => l(:label_change_plural) |
|
263 | 263 | ) |
|
264 | 264 | |
|
265 | 265 | graph.burn |
|
266 | 266 | end |
|
267 | 267 | |
|
268 | 268 | def graph_commits_per_author(repository) |
|
269 | 269 | commits_by_author = repository.changesets.count(:all, :group => :committer) |
|
270 | 270 | commits_by_author.sort! {|x, y| x.last <=> y.last} |
|
271 | 271 | |
|
272 | 272 | changes_by_author = repository.changes.count(:all, :group => :committer) |
|
273 | 273 | h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o} |
|
274 | 274 | |
|
275 | 275 | fields = commits_by_author.collect {|r| r.first} |
|
276 | 276 | commits_data = commits_by_author.collect {|r| r.last} |
|
277 | 277 | changes_data = commits_by_author.collect {|r| h[r.first] || 0} |
|
278 | 278 | |
|
279 | 279 | fields = fields + [""]*(10 - fields.length) if fields.length<10 |
|
280 | 280 | commits_data = commits_data + [0]*(10 - commits_data.length) if commits_data.length<10 |
|
281 | 281 | changes_data = changes_data + [0]*(10 - changes_data.length) if changes_data.length<10 |
|
282 | 282 | |
|
283 | 283 | # Remove email adress in usernames |
|
284 | 284 | fields = fields.collect {|c| c.gsub(%r{<.+@.+>}, '') } |
|
285 | 285 | |
|
286 | 286 | graph = SVG::Graph::BarHorizontal.new( |
|
287 | 287 | :height => 400, |
|
288 | 288 | :width => 800, |
|
289 | 289 | :fields => fields, |
|
290 | 290 | :stack => :side, |
|
291 | 291 | :scale_integers => true, |
|
292 | 292 | :show_data_values => false, |
|
293 | 293 | :rotate_y_labels => false, |
|
294 | 294 | :graph_title => l(:label_commits_per_author), |
|
295 | 295 | :show_graph_title => true |
|
296 | 296 | ) |
|
297 | 297 | |
|
298 | 298 | graph.add_data( |
|
299 | 299 | :data => commits_data, |
|
300 | 300 | :title => l(:label_revision_plural) |
|
301 | 301 | ) |
|
302 | 302 | |
|
303 | 303 | graph.add_data( |
|
304 | 304 | :data => changes_data, |
|
305 | 305 | :title => l(:label_change_plural) |
|
306 | 306 | ) |
|
307 | 307 | |
|
308 | 308 | graph.burn |
|
309 | 309 | end |
|
310 | 310 | |
|
311 | 311 | end |
|
312 | 312 | |
|
313 | 313 | class Date |
|
314 | 314 | def months_ago(date = Date.today) |
|
315 | 315 | (date.year - self.year)*12 + (date.month - self.month) |
|
316 | 316 | end |
|
317 | 317 | |
|
318 | 318 | def weeks_ago(date = Date.today) |
|
319 | 319 | (date.year - self.year)*52 + (date.cweek - self.cweek) |
|
320 | 320 | end |
|
321 | 321 | end |
|
322 | 322 | |
|
323 | 323 | class String |
|
324 | 324 | def with_leading_slash |
|
325 | 325 | starts_with?('/') ? self : "/#{self}" |
|
326 | 326 | end |
|
327 | 327 | end |
@@ -1,168 +1,168 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2008 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require 'iconv' |
|
19 | 19 | |
|
20 | 20 | class Changeset < ActiveRecord::Base |
|
21 | 21 | belongs_to :repository |
|
22 | 22 | belongs_to :user |
|
23 | 23 | has_many :changes, :dependent => :delete_all |
|
24 | 24 | has_and_belongs_to_many :issues |
|
25 | 25 | |
|
26 | 26 | acts_as_event :title => Proc.new {|o| "#{l(:label_revision)} #{o.revision}" + (o.short_comments.blank? ? '' : (': ' + o.short_comments))}, |
|
27 | 27 | :description => :long_comments, |
|
28 | 28 | :datetime => :committed_on, |
|
29 |
:url => Proc.new {|o| {:controller => 'repositories', :action => 'revision', :id => o.repository.project |
|
|
29 | :url => Proc.new {|o| {:controller => 'repositories', :action => 'revision', :id => o.repository.project, :rev => o.revision}} | |
|
30 | 30 | |
|
31 | 31 | acts_as_searchable :columns => 'comments', |
|
32 | 32 | :include => {:repository => :project}, |
|
33 | 33 | :project_key => "#{Repository.table_name}.project_id", |
|
34 | 34 | :date_column => 'committed_on' |
|
35 | 35 | |
|
36 | 36 | acts_as_activity_provider :timestamp => "#{table_name}.committed_on", |
|
37 | 37 | :author_key => :user_id, |
|
38 | :find_options => {:include => {:repository => :project}} | |
|
38 | :find_options => {:include => [:user, {:repository => :project}]} | |
|
39 | 39 | |
|
40 | 40 | validates_presence_of :repository_id, :revision, :committed_on, :commit_date |
|
41 | 41 | validates_uniqueness_of :revision, :scope => :repository_id |
|
42 | 42 | validates_uniqueness_of :scmid, :scope => :repository_id, :allow_nil => true |
|
43 | 43 | |
|
44 | 44 | def revision=(r) |
|
45 | 45 | write_attribute :revision, (r.nil? ? nil : r.to_s) |
|
46 | 46 | end |
|
47 | 47 | |
|
48 | 48 | def comments=(comment) |
|
49 | 49 | write_attribute(:comments, Changeset.normalize_comments(comment)) |
|
50 | 50 | end |
|
51 | 51 | |
|
52 | 52 | def committed_on=(date) |
|
53 | 53 | self.commit_date = date |
|
54 | 54 | super |
|
55 | 55 | end |
|
56 | 56 | |
|
57 | 57 | def project |
|
58 | 58 | repository.project |
|
59 | 59 | end |
|
60 | 60 | |
|
61 | 61 | def author |
|
62 | 62 | user || committer.to_s.split('<').first |
|
63 | 63 | end |
|
64 | 64 | |
|
65 | 65 | def before_create |
|
66 | 66 | self.user = repository.find_committer_user(committer) |
|
67 | 67 | end |
|
68 | 68 | |
|
69 | 69 | def after_create |
|
70 | 70 | scan_comment_for_issue_ids |
|
71 | 71 | end |
|
72 | 72 | require 'pp' |
|
73 | 73 | |
|
74 | 74 | def scan_comment_for_issue_ids |
|
75 | 75 | return if comments.blank? |
|
76 | 76 | # keywords used to reference issues |
|
77 | 77 | ref_keywords = Setting.commit_ref_keywords.downcase.split(",").collect(&:strip) |
|
78 | 78 | # keywords used to fix issues |
|
79 | 79 | fix_keywords = Setting.commit_fix_keywords.downcase.split(",").collect(&:strip) |
|
80 | 80 | # status and optional done ratio applied |
|
81 | 81 | fix_status = IssueStatus.find_by_id(Setting.commit_fix_status_id) |
|
82 | 82 | done_ratio = Setting.commit_fix_done_ratio.blank? ? nil : Setting.commit_fix_done_ratio.to_i |
|
83 | 83 | |
|
84 | 84 | kw_regexp = (ref_keywords + fix_keywords).collect{|kw| Regexp.escape(kw)}.join("|") |
|
85 | 85 | return if kw_regexp.blank? |
|
86 | 86 | |
|
87 | 87 | referenced_issues = [] |
|
88 | 88 | |
|
89 | 89 | if ref_keywords.delete('*') |
|
90 | 90 | # find any issue ID in the comments |
|
91 | 91 | target_issue_ids = [] |
|
92 | 92 | comments.scan(%r{([\s\(,-]|^)#(\d+)(?=[[:punct:]]|\s|<|$)}).each { |m| target_issue_ids << m[1] } |
|
93 | 93 | referenced_issues += repository.project.issues.find_all_by_id(target_issue_ids) |
|
94 | 94 | end |
|
95 | 95 | |
|
96 | 96 | comments.scan(Regexp.new("(#{kw_regexp})[\s:]+(([\s,;&]*#?\\d+)+)", Regexp::IGNORECASE)).each do |match| |
|
97 | 97 | action = match[0] |
|
98 | 98 | target_issue_ids = match[1].scan(/\d+/) |
|
99 | 99 | target_issues = repository.project.issues.find_all_by_id(target_issue_ids) |
|
100 | 100 | if fix_status && fix_keywords.include?(action.downcase) |
|
101 | 101 | # update status of issues |
|
102 | 102 | logger.debug "Issues fixed by changeset #{self.revision}: #{issue_ids.join(', ')}." if logger && logger.debug? |
|
103 | 103 | target_issues.each do |issue| |
|
104 | 104 | # the issue may have been updated by the closure of another one (eg. duplicate) |
|
105 | 105 | issue.reload |
|
106 | 106 | # don't change the status is the issue is closed |
|
107 | 107 | next if issue.status.is_closed? |
|
108 | 108 | csettext = "r#{self.revision}" |
|
109 | 109 | if self.scmid && (! (csettext =~ /^r[0-9]+$/)) |
|
110 | 110 | csettext = "commit:\"#{self.scmid}\"" |
|
111 | 111 | end |
|
112 | 112 | journal = issue.init_journal(user || User.anonymous, ll(Setting.default_language, :text_status_changed_by_changeset, csettext)) |
|
113 | 113 | issue.status = fix_status |
|
114 | 114 | issue.done_ratio = done_ratio if done_ratio |
|
115 | 115 | issue.save |
|
116 | 116 | end |
|
117 | 117 | end |
|
118 | 118 | referenced_issues += target_issues |
|
119 | 119 | end |
|
120 | 120 | |
|
121 | 121 | self.issues = referenced_issues.uniq |
|
122 | 122 | end |
|
123 | 123 | |
|
124 | 124 | def short_comments |
|
125 | 125 | @short_comments || split_comments.first |
|
126 | 126 | end |
|
127 | 127 | |
|
128 | 128 | def long_comments |
|
129 | 129 | @long_comments || split_comments.last |
|
130 | 130 | end |
|
131 | 131 | |
|
132 | 132 | # Returns the previous changeset |
|
133 | 133 | def previous |
|
134 | 134 | @previous ||= Changeset.find(:first, :conditions => ['id < ? AND repository_id = ?', self.id, self.repository_id], :order => 'id DESC') |
|
135 | 135 | end |
|
136 | 136 | |
|
137 | 137 | # Returns the next changeset |
|
138 | 138 | def next |
|
139 | 139 | @next ||= Changeset.find(:first, :conditions => ['id > ? AND repository_id = ?', self.id, self.repository_id], :order => 'id ASC') |
|
140 | 140 | end |
|
141 | 141 | |
|
142 | 142 | # Strips and reencodes a commit log before insertion into the database |
|
143 | 143 | def self.normalize_comments(str) |
|
144 | 144 | to_utf8(str.to_s.strip) |
|
145 | 145 | end |
|
146 | 146 | |
|
147 | 147 | private |
|
148 | 148 | |
|
149 | 149 | def split_comments |
|
150 | 150 | comments =~ /\A(.+?)\r?\n(.*)$/m |
|
151 | 151 | @short_comments = $1 || comments |
|
152 | 152 | @long_comments = $2.to_s.strip |
|
153 | 153 | return @short_comments, @long_comments |
|
154 | 154 | end |
|
155 | 155 | |
|
156 | 156 | def self.to_utf8(str) |
|
157 | 157 | return str if /\A[\r\n\t\x20-\x7e]*\Z/n.match(str) # for us-ascii |
|
158 | 158 | encoding = Setting.commit_logs_encoding.to_s.strip |
|
159 | 159 | unless encoding.blank? || encoding == 'UTF-8' |
|
160 | 160 | begin |
|
161 | 161 | return Iconv.conv('UTF-8', encoding, str) |
|
162 | 162 | rescue Iconv::Failure |
|
163 | 163 | # do nothing here |
|
164 | 164 | end |
|
165 | 165 | end |
|
166 | 166 | str |
|
167 | 167 | end |
|
168 | 168 | end |
General Comments 0
You need to be logged in to leave comments.
Login now