From: Toshi MARUYAMA Date: Tue, 3 May 2011 07:32:50 +0000 (+0000) Subject: scm: code clean up RepositoriesController. X-Git-Tag: 1.2.0~270 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ca5ce92cfcb93a327717d4cf6fd4a0d2d259701f;p=redmine.git scm: code clean up RepositoriesController. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5617 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 475472509..dd7d709e2 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -26,14 +26,14 @@ class RepositoriesController < ApplicationController menu_item :repository menu_item :settings, :only => :edit default_search_scope :changesets - + before_filter :find_repository, :except => :edit before_filter :find_project, :only => :edit before_filter :authorize accept_key_auth :revisions - + rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed - + def edit @repository = @project.repository if !@repository @@ -52,7 +52,7 @@ class RepositoriesController < ApplicationController end end end - + def committers @committers = @repository.committers @users = @project.users @@ -192,8 +192,7 @@ class RepositoriesController < ApplicationController User.current.pref[:diff_type] = @diff_type User.current.preference.save end - - @cache_key = "repositories/diff/#{@repository.id}/" + Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}") + @cache_key = "repositories/diff/#{@repository.id}/" + Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}") unless read_fragment(@cache_key) @diff = @repository.diff(@path, @rev, @rev_to) show_error_not_found unless @diff @@ -223,7 +222,7 @@ class RepositoriesController < ApplicationController render_404 end end - + private REV_PARAM_RE = %r{\A[a-f0-9]*\Z}i @@ -236,7 +235,7 @@ class RepositoriesController < ApplicationController @path ||= '' @rev = params[:rev].blank? ? @repository.default_branch : params[:rev].strip @rev_to = params[:rev_to] - + unless @rev.to_s.match(REV_PARAM_RE) && @rev_to.to_s.match(REV_PARAM_RE) if @repository.branches.blank? raise InvalidRevisionParam @@ -251,27 +250,31 @@ class RepositoriesController < ApplicationController def show_error_not_found render_error :message => l(:error_scm_not_found), :status => 404 end - + # Handler for Redmine::Scm::Adapters::CommandFailed exception def show_error_command_failed(exception) render_error l(:error_scm_command_failed, exception.message) end - + def graph_commits_per_month(repository) @date_to = Date.today @date_from = @date_to << 11 @date_from = Date.civil(@date_from.year, @date_from.month, 1) - commits_by_day = repository.changesets.count(:all, :group => :commit_date, :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to]) + commits_by_day = repository.changesets.count( + :all, :group => :commit_date, + :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to]) commits_by_month = [0] * 12 commits_by_day.each {|c| commits_by_month[c.first.to_date.months_ago] += c.last } - changes_by_day = repository.changes.count(:all, :group => :commit_date, :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to]) + changes_by_day = repository.changes.count( + :all, :group => :commit_date, + :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to]) changes_by_month = [0] * 12 changes_by_day.each {|c| changes_by_month[c.first.to_date.months_ago] += c.last } - + fields = [] 12.times {|m| fields << month_name(((Date.today.month - 1 - m) % 12) + 1)} - + graph = SVG::Graph::Bar.new( :height => 300, :width => 800, @@ -283,7 +286,7 @@ class RepositoriesController < ApplicationController :graph_title => l(:label_commits_per_month), :show_graph_title => true ) - + graph.add_data( :data => commits_by_month[0..11].reverse, :title => l(:label_revision_plural) @@ -326,22 +329,18 @@ class RepositoriesController < ApplicationController :graph_title => l(:label_commits_per_author), :show_graph_title => true ) - graph.add_data( :data => commits_data, :title => l(:label_revision_plural) ) - graph.add_data( :data => changes_data, :title => l(:label_change_plural) ) - graph.burn end - end - + class Date def months_ago(date = Date.today) (date.year - self.year)*12 + (date.month - self.month)