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
end
end
end
-
+
def committers
@committers = @repository.committers
@users = @project.users
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
render_404
end
end
-
+
private
REV_PARAM_RE = %r{\A[a-f0-9]*\Z}i
@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
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,
: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)
: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)