@@ -26,14 +26,14 class RepositoriesController < ApplicationController | |||||
26 | menu_item :repository |
|
26 | menu_item :repository | |
27 | menu_item :settings, :only => :edit |
|
27 | menu_item :settings, :only => :edit | |
28 | default_search_scope :changesets |
|
28 | default_search_scope :changesets | |
29 |
|
29 | |||
30 | before_filter :find_repository, :except => :edit |
|
30 | before_filter :find_repository, :except => :edit | |
31 | before_filter :find_project, :only => :edit |
|
31 | before_filter :find_project, :only => :edit | |
32 | before_filter :authorize |
|
32 | before_filter :authorize | |
33 | accept_key_auth :revisions |
|
33 | accept_key_auth :revisions | |
34 |
|
34 | |||
35 | rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed |
|
35 | rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed | |
36 |
|
36 | |||
37 | def edit |
|
37 | def edit | |
38 | @repository = @project.repository |
|
38 | @repository = @project.repository | |
39 | if !@repository |
|
39 | if !@repository | |
@@ -52,7 +52,7 class RepositoriesController < ApplicationController | |||||
52 | end |
|
52 | end | |
53 | end |
|
53 | end | |
54 | end |
|
54 | end | |
55 |
|
55 | |||
56 | def committers |
|
56 | def committers | |
57 | @committers = @repository.committers |
|
57 | @committers = @repository.committers | |
58 | @users = @project.users |
|
58 | @users = @project.users | |
@@ -192,8 +192,7 class RepositoriesController < ApplicationController | |||||
192 | User.current.pref[:diff_type] = @diff_type |
|
192 | User.current.pref[:diff_type] = @diff_type | |
193 | User.current.preference.save |
|
193 | User.current.preference.save | |
194 | end |
|
194 | end | |
195 |
|
195 | @cache_key = "repositories/diff/#{@repository.id}/" + Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}") | ||
196 | @cache_key = "repositories/diff/#{@repository.id}/" + Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}") |
|
|||
197 | unless read_fragment(@cache_key) |
|
196 | unless read_fragment(@cache_key) | |
198 | @diff = @repository.diff(@path, @rev, @rev_to) |
|
197 | @diff = @repository.diff(@path, @rev, @rev_to) | |
199 | show_error_not_found unless @diff |
|
198 | show_error_not_found unless @diff | |
@@ -223,7 +222,7 class RepositoriesController < ApplicationController | |||||
223 | render_404 |
|
222 | render_404 | |
224 | end |
|
223 | end | |
225 | end |
|
224 | end | |
226 |
|
225 | |||
227 | private |
|
226 | private | |
228 |
|
227 | |||
229 | REV_PARAM_RE = %r{\A[a-f0-9]*\Z}i |
|
228 | REV_PARAM_RE = %r{\A[a-f0-9]*\Z}i | |
@@ -236,7 +235,7 class RepositoriesController < ApplicationController | |||||
236 | @path ||= '' |
|
235 | @path ||= '' | |
237 | @rev = params[:rev].blank? ? @repository.default_branch : params[:rev].strip |
|
236 | @rev = params[:rev].blank? ? @repository.default_branch : params[:rev].strip | |
238 | @rev_to = params[:rev_to] |
|
237 | @rev_to = params[:rev_to] | |
239 |
|
238 | |||
240 | unless @rev.to_s.match(REV_PARAM_RE) && @rev_to.to_s.match(REV_PARAM_RE) |
|
239 | unless @rev.to_s.match(REV_PARAM_RE) && @rev_to.to_s.match(REV_PARAM_RE) | |
241 | if @repository.branches.blank? |
|
240 | if @repository.branches.blank? | |
242 | raise InvalidRevisionParam |
|
241 | raise InvalidRevisionParam | |
@@ -251,27 +250,31 class RepositoriesController < ApplicationController | |||||
251 | def show_error_not_found |
|
250 | def show_error_not_found | |
252 | render_error :message => l(:error_scm_not_found), :status => 404 |
|
251 | render_error :message => l(:error_scm_not_found), :status => 404 | |
253 | end |
|
252 | end | |
254 |
|
253 | |||
255 | # Handler for Redmine::Scm::Adapters::CommandFailed exception |
|
254 | # Handler for Redmine::Scm::Adapters::CommandFailed exception | |
256 | def show_error_command_failed(exception) |
|
255 | def show_error_command_failed(exception) | |
257 | render_error l(:error_scm_command_failed, exception.message) |
|
256 | render_error l(:error_scm_command_failed, exception.message) | |
258 | end |
|
257 | end | |
259 |
|
258 | |||
260 | def graph_commits_per_month(repository) |
|
259 | def graph_commits_per_month(repository) | |
261 | @date_to = Date.today |
|
260 | @date_to = Date.today | |
262 | @date_from = @date_to << 11 |
|
261 | @date_from = @date_to << 11 | |
263 | @date_from = Date.civil(@date_from.year, @date_from.month, 1) |
|
262 | @date_from = Date.civil(@date_from.year, @date_from.month, 1) | |
264 | commits_by_day = repository.changesets.count(:all, :group => :commit_date, :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to]) |
|
263 | commits_by_day = repository.changesets.count( | |
|
264 | :all, :group => :commit_date, | |||
|
265 | :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to]) | |||
265 | commits_by_month = [0] * 12 |
|
266 | commits_by_month = [0] * 12 | |
266 | commits_by_day.each {|c| commits_by_month[c.first.to_date.months_ago] += c.last } |
|
267 | commits_by_day.each {|c| commits_by_month[c.first.to_date.months_ago] += c.last } | |
267 |
|
268 | |||
268 | changes_by_day = repository.changes.count(:all, :group => :commit_date, :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to]) |
|
269 | changes_by_day = repository.changes.count( | |
|
270 | :all, :group => :commit_date, | |||
|
271 | :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to]) | |||
269 | changes_by_month = [0] * 12 |
|
272 | changes_by_month = [0] * 12 | |
270 | changes_by_day.each {|c| changes_by_month[c.first.to_date.months_ago] += c.last } |
|
273 | changes_by_day.each {|c| changes_by_month[c.first.to_date.months_ago] += c.last } | |
271 |
|
274 | |||
272 | fields = [] |
|
275 | fields = [] | |
273 | 12.times {|m| fields << month_name(((Date.today.month - 1 - m) % 12) + 1)} |
|
276 | 12.times {|m| fields << month_name(((Date.today.month - 1 - m) % 12) + 1)} | |
274 |
|
277 | |||
275 | graph = SVG::Graph::Bar.new( |
|
278 | graph = SVG::Graph::Bar.new( | |
276 | :height => 300, |
|
279 | :height => 300, | |
277 | :width => 800, |
|
280 | :width => 800, | |
@@ -283,7 +286,7 class RepositoriesController < ApplicationController | |||||
283 | :graph_title => l(:label_commits_per_month), |
|
286 | :graph_title => l(:label_commits_per_month), | |
284 | :show_graph_title => true |
|
287 | :show_graph_title => true | |
285 | ) |
|
288 | ) | |
286 |
|
289 | |||
287 | graph.add_data( |
|
290 | graph.add_data( | |
288 | :data => commits_by_month[0..11].reverse, |
|
291 | :data => commits_by_month[0..11].reverse, | |
289 | :title => l(:label_revision_plural) |
|
292 | :title => l(:label_revision_plural) | |
@@ -326,22 +329,18 class RepositoriesController < ApplicationController | |||||
326 | :graph_title => l(:label_commits_per_author), |
|
329 | :graph_title => l(:label_commits_per_author), | |
327 | :show_graph_title => true |
|
330 | :show_graph_title => true | |
328 | ) |
|
331 | ) | |
329 |
|
||||
330 | graph.add_data( |
|
332 | graph.add_data( | |
331 | :data => commits_data, |
|
333 | :data => commits_data, | |
332 | :title => l(:label_revision_plural) |
|
334 | :title => l(:label_revision_plural) | |
333 | ) |
|
335 | ) | |
334 |
|
||||
335 | graph.add_data( |
|
336 | graph.add_data( | |
336 | :data => changes_data, |
|
337 | :data => changes_data, | |
337 | :title => l(:label_change_plural) |
|
338 | :title => l(:label_change_plural) | |
338 | ) |
|
339 | ) | |
339 |
|
||||
340 | graph.burn |
|
340 | graph.burn | |
341 | end |
|
341 | end | |
342 |
|
||||
343 | end |
|
342 | end | |
344 |
|
343 | |||
345 | class Date |
|
344 | class Date | |
346 | def months_ago(date = Date.today) |
|
345 | def months_ago(date = Date.today) | |
347 | (date.year - self.year)*12 + (date.month - self.month) |
|
346 | (date.year - self.year)*12 + (date.month - self.month) |
General Comments 0
You need to be logged in to leave comments.
Login now