2009-08-17 18:26:13 +04:00
|
|
|
# Redmine - project management software
|
2012-01-07 23:02:10 +04:00
|
|
|
# Copyright (C) 2006-2012 Jean-Philippe Lang
|
2006-12-24 16:38:45 +03:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
2011-05-21 10:15:34 +04:00
|
|
|
#
|
2006-12-24 16:38:45 +03:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2011-05-21 10:15:34 +04:00
|
|
|
#
|
2006-12-24 16:38:45 +03:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
2007-03-25 21:11:46 +04:00
|
|
|
require 'SVG/Graph/Bar'
|
|
|
|
require 'SVG/Graph/BarHorizontal'
|
2007-05-02 00:56:19 +04:00
|
|
|
require 'digest/sha1'
|
2012-04-25 21:17:49 +04:00
|
|
|
require 'redmine/scm/adapters/abstract_adapter'
|
2007-03-25 21:11:46 +04:00
|
|
|
|
2008-04-03 20:50:53 +04:00
|
|
|
class ChangesetNotFound < Exception; end
|
|
|
|
class InvalidRevisionParam < Exception; end
|
2007-12-01 20:15:42 +03:00
|
|
|
|
2006-12-24 16:38:45 +03:00
|
|
|
class RepositoriesController < ApplicationController
|
2008-01-19 14:53:43 +03:00
|
|
|
menu_item :repository
|
2012-01-15 18:23:06 +04:00
|
|
|
menu_item :settings, :only => [:new, :create, :edit, :update, :destroy, :committers]
|
2009-10-21 21:07:18 +04:00
|
|
|
default_search_scope :changesets
|
2011-05-03 11:32:50 +04:00
|
|
|
|
2012-01-15 18:23:06 +04:00
|
|
|
before_filter :find_project_by_project_id, :only => [:new, :create]
|
|
|
|
before_filter :find_repository, :only => [:edit, :update, :destroy, :committers]
|
|
|
|
before_filter :find_project_repository, :except => [:new, :create, :edit, :update, :destroy, :committers]
|
2012-02-05 14:56:27 +04:00
|
|
|
before_filter :find_changeset, :only => [:revision, :add_related_issue, :remove_related_issue]
|
2007-09-14 15:34:08 +04:00
|
|
|
before_filter :authorize
|
2011-07-09 12:56:07 +04:00
|
|
|
accept_rss_auth :revisions
|
2011-05-03 11:32:50 +04:00
|
|
|
|
2008-06-15 20:11:07 +04:00
|
|
|
rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed
|
2011-05-03 11:32:50 +04:00
|
|
|
|
2012-01-15 18:23:06 +04:00
|
|
|
def new
|
2012-01-16 02:23:56 +04:00
|
|
|
scm = params[:repository_scm] || (Redmine::Scm::Base.all & Setting.enabled_scm).first
|
2012-01-15 18:23:06 +04:00
|
|
|
@repository = Repository.factory(scm)
|
2012-01-15 22:19:19 +04:00
|
|
|
@repository.is_default = @project.repository.nil?
|
2012-01-15 18:23:06 +04:00
|
|
|
@repository.project = @project
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2012-05-03 15:48:33 +04:00
|
|
|
attrs = pickup_extra_info
|
2012-06-19 23:47:54 +04:00
|
|
|
@repository = Repository.factory(params[:repository_scm])
|
|
|
|
@repository.safe_attributes = params[:repository]
|
2012-05-03 15:48:33 +04:00
|
|
|
if attrs[:attrs_extra].keys.any?
|
|
|
|
@repository.merge_extra_info(attrs[:attrs_extra])
|
|
|
|
end
|
2012-01-15 18:23:06 +04:00
|
|
|
@repository.project = @project
|
|
|
|
if request.post? && @repository.save
|
|
|
|
redirect_to settings_project_path(@project, :tab => 'repositories')
|
|
|
|
else
|
|
|
|
render :action => 'new'
|
2007-09-14 15:34:08 +04:00
|
|
|
end
|
2012-01-15 18:23:06 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2012-05-03 15:48:33 +04:00
|
|
|
attrs = pickup_extra_info
|
2012-06-19 23:47:54 +04:00
|
|
|
@repository.safe_attributes = attrs[:attrs]
|
2012-05-03 15:48:33 +04:00
|
|
|
if attrs[:attrs_extra].keys.any?
|
|
|
|
@repository.merge_extra_info(attrs[:attrs_extra])
|
|
|
|
end
|
2012-01-15 18:23:06 +04:00
|
|
|
@repository.project = @project
|
|
|
|
if request.put? && @repository.save
|
|
|
|
redirect_to settings_project_path(@project, :tab => 'repositories')
|
|
|
|
else
|
|
|
|
render :action => 'edit'
|
2010-04-17 16:51:46 +04:00
|
|
|
end
|
2007-09-14 15:34:08 +04:00
|
|
|
end
|
2011-05-03 11:32:50 +04:00
|
|
|
|
2012-05-03 15:48:33 +04:00
|
|
|
def pickup_extra_info
|
|
|
|
p = {}
|
|
|
|
p_extra = {}
|
|
|
|
params[:repository].each do |k, v|
|
|
|
|
if k =~ /^extra_/
|
|
|
|
p_extra[k] = v
|
|
|
|
else
|
|
|
|
p[k] = v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
{:attrs => p, :attrs_extra => p_extra}
|
|
|
|
end
|
|
|
|
private :pickup_extra_info
|
|
|
|
|
2008-11-10 21:59:06 +03:00
|
|
|
def committers
|
|
|
|
@committers = @repository.committers
|
|
|
|
@users = @project.users
|
|
|
|
additional_user_ids = @committers.collect(&:last).collect(&:to_i) - @users.collect(&:id)
|
|
|
|
@users += User.find_all_by_id(additional_user_ids) unless additional_user_ids.empty?
|
|
|
|
@users.compact!
|
|
|
|
@users.sort!
|
2008-12-15 21:02:25 +03:00
|
|
|
if request.post? && params[:committers].is_a?(Hash)
|
|
|
|
# Build a hash with repository usernames as keys and corresponding user ids as values
|
|
|
|
@repository.committer_ids = params[:committers].values.inject({}) {|h, c| h[c.first] = c.last; h}
|
2008-11-10 21:59:06 +03:00
|
|
|
flash[:notice] = l(:notice_successful_update)
|
2012-01-15 18:23:06 +04:00
|
|
|
redirect_to settings_project_path(@project, :tab => 'repositories')
|
2008-11-10 21:59:06 +03:00
|
|
|
end
|
|
|
|
end
|
2011-02-12 12:44:46 +03:00
|
|
|
|
2007-09-14 15:34:08 +04:00
|
|
|
def destroy
|
2012-01-15 18:23:06 +04:00
|
|
|
@repository.destroy if request.delete?
|
|
|
|
redirect_to settings_project_path(@project, :tab => 'repositories')
|
2007-09-14 15:34:08 +04:00
|
|
|
end
|
2011-02-12 12:44:46 +03:00
|
|
|
|
|
|
|
def show
|
2009-08-16 02:41:40 +04:00
|
|
|
@repository.fetch_changesets if Setting.autofetch_changesets? && @path.empty?
|
|
|
|
|
2007-06-13 00:12:05 +04:00
|
|
|
@entries = @repository.entries(@path, @rev)
|
2011-03-15 11:21:26 +03:00
|
|
|
@changeset = @repository.find_changeset_by_name(@rev)
|
2007-10-22 21:45:41 +04:00
|
|
|
if request.xhr?
|
|
|
|
@entries ? render(:partial => 'dir_list_content') : render(:nothing => true)
|
|
|
|
else
|
2009-12-18 17:22:18 +03:00
|
|
|
(show_error_not_found; return) unless @entries
|
2009-09-01 16:13:17 +04:00
|
|
|
@changesets = @repository.latest_changesets(@path, @rev)
|
2008-07-05 12:59:04 +04:00
|
|
|
@properties = @repository.properties(@path, @rev)
|
2012-01-15 22:19:19 +04:00
|
|
|
@repositories = @project.repositories
|
2009-08-16 02:41:40 +04:00
|
|
|
render :action => 'show'
|
2007-10-22 21:45:41 +04:00
|
|
|
end
|
2007-06-13 00:12:05 +04:00
|
|
|
end
|
2009-08-16 02:41:40 +04:00
|
|
|
|
|
|
|
alias_method :browse, :show
|
2011-02-12 12:44:46 +03:00
|
|
|
|
2007-06-13 00:12:05 +04:00
|
|
|
def changes
|
2008-06-15 19:47:28 +04:00
|
|
|
@entry = @repository.entry(@path, @rev)
|
2009-12-18 17:22:18 +03:00
|
|
|
(show_error_not_found; return) unless @entry
|
2009-08-16 02:41:40 +04:00
|
|
|
@changesets = @repository.latest_changesets(@path, @rev, Setting.repository_log_display_limit.to_i)
|
2008-07-05 12:59:04 +04:00
|
|
|
@properties = @repository.properties(@path, @rev)
|
2011-01-21 16:22:08 +03:00
|
|
|
@changeset = @repository.find_changeset_by_name(@rev)
|
2006-12-24 16:38:45 +03:00
|
|
|
end
|
2011-02-12 12:44:46 +03:00
|
|
|
|
2006-12-24 16:38:45 +03:00
|
|
|
def revisions
|
2007-06-13 00:12:05 +04:00
|
|
|
@changeset_count = @repository.changesets.count
|
|
|
|
@changeset_pages = Paginator.new self, @changeset_count,
|
2011-02-12 12:44:46 +03:00
|
|
|
per_page_option,
|
|
|
|
params['page']
|
2007-06-13 00:12:05 +04:00
|
|
|
@changesets = @repository.changesets.find(:all,
|
2011-02-12 12:44:46 +03:00
|
|
|
:limit => @changeset_pages.items_per_page,
|
|
|
|
:offset => @changeset_pages.current.offset,
|
2011-11-03 12:11:38 +04:00
|
|
|
:include => [:user, :repository, :parents])
|
2007-06-13 00:12:05 +04:00
|
|
|
|
2007-08-29 20:52:35 +04:00
|
|
|
respond_to do |format|
|
|
|
|
format.html { render :layout => false if request.xhr? }
|
|
|
|
format.atom { render_feed(@changesets, :title => "#{@project.name}: #{l(:label_revision_plural)}") }
|
|
|
|
end
|
2006-12-24 16:38:45 +03:00
|
|
|
end
|
2011-02-12 12:44:46 +03:00
|
|
|
|
2012-05-05 05:01:29 +04:00
|
|
|
def raw
|
|
|
|
entry_and_raw(true)
|
|
|
|
end
|
|
|
|
|
2006-12-24 16:38:45 +03:00
|
|
|
def entry
|
2012-05-05 05:01:29 +04:00
|
|
|
entry_and_raw(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
def entry_and_raw(is_raw)
|
2008-06-15 19:47:28 +04:00
|
|
|
@entry = @repository.entry(@path, @rev)
|
2009-12-18 17:22:18 +03:00
|
|
|
(show_error_not_found; return) unless @entry
|
|
|
|
|
2008-04-27 14:12:15 +04:00
|
|
|
# If the entry is a dir, show the browser
|
2009-12-18 17:22:18 +03:00
|
|
|
(show; return) if @entry.is_dir?
|
|
|
|
|
2008-06-15 19:47:28 +04:00
|
|
|
@content = @repository.cat(@path, @rev)
|
2009-12-18 17:22:18 +03:00
|
|
|
(show_error_not_found; return) unless @content
|
2012-05-05 05:01:29 +04:00
|
|
|
if is_raw ||
|
2011-03-22 18:31:17 +03:00
|
|
|
(@content.size && @content.size > Setting.file_max_size_displayed.to_i.kilobyte) ||
|
|
|
|
! is_entry_text_data?(@content, @path)
|
2009-02-21 19:04:51 +03:00
|
|
|
# Force the download
|
2011-03-22 19:56:52 +03:00
|
|
|
send_opt = { :filename => filename_for_content_disposition(@path.split('/').last) }
|
|
|
|
send_type = Redmine::MimeType.of(@path)
|
|
|
|
send_opt[:type] = send_type.to_s if send_type
|
2012-06-07 21:00:29 +04:00
|
|
|
send_opt[:disposition] = (Redmine::MimeType.is_type?('image', @path) && !is_raw ? 'inline' : 'attachment')
|
2011-03-22 19:56:52 +03:00
|
|
|
send_data @content, send_opt
|
2007-12-14 20:48:11 +03:00
|
|
|
else
|
|
|
|
# Prevent empty lines when displaying a file with Windows style eol
|
2011-03-22 18:31:17 +03:00
|
|
|
# TODO: UTF-16
|
|
|
|
# Is this needs? AttachmentsController reads file simply.
|
2007-12-14 20:48:11 +03:00
|
|
|
@content.gsub!("\r\n", "\n")
|
2011-01-21 16:22:08 +03:00
|
|
|
@changeset = @repository.find_changeset_by_name(@rev)
|
2011-03-22 18:31:17 +03:00
|
|
|
end
|
|
|
|
end
|
2012-05-05 05:01:29 +04:00
|
|
|
private :entry_and_raw
|
2011-03-22 18:31:17 +03:00
|
|
|
|
|
|
|
def is_entry_text_data?(ent, path)
|
|
|
|
# UTF-16 contains "\x00".
|
2011-05-21 10:15:34 +04:00
|
|
|
# It is very strict that file contains less than 30% of ascii symbols
|
2011-03-22 18:31:17 +03:00
|
|
|
# in non Western Europe.
|
|
|
|
return true if Redmine::MimeType.is_type?('text', path)
|
|
|
|
# Ruby 1.8.6 has a bug of integer divisions.
|
|
|
|
# http://apidock.com/ruby/v1_8_6_287/String/is_binary_data%3F
|
|
|
|
return false if ent.is_binary_data?
|
|
|
|
true
|
2006-12-24 16:38:45 +03:00
|
|
|
end
|
2011-03-22 18:31:17 +03:00
|
|
|
private :is_entry_text_data?
|
2011-01-21 16:22:08 +03:00
|
|
|
|
2007-12-02 23:58:02 +03:00
|
|
|
def annotate
|
2008-12-22 23:33:01 +03:00
|
|
|
@entry = @repository.entry(@path, @rev)
|
2009-12-18 17:22:18 +03:00
|
|
|
(show_error_not_found; return) unless @entry
|
2011-02-12 12:44:46 +03:00
|
|
|
|
2007-12-02 23:58:02 +03:00
|
|
|
@annotate = @repository.scm.annotate(@path, @rev)
|
2011-11-05 07:47:03 +04:00
|
|
|
if @annotate.nil? || @annotate.empty?
|
|
|
|
(render_error l(:error_scm_annotate); return)
|
|
|
|
end
|
|
|
|
ann_buf_size = 0
|
|
|
|
@annotate.lines.each do |buf|
|
|
|
|
ann_buf_size += buf.size
|
|
|
|
end
|
|
|
|
if ann_buf_size > Setting.file_max_size_displayed.to_i.kilobyte
|
|
|
|
(render_error l(:error_scm_annotate_big_text_file); return)
|
|
|
|
end
|
2011-01-21 16:22:08 +03:00
|
|
|
@changeset = @repository.find_changeset_by_name(@rev)
|
2007-12-02 23:58:02 +03:00
|
|
|
end
|
2011-01-21 16:22:08 +03:00
|
|
|
|
2006-12-24 16:38:45 +03:00
|
|
|
def revision
|
2007-12-01 20:15:42 +03:00
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.js {render :layout => false}
|
|
|
|
end
|
2012-02-05 14:56:27 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
# Adds a related issue to a changeset
|
|
|
|
# POST /projects/:project_id/repository/(:repository_id/)revisions/:rev/issues
|
|
|
|
def add_related_issue
|
|
|
|
@issue = @changeset.find_referenced_issue_by_id(params[:issue_id])
|
|
|
|
if @issue && (!@issue.visible? || @changeset.issues.include?(@issue))
|
|
|
|
@issue = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
if @issue
|
|
|
|
@changeset.issues << @issue
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Removes a related issue from a changeset
|
|
|
|
# DELETE /projects/:project_id/repository/(:repository_id/)revisions/:rev/issues/:issue_id
|
|
|
|
def remove_related_issue
|
|
|
|
@issue = Issue.visible.find_by_id(params[:issue_id])
|
|
|
|
if @issue
|
|
|
|
@changeset.issues.delete(@issue)
|
|
|
|
end
|
2006-12-24 16:38:45 +03:00
|
|
|
end
|
2011-02-12 12:44:46 +03:00
|
|
|
|
2006-12-24 16:38:45 +03:00
|
|
|
def diff
|
2008-06-08 20:48:21 +04:00
|
|
|
if params[:format] == 'diff'
|
2008-06-08 20:28:42 +04:00
|
|
|
@diff = @repository.diff(@path, @rev, @rev_to)
|
2009-12-18 17:22:18 +03:00
|
|
|
(show_error_not_found; return) unless @diff
|
2008-06-08 20:48:21 +04:00
|
|
|
filename = "changeset_r#{@rev}"
|
|
|
|
filename << "_r#{@rev_to}" if @rev_to
|
|
|
|
send_data @diff.join, :filename => "#{filename}.diff",
|
|
|
|
:type => 'text/x-patch',
|
|
|
|
:disposition => 'attachment'
|
|
|
|
else
|
|
|
|
@diff_type = params[:type] || User.current.pref[:diff_type] || 'inline'
|
|
|
|
@diff_type = 'inline' unless %w(inline sbs).include?(@diff_type)
|
2011-05-21 10:15:34 +04:00
|
|
|
|
2008-06-08 20:48:21 +04:00
|
|
|
# Save diff type as user preference
|
|
|
|
if User.current.logged? && @diff_type != User.current.pref[:diff_type]
|
|
|
|
User.current.pref[:diff_type] = @diff_type
|
|
|
|
User.current.preference.save
|
|
|
|
end
|
2011-08-31 16:01:01 +04:00
|
|
|
@cache_key = "repositories/diff/#{@repository.id}/" +
|
2011-06-14 02:09:01 +04:00
|
|
|
Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}-#{current_language}")
|
2008-06-08 20:48:21 +04:00
|
|
|
unless read_fragment(@cache_key)
|
|
|
|
@diff = @repository.diff(@path, @rev, @rev_to)
|
|
|
|
show_error_not_found unless @diff
|
|
|
|
end
|
2011-01-02 12:45:05 +03:00
|
|
|
|
|
|
|
@changeset = @repository.find_changeset_by_name(@rev)
|
|
|
|
@changeset_to = @rev_to ? @repository.find_changeset_by_name(@rev_to) : nil
|
2011-01-11 19:04:07 +03:00
|
|
|
@diff_format_revisions = @repository.diff_format_revisions(@changeset, @changeset_to)
|
2007-05-02 00:56:19 +04:00
|
|
|
end
|
2006-12-24 16:38:45 +03:00
|
|
|
end
|
2011-01-11 19:04:07 +03:00
|
|
|
|
2011-02-12 12:44:46 +03:00
|
|
|
def stats
|
2007-03-25 21:11:46 +04:00
|
|
|
end
|
2011-02-12 12:44:46 +03:00
|
|
|
|
2007-03-25 21:11:46 +04:00
|
|
|
def graph
|
2011-02-12 12:44:46 +03:00
|
|
|
data = nil
|
2007-03-25 21:11:46 +04:00
|
|
|
case params[:graph]
|
|
|
|
when "commits_per_month"
|
|
|
|
data = graph_commits_per_month(@repository)
|
|
|
|
when "commits_per_author"
|
|
|
|
data = graph_commits_per_author(@repository)
|
|
|
|
end
|
|
|
|
if data
|
|
|
|
headers["Content-Type"] = "image/svg+xml"
|
|
|
|
send_data(data, :type => "image/svg+xml", :disposition => "inline")
|
|
|
|
else
|
|
|
|
render_404
|
|
|
|
end
|
|
|
|
end
|
2011-05-03 11:32:50 +04:00
|
|
|
|
2010-12-18 21:37:49 +03:00
|
|
|
private
|
|
|
|
|
2012-01-15 18:23:06 +04:00
|
|
|
def find_repository
|
|
|
|
@repository = Repository.find(params[:id])
|
|
|
|
@project = @repository.project
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
render_404
|
|
|
|
end
|
|
|
|
|
2010-12-20 21:47:54 +03:00
|
|
|
REV_PARAM_RE = %r{\A[a-f0-9]*\Z}i
|
2010-12-18 21:37:49 +03:00
|
|
|
|
2012-01-15 18:23:06 +04:00
|
|
|
def find_project_repository
|
2007-09-14 15:34:08 +04:00
|
|
|
@project = Project.find(params[:id])
|
2012-01-15 22:19:19 +04:00
|
|
|
if params[:repository_id].present?
|
|
|
|
@repository = @project.repositories.find_by_identifier_param(params[:repository_id])
|
|
|
|
else
|
|
|
|
@repository = @project.repository
|
|
|
|
end
|
2009-12-18 17:22:18 +03:00
|
|
|
(render_404; return false) unless @repository
|
2012-04-25 21:17:49 +04:00
|
|
|
@path = params[:path].is_a?(Array) ? params[:path].join('/') : params[:path].to_s
|
2011-10-10 03:34:53 +04:00
|
|
|
@rev = params[:rev].blank? ? @repository.default_branch : params[:rev].to_s.strip
|
2008-04-03 20:50:53 +04:00
|
|
|
@rev_to = params[:rev_to]
|
2011-05-03 11:32:50 +04:00
|
|
|
|
2011-02-17 17:17:04 +03:00
|
|
|
unless @rev.to_s.match(REV_PARAM_RE) && @rev_to.to_s.match(REV_PARAM_RE)
|
2010-12-18 21:37:49 +03:00
|
|
|
if @repository.branches.blank?
|
|
|
|
raise InvalidRevisionParam
|
|
|
|
end
|
|
|
|
end
|
2007-01-02 11:47:07 +03:00
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
render_404
|
2008-04-03 20:50:53 +04:00
|
|
|
rescue InvalidRevisionParam
|
|
|
|
show_error_not_found
|
2006-12-24 16:38:45 +03:00
|
|
|
end
|
|
|
|
|
2012-02-05 14:56:27 +04:00
|
|
|
def find_changeset
|
|
|
|
if @rev.present?
|
|
|
|
@changeset = @repository.find_changeset_by_name(@rev)
|
|
|
|
end
|
|
|
|
show_error_not_found unless @changeset
|
|
|
|
end
|
|
|
|
|
2008-01-23 20:25:11 +03:00
|
|
|
def show_error_not_found
|
2011-01-14 23:22:36 +03:00
|
|
|
render_error :message => l(:error_scm_not_found), :status => 404
|
2008-01-23 20:25:11 +03:00
|
|
|
end
|
2011-05-03 11:32:50 +04:00
|
|
|
|
2008-06-15 20:11:07 +04:00
|
|
|
# Handler for Redmine::Scm::Adapters::CommandFailed exception
|
|
|
|
def show_error_command_failed(exception)
|
|
|
|
render_error l(:error_scm_command_failed, exception.message)
|
2006-12-24 16:38:45 +03:00
|
|
|
end
|
2011-05-03 11:32:50 +04:00
|
|
|
|
2007-03-25 21:11:46 +04:00
|
|
|
def graph_commits_per_month(repository)
|
|
|
|
@date_to = Date.today
|
2007-08-16 03:04:14 +04:00
|
|
|
@date_from = @date_to << 11
|
|
|
|
@date_from = Date.civil(@date_from.year, @date_from.month, 1)
|
2012-04-25 21:17:49 +04:00
|
|
|
commits_by_day = Changeset.count(
|
2011-05-03 11:32:50 +04:00
|
|
|
:all, :group => :commit_date,
|
2012-04-25 21:17:49 +04:00
|
|
|
:conditions => ["repository_id = ? AND commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to])
|
2007-03-25 21:11:46 +04:00
|
|
|
commits_by_month = [0] * 12
|
2012-05-02 01:12:47 +04:00
|
|
|
commits_by_day.each {|c| commits_by_month[(@date_to.month - c.first.to_date.month) % 12] += c.last }
|
2007-03-25 21:11:46 +04:00
|
|
|
|
2012-04-25 21:17:49 +04:00
|
|
|
changes_by_day = Change.count(
|
|
|
|
:all, :group => :commit_date, :include => :changeset,
|
|
|
|
:conditions => ["#{Changeset.table_name}.repository_id = ? AND #{Changeset.table_name}.commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to])
|
2007-03-25 21:11:46 +04:00
|
|
|
changes_by_month = [0] * 12
|
2012-05-02 01:12:47 +04:00
|
|
|
changes_by_day.each {|c| changes_by_month[(@date_to.month - c.first.to_date.month) % 12] += c.last }
|
2011-05-03 11:32:50 +04:00
|
|
|
|
2007-03-25 21:11:46 +04:00
|
|
|
fields = []
|
2009-02-21 14:04:50 +03:00
|
|
|
12.times {|m| fields << month_name(((Date.today.month - 1 - m) % 12) + 1)}
|
2011-05-03 11:32:50 +04:00
|
|
|
|
2007-03-25 21:11:46 +04:00
|
|
|
graph = SVG::Graph::Bar.new(
|
|
|
|
:height => 300,
|
2008-06-29 15:13:10 +04:00
|
|
|
:width => 800,
|
2007-03-25 21:11:46 +04:00
|
|
|
:fields => fields.reverse,
|
|
|
|
:stack => :side,
|
|
|
|
:scale_integers => true,
|
|
|
|
:step_x_labels => 2,
|
|
|
|
:show_data_values => false,
|
|
|
|
:graph_title => l(:label_commits_per_month),
|
|
|
|
:show_graph_title => true
|
|
|
|
)
|
2011-05-03 11:32:50 +04:00
|
|
|
|
2007-03-25 21:11:46 +04:00
|
|
|
graph.add_data(
|
|
|
|
:data => commits_by_month[0..11].reverse,
|
|
|
|
:title => l(:label_revision_plural)
|
|
|
|
)
|
|
|
|
|
|
|
|
graph.add_data(
|
|
|
|
:data => changes_by_month[0..11].reverse,
|
|
|
|
:title => l(:label_change_plural)
|
|
|
|
)
|
2011-05-21 10:15:34 +04:00
|
|
|
|
2007-03-25 21:11:46 +04:00
|
|
|
graph.burn
|
|
|
|
end
|
|
|
|
|
|
|
|
def graph_commits_per_author(repository)
|
2012-04-25 21:17:49 +04:00
|
|
|
commits_by_author = Changeset.count(:all, :group => :committer, :conditions => ["repository_id = ?", repository.id])
|
2009-09-13 21:14:35 +04:00
|
|
|
commits_by_author.to_a.sort! {|x, y| x.last <=> y.last}
|
2007-03-26 21:14:06 +04:00
|
|
|
|
2012-04-25 21:17:49 +04:00
|
|
|
changes_by_author = Change.count(:all, :group => :committer, :include => :changeset, :conditions => ["#{Changeset.table_name}.repository_id = ?", repository.id])
|
2007-03-26 21:14:06 +04:00
|
|
|
h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o}
|
2011-05-21 10:15:34 +04:00
|
|
|
|
2007-03-25 21:11:46 +04:00
|
|
|
fields = commits_by_author.collect {|r| r.first}
|
2007-03-26 21:14:06 +04:00
|
|
|
commits_data = commits_by_author.collect {|r| r.last}
|
|
|
|
changes_data = commits_by_author.collect {|r| h[r.first] || 0}
|
2011-05-21 10:15:34 +04:00
|
|
|
|
2007-03-25 21:11:46 +04:00
|
|
|
fields = fields + [""]*(10 - fields.length) if fields.length<10
|
2007-03-26 21:14:06 +04:00
|
|
|
commits_data = commits_data + [0]*(10 - commits_data.length) if commits_data.length<10
|
|
|
|
changes_data = changes_data + [0]*(10 - changes_data.length) if changes_data.length<10
|
2011-05-21 10:15:34 +04:00
|
|
|
|
2008-04-24 22:35:56 +04:00
|
|
|
# Remove email adress in usernames
|
|
|
|
fields = fields.collect {|c| c.gsub(%r{<.+@.+>}, '') }
|
2011-05-21 10:15:34 +04:00
|
|
|
|
2007-03-25 21:11:46 +04:00
|
|
|
graph = SVG::Graph::BarHorizontal.new(
|
2008-06-29 15:13:10 +04:00
|
|
|
:height => 400,
|
|
|
|
:width => 800,
|
2007-03-25 21:11:46 +04:00
|
|
|
:fields => fields,
|
|
|
|
:stack => :side,
|
|
|
|
:scale_integers => true,
|
|
|
|
:show_data_values => false,
|
|
|
|
:rotate_y_labels => false,
|
|
|
|
:graph_title => l(:label_commits_per_author),
|
|
|
|
:show_graph_title => true
|
|
|
|
)
|
|
|
|
graph.add_data(
|
2007-03-26 21:14:06 +04:00
|
|
|
:data => commits_data,
|
2007-03-25 21:11:46 +04:00
|
|
|
:title => l(:label_revision_plural)
|
|
|
|
)
|
2007-03-26 21:14:06 +04:00
|
|
|
graph.add_data(
|
|
|
|
:data => changes_data,
|
|
|
|
:title => l(:label_change_plural)
|
|
|
|
)
|
2007-03-25 21:11:46 +04:00
|
|
|
graph.burn
|
|
|
|
end
|
2006-12-24 16:38:45 +03:00
|
|
|
end
|