| 
									
										
										
										
											2009-08-17 14:26:13 +00:00
										 |  |  | # Redmine - project management software | 
					
						
							|  |  |  | # Copyright (C) 2006-2009  Jean-Philippe Lang | 
					
						
							| 
									
										
										
										
											2006-12-24 13:38:45 +00: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. | 
					
						
							|  |  |  | #  | 
					
						
							|  |  |  | # 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. | 
					
						
							|  |  |  | #  | 
					
						
							|  |  |  | # 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 17:11:46 +00:00
										 |  |  | require 'SVG/Graph/Bar' | 
					
						
							|  |  |  | require 'SVG/Graph/BarHorizontal' | 
					
						
							| 
									
										
										
										
											2007-05-01 20:56:19 +00:00
										 |  |  | require 'digest/sha1' | 
					
						
							| 
									
										
										
										
											2007-03-25 17:11:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-03 16:50:53 +00:00
										 |  |  | class ChangesetNotFound < Exception; end | 
					
						
							|  |  |  | class InvalidRevisionParam < Exception; end | 
					
						
							| 
									
										
										
										
											2007-12-01 17:15:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-24 13:38:45 +00:00
										 |  |  | class RepositoriesController < ApplicationController | 
					
						
							| 
									
										
										
										
											2008-01-19 11:53:43 +00:00
										 |  |  |   menu_item :repository | 
					
						
							| 
									
										
										
										
											2010-04-17 12:51:46 +00:00
										 |  |  |   menu_item :settings, :only => :edit | 
					
						
							| 
									
										
										
										
											2009-10-21 17:07:18 +00:00
										 |  |  |   default_search_scope :changesets | 
					
						
							|  |  |  |    | 
					
						
							| 
									
										
										
										
											2007-09-14 11:34:08 +00:00
										 |  |  |   before_filter :find_repository, :except => :edit | 
					
						
							|  |  |  |   before_filter :find_project, :only => :edit | 
					
						
							|  |  |  |   before_filter :authorize | 
					
						
							| 
									
										
										
										
											2007-08-29 16:52:35 +00:00
										 |  |  |   accept_key_auth :revisions | 
					
						
							| 
									
										
										
										
											2007-03-25 17:11:46 +00:00
										 |  |  |    | 
					
						
							| 
									
										
										
										
											2008-06-15 16:11:07 +00:00
										 |  |  |   rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed | 
					
						
							|  |  |  |    | 
					
						
							| 
									
										
										
										
											2007-09-14 11:34:08 +00:00
										 |  |  |   def edit | 
					
						
							|  |  |  |     @repository = @project.repository | 
					
						
							|  |  |  |     if !@repository | 
					
						
							|  |  |  |       @repository = Repository.factory(params[:repository_scm]) | 
					
						
							| 
									
										
										
										
											2008-06-08 14:59:26 +00:00
										 |  |  |       @repository.project = @project if @repository | 
					
						
							| 
									
										
										
										
											2007-09-14 11:34:08 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2008-06-08 14:59:26 +00:00
										 |  |  |     if request.post? && @repository | 
					
						
							| 
									
										
										
										
											2007-09-14 11:34:08 +00:00
										 |  |  |       @repository.attributes = params[:repository] | 
					
						
							|  |  |  |       @repository.save | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2010-04-17 12:51:46 +00:00
										 |  |  |     render(:update) do |page| | 
					
						
							|  |  |  |       page.replace_html "tab-content-repository", :partial => 'projects/settings/repository' | 
					
						
							|  |  |  |       if @repository && !@project.repository | 
					
						
							|  |  |  |         @project.reload #needed to reload association | 
					
						
							|  |  |  |         page.replace_html "main-menu", render_main_menu(@project) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2007-09-14 11:34:08 +00:00
										 |  |  |   end | 
					
						
							|  |  |  |    | 
					
						
							| 
									
										
										
										
											2008-11-10 18:59:06 +00: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 18:02:25 +00: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 18:59:06 +00:00
										 |  |  |       flash[:notice] = l(:notice_successful_update) | 
					
						
							|  |  |  |       redirect_to :action => 'committers', :id => @project | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  |    | 
					
						
							| 
									
										
										
										
											2007-09-14 11:34:08 +00:00
										 |  |  |   def destroy | 
					
						
							|  |  |  |     @repository.destroy | 
					
						
							|  |  |  |     redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'repository' | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  |    | 
					
						
							| 
									
										
										
										
											2009-08-15 22:41:40 +00:00
										 |  |  |   def show  | 
					
						
							|  |  |  |     @repository.fetch_changesets if Setting.autofetch_changesets? && @path.empty? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-06-12 20:12:05 +00:00
										 |  |  |     @entries = @repository.entries(@path, @rev) | 
					
						
							| 
									
										
										
										
											2007-10-22 17:45:41 +00:00
										 |  |  |     if request.xhr? | 
					
						
							|  |  |  |       @entries ? render(:partial => 'dir_list_content') : render(:nothing => true) | 
					
						
							|  |  |  |     else | 
					
						
							| 
									
										
										
										
											2009-12-18 14:22:18 +00:00
										 |  |  |       (show_error_not_found; return) unless @entries | 
					
						
							| 
									
										
										
										
											2009-09-01 12:13:17 +00:00
										 |  |  |       @changesets = @repository.latest_changesets(@path, @rev) | 
					
						
							| 
									
										
										
										
											2008-07-05 08:59:04 +00:00
										 |  |  |       @properties = @repository.properties(@path, @rev) | 
					
						
							| 
									
										
										
										
											2009-08-15 22:41:40 +00:00
										 |  |  |       render :action => 'show' | 
					
						
							| 
									
										
										
										
											2007-10-22 17:45:41 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2007-06-12 20:12:05 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2009-08-15 22:41:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   alias_method :browse, :show | 
					
						
							| 
									
										
										
										
											2007-06-12 20:12:05 +00:00
										 |  |  |    | 
					
						
							|  |  |  |   def changes | 
					
						
							| 
									
										
										
										
											2008-06-15 15:47:28 +00:00
										 |  |  |     @entry = @repository.entry(@path, @rev) | 
					
						
							| 
									
										
										
										
											2009-12-18 14:22:18 +00:00
										 |  |  |     (show_error_not_found; return) unless @entry | 
					
						
							| 
									
										
										
										
											2009-08-15 22:41:40 +00:00
										 |  |  |     @changesets = @repository.latest_changesets(@path, @rev, Setting.repository_log_display_limit.to_i) | 
					
						
							| 
									
										
										
										
											2008-07-05 08:59:04 +00:00
										 |  |  |     @properties = @repository.properties(@path, @rev) | 
					
						
							| 
									
										
										
										
											2006-12-24 13:38:45 +00:00
										 |  |  |   end | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   def revisions | 
					
						
							| 
									
										
										
										
											2007-06-12 20:12:05 +00:00
										 |  |  |     @changeset_count = @repository.changesets.count | 
					
						
							|  |  |  |     @changeset_pages = Paginator.new self, @changeset_count, | 
					
						
							| 
									
										
										
										
											2007-12-29 11:36:30 +00:00
										 |  |  | 								      per_page_option, | 
					
						
							| 
									
										
										
										
											2007-06-12 20:12:05 +00:00
										 |  |  | 								      params['page']								 | 
					
						
							|  |  |  |     @changesets = @repository.changesets.find(:all, | 
					
						
							|  |  |  | 						:limit  =>  @changeset_pages.items_per_page, | 
					
						
							| 
									
										
										
										
											2008-11-10 19:09:00 +00:00
										 |  |  | 						:offset =>  @changeset_pages.current.offset, | 
					
						
							| 
									
										
										
										
											2009-04-07 17:30:56 +00:00
										 |  |  |             :include => [:user, :repository]) | 
					
						
							| 
									
										
										
										
											2007-06-12 20:12:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-08-29 16:52:35 +00: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 13:38:45 +00:00
										 |  |  |   end | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   def entry | 
					
						
							| 
									
										
										
										
											2008-06-15 15:47:28 +00:00
										 |  |  |     @entry = @repository.entry(@path, @rev) | 
					
						
							| 
									
										
										
										
											2009-12-18 14:22:18 +00:00
										 |  |  |     (show_error_not_found; return) unless @entry | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-27 10:12:15 +00:00
										 |  |  |     # If the entry is a dir, show the browser | 
					
						
							| 
									
										
										
										
											2009-12-18 14:22:18 +00:00
										 |  |  |     (show; return) if @entry.is_dir? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-15 15:47:28 +00:00
										 |  |  |     @content = @repository.cat(@path, @rev) | 
					
						
							| 
									
										
										
										
											2009-12-18 14:22:18 +00:00
										 |  |  |     (show_error_not_found; return) unless @content | 
					
						
							| 
									
										
										
										
											2009-02-21 16:04:51 +00:00
										 |  |  |     if 'raw' == params[:format] || @content.is_binary_data? || (@entry.size && @entry.size > Setting.file_max_size_displayed.to_i.kilobyte) | 
					
						
							|  |  |  |       # Force the download | 
					
						
							| 
									
										
										
										
											2007-05-08 15:49:20 +00:00
										 |  |  |       send_data @content, :filename => @path.split('/').last | 
					
						
							| 
									
										
										
										
											2007-12-14 17:48:11 +00:00
										 |  |  |     else | 
					
						
							|  |  |  |       # Prevent empty lines when displaying a file with Windows style eol | 
					
						
							|  |  |  |       @content.gsub!("\r\n", "\n") | 
					
						
							| 
									
										
										
										
											2008-07-05 08:59:04 +00:00
										 |  |  |    end | 
					
						
							| 
									
										
										
										
											2006-12-24 13:38:45 +00:00
										 |  |  |   end | 
					
						
							|  |  |  |    | 
					
						
							| 
									
										
										
										
											2007-12-02 20:58:02 +00:00
										 |  |  |   def annotate | 
					
						
							| 
									
										
										
										
											2008-12-22 20:33:01 +00:00
										 |  |  |     @entry = @repository.entry(@path, @rev) | 
					
						
							| 
									
										
										
										
											2009-12-18 14:22:18 +00:00
										 |  |  |     (show_error_not_found; return) unless @entry | 
					
						
							| 
									
										
										
										
											2008-12-22 20:33:01 +00:00
										 |  |  |      | 
					
						
							| 
									
										
										
										
											2007-12-02 20:58:02 +00:00
										 |  |  |     @annotate = @repository.scm.annotate(@path, @rev) | 
					
						
							| 
									
										
										
										
											2009-12-18 14:22:18 +00:00
										 |  |  |     (render_error l(:error_scm_annotate); return) if @annotate.nil? || @annotate.empty? | 
					
						
							| 
									
										
										
										
											2007-12-02 20:58:02 +00:00
										 |  |  |   end | 
					
						
							|  |  |  |    | 
					
						
							| 
									
										
										
										
											2006-12-24 13:38:45 +00:00
										 |  |  |   def revision | 
					
						
							| 
									
										
										
										
											2009-09-20 15:20:22 +00:00
										 |  |  |     @changeset = @repository.find_changeset_by_name(@rev) | 
					
						
							| 
									
										
										
										
											2007-12-01 17:15:42 +00:00
										 |  |  |     raise ChangesetNotFound unless @changeset | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     respond_to do |format| | 
					
						
							|  |  |  |       format.html | 
					
						
							|  |  |  |       format.js {render :layout => false} | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   rescue ChangesetNotFound | 
					
						
							| 
									
										
										
										
											2008-01-25 10:55:16 +00:00
										 |  |  |     show_error_not_found | 
					
						
							| 
									
										
										
										
											2006-12-24 13:38:45 +00:00
										 |  |  |   end | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   def diff | 
					
						
							| 
									
										
										
										
											2008-06-08 16:48:21 +00:00
										 |  |  |     if params[:format] == 'diff' | 
					
						
							| 
									
										
										
										
											2008-06-08 16:28:42 +00:00
										 |  |  |       @diff = @repository.diff(@path, @rev, @rev_to) | 
					
						
							| 
									
										
										
										
											2009-12-18 14:22:18 +00:00
										 |  |  |       (show_error_not_found; return) unless @diff | 
					
						
							| 
									
										
										
										
											2008-06-08 16:48:21 +00: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) | 
					
						
							|  |  |  |        | 
					
						
							|  |  |  |       # 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 | 
					
						
							|  |  |  |        | 
					
						
							|  |  |  |       @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 | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2007-05-01 20:56:19 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2006-12-24 13:38:45 +00:00
										 |  |  |   end | 
					
						
							|  |  |  |    | 
					
						
							| 
									
										
										
										
											2007-03-25 17:11:46 +00:00
										 |  |  |   def stats   | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   def graph | 
					
						
							|  |  |  |     data = nil     | 
					
						
							|  |  |  |     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 | 
					
						
							|  |  |  |    | 
					
						
							| 
									
										
										
										
											2006-12-24 13:38:45 +00:00
										 |  |  | private | 
					
						
							| 
									
										
										
										
											2007-09-14 11:34:08 +00:00
										 |  |  |   def find_repository | 
					
						
							|  |  |  |     @project = Project.find(params[:id]) | 
					
						
							| 
									
										
										
										
											2006-12-24 13:38:45 +00:00
										 |  |  |     @repository = @project.repository | 
					
						
							| 
									
										
										
										
											2009-12-18 14:22:18 +00:00
										 |  |  |     (render_404; return false) unless @repository | 
					
						
							| 
									
										
										
										
											2007-11-04 11:20:21 +00:00
										 |  |  |     @path = params[:path].join('/') unless params[:path].nil? | 
					
						
							| 
									
										
										
										
											2006-12-24 13:38:45 +00:00
										 |  |  |     @path ||= '' | 
					
						
							| 
									
										
										
										
											2009-08-15 22:41:40 +00:00
										 |  |  |     @rev = params[:rev].blank? ? @repository.default_branch : params[:rev].strip | 
					
						
							| 
									
										
										
										
											2008-04-03 16:50:53 +00:00
										 |  |  |     @rev_to = params[:rev_to] | 
					
						
							| 
									
										
										
										
											2007-01-02 08:47:07 +00:00
										 |  |  |   rescue ActiveRecord::RecordNotFound | 
					
						
							|  |  |  |     render_404 | 
					
						
							| 
									
										
										
										
											2008-04-03 16:50:53 +00:00
										 |  |  |   rescue InvalidRevisionParam | 
					
						
							|  |  |  |     show_error_not_found | 
					
						
							| 
									
										
										
										
											2006-12-24 13:38:45 +00:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-23 17:25:11 +00:00
										 |  |  |   def show_error_not_found | 
					
						
							|  |  |  |     render_error l(:error_scm_not_found) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  |    | 
					
						
							| 
									
										
										
										
											2008-06-15 16:11:07 +00: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 13:38:45 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2007-03-25 17:11:46 +00:00
										 |  |  |    | 
					
						
							|  |  |  |   def graph_commits_per_month(repository) | 
					
						
							|  |  |  |     @date_to = Date.today | 
					
						
							| 
									
										
										
										
											2007-08-15 23:04:14 +00:00
										 |  |  |     @date_from = @date_to << 11
 | 
					
						
							|  |  |  |     @date_from = Date.civil(@date_from.year, @date_from.month, 1) | 
					
						
							| 
									
										
										
										
											2007-03-25 17:11:46 +00:00
										 |  |  |     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 } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-08-15 23:04:14 +00:00
										 |  |  |     changes_by_day = repository.changes.count(:all, :group => :commit_date, :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to]) | 
					
						
							| 
									
										
										
										
											2007-03-25 17:11:46 +00:00
										 |  |  |     changes_by_month = [0] * 12
 | 
					
						
							|  |  |  |     changes_by_day.each {|c| changes_by_month[c.first.to_date.months_ago] += c.last } | 
					
						
							|  |  |  |     | 
					
						
							|  |  |  |     fields = [] | 
					
						
							| 
									
										
										
										
											2009-02-21 11:04:50 +00:00
										 |  |  |     12.times {|m| fields << month_name(((Date.today.month - 1 - m) % 12) + 1)} | 
					
						
							| 
									
										
										
										
											2007-03-25 17:11:46 +00:00
										 |  |  |    | 
					
						
							|  |  |  |     graph = SVG::Graph::Bar.new( | 
					
						
							|  |  |  |       :height => 300, | 
					
						
							| 
									
										
										
										
											2008-06-29 11:13:10 +00:00
										 |  |  |       :width => 800, | 
					
						
							| 
									
										
										
										
											2007-03-25 17:11:46 +00: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 | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     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) | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     graph.burn | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def graph_commits_per_author(repository) | 
					
						
							|  |  |  |     commits_by_author = repository.changesets.count(:all, :group => :committer) | 
					
						
							| 
									
										
										
										
											2009-09-13 17:14:35 +00:00
										 |  |  |     commits_by_author.to_a.sort! {|x, y| x.last <=> y.last} | 
					
						
							| 
									
										
										
										
											2007-03-26 17:14:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     changes_by_author = repository.changes.count(:all, :group => :committer) | 
					
						
							|  |  |  |     h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o} | 
					
						
							| 
									
										
										
										
											2007-03-25 17:11:46 +00:00
										 |  |  |      | 
					
						
							|  |  |  |     fields = commits_by_author.collect {|r| r.first} | 
					
						
							| 
									
										
										
										
											2007-03-26 17:14:06 +00:00
										 |  |  |     commits_data = commits_by_author.collect {|r| r.last} | 
					
						
							|  |  |  |     changes_data = commits_by_author.collect {|r| h[r.first] || 0} | 
					
						
							| 
									
										
										
										
											2007-03-25 17:11:46 +00:00
										 |  |  |      | 
					
						
							|  |  |  |     fields = fields + [""]*(10 - fields.length) if fields.length<10
 | 
					
						
							| 
									
										
										
										
											2007-03-26 17:14:06 +00: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
 | 
					
						
							| 
									
										
										
										
											2007-03-25 17:11:46 +00:00
										 |  |  |      | 
					
						
							| 
									
										
										
										
											2008-04-24 18:35:56 +00:00
										 |  |  |     # Remove email adress in usernames | 
					
						
							|  |  |  |     fields = fields.collect {|c| c.gsub(%r{<.+@.+>}, '') } | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2007-03-25 17:11:46 +00:00
										 |  |  |     graph = SVG::Graph::BarHorizontal.new( | 
					
						
							| 
									
										
										
										
											2008-06-29 11:13:10 +00:00
										 |  |  |       :height => 400, | 
					
						
							|  |  |  |       :width => 800, | 
					
						
							| 
									
										
										
										
											2007-03-25 17:11:46 +00: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 17:14:06 +00:00
										 |  |  |       :data => commits_data, | 
					
						
							| 
									
										
										
										
											2007-03-25 17:11:46 +00:00
										 |  |  |       :title => l(:label_revision_plural) | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2007-03-26 17:14:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     graph.add_data( | 
					
						
							|  |  |  |       :data => changes_data, | 
					
						
							|  |  |  |       :title => l(:label_change_plural) | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |         | 
					
						
							| 
									
										
										
										
											2007-03-25 17:11:46 +00:00
										 |  |  |     graph.burn | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-24 13:38:45 +00:00
										 |  |  | end | 
					
						
							| 
									
										
										
										
											2007-03-25 17:11:46 +00:00
										 |  |  |    | 
					
						
							|  |  |  | class Date | 
					
						
							|  |  |  |   def months_ago(date = Date.today) | 
					
						
							|  |  |  |     (date.year - self.year)*12 + (date.month - self.month) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def weeks_ago(date = Date.today) | 
					
						
							|  |  |  |     (date.year - self.year)*52 + (date.cweek - self.cweek) | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2007-03-29 18:14:59 +00:00
										 |  |  | end | 
					
						
							| 
									
										
										
										
											2007-06-12 20:12:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | class String | 
					
						
							|  |  |  |   def with_leading_slash | 
					
						
							|  |  |  |     starts_with?('/') ? self : "/#{self}" | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |