##// END OF EJS Templates
By default, only show statuses that are used by the tracker on the workflow edit view....
By default, only show statuses that are used by the tracker on the workflow edit view. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3188 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r3071:488c192286ea
r3074:6bf0723d0654
Show More
repositories_controller.rb
321 lines | 10.4 KiB | text/x-ruby | RubyLexer
/ app / controllers / repositories_controller.rb
Jean-Philippe Lang
SCM browser:...
r2738 # Redmine - project management software
# Copyright (C) 2006-2009 Jean-Philippe Lang
Jean-Philippe Lang
svn browser merged in trunk...
r103 #
# 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.
Jean-Philippe Lang
added simple svn statistics graphs, rendered using SVG::Graph...
r377 require 'SVG/Graph/Bar'
require 'SVG/Graph/BarHorizontal'
Jean-Philippe Lang
Added fragment caching for svn diffs....
r496 require 'digest/sha1'
Jean-Philippe Lang
added simple svn statistics graphs, rendered using SVG::Graph...
r377
Jean-Philippe Lang
Verify rev and rev_to params format in RepositoriesController. And turn revision arguments into integers in SubversionAdapter....
r1309 class ChangesetNotFound < Exception; end
class InvalidRevisionParam < Exception; end
Jean-Philippe Lang
* Added links to previous and next revisions on revision view (patch by Cyril Mougel slightly edited)...
r925
Jean-Philippe Lang
svn browser merged in trunk...
r103 class RepositoriesController < ApplicationController
Jean-Philippe Lang
Highlight the current item of the main menu....
r1062 menu_item :repository
Jean-Philippe Lang
Contextual quick search (#3263)....
r2829 default_search_scope :changesets
Jean-Philippe Lang
Added project module concept....
r714 before_filter :find_repository, :except => :edit
before_filter :find_project, :only => :edit
before_filter :authorize
Jean-Philippe Lang
Merged 0.6 branch into trunk....
r663 accept_key_auth :revisions
Jean-Philippe Lang
added simple svn statistics graphs, rendered using SVG::Graph...
r377
Jean-Philippe Lang
RepositoriesController cleanup with rescue_from....
r1541 rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed
Jean-Philippe Lang
Added project module concept....
r714 def edit
@repository = @project.repository
if !@repository
@repository = Repository.factory(params[:repository_scm])
Jean-Philippe Lang
Ability to disable unused SCM adapters in application settings....
r1493 @repository.project = @project if @repository
Jean-Philippe Lang
Added project module concept....
r714 end
Jean-Philippe Lang
Ability to disable unused SCM adapters in application settings....
r1493 if request.post? && @repository
Jean-Philippe Lang
Added project module concept....
r714 @repository.attributes = params[:repository]
@repository.save
end
render(:update) {|page| page.replace_html "tab-content-repository", :partial => 'projects/settings/repository'}
end
Jean-Philippe Lang
Maps repository users to Redmine users (#1383)....
r2004 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!
Jean-Philippe Lang
Fixes repository user mapping submission when a repository username is blank (#2339, Conflicting types for parameter containers)....
r2135 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}
Jean-Philippe Lang
Maps repository users to Redmine users (#1383)....
r2004 flash[:notice] = l(:notice_successful_update)
redirect_to :action => 'committers', :id => @project
end
end
Jean-Philippe Lang
Added project module concept....
r714 def destroy
@repository.destroy
redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'repository'
end
Eric Davis
Added branch and tag support to the git repository viewer. (#1406)...
r2735 def show
@repository.fetch_changesets if Setting.autofetch_changesets? && @path.empty?
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556 @entries = @repository.entries(@path, @rev)
Jean-Philippe Lang
Added a bit of AJAX on the SCM browser (tree view)....
r849 if request.xhr?
@entries ? render(:partial => 'dir_list_content') : render(:nothing => true)
else
Jean-Philippe Lang
Removes "xxx and return" calls (#4446)....
r3071 (show_error_not_found; return) unless @entries
Jean-Philippe Lang
SCM:...
r2744 @changesets = @repository.latest_changesets(@path, @rev)
Jean-Philippe Lang
Display svn properties in the browser, svn >= 1.5.0 only (#1581)....
r1613 @properties = @repository.properties(@path, @rev)
Eric Davis
Added branch and tag support to the git repository viewer. (#1406)...
r2735 render :action => 'show'
Jean-Philippe Lang
Added a bit of AJAX on the SCM browser (tree view)....
r849 end
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556 end
Eric Davis
Added branch and tag support to the git repository viewer. (#1406)...
r2735
alias_method :browse, :show
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556
def changes
Jean-Philippe Lang
Fixed: view file at given revision with CVS....
r1539 @entry = @repository.entry(@path, @rev)
Jean-Philippe Lang
Removes "xxx and return" calls (#4446)....
r3071 (show_error_not_found; return) unless @entry
Eric Davis
Added branch and tag support to the git repository viewer. (#1406)...
r2735 @changesets = @repository.latest_changesets(@path, @rev, Setting.repository_log_display_limit.to_i)
Jean-Philippe Lang
Display svn properties in the browser, svn >= 1.5.0 only (#1581)....
r1613 @properties = @repository.properties(@path, @rev)
Jean-Philippe Lang
svn browser merged in trunk...
r103 end
def revisions
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556 @changeset_count = @repository.changesets.count
@changeset_pages = Paginator.new self, @changeset_count,
Jean-Philippe Lang
New setting added to specify how many objects should be displayed on most paginated lists....
r1013 per_page_option,
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556 params['page']
@changesets = @repository.changesets.find(:all,
:limit => @changeset_pages.items_per_page,
Jean-Philippe Lang
Eager-load users....
r2005 :offset => @changeset_pages.current.offset,
Jean-Philippe Lang
Fixed: links to changesets in activity and atom feeds uses project id instead project identifier (#3137)....
r2571 :include => [:user, :repository])
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556
Jean-Philippe Lang
Merged 0.6 branch into trunk....
r663 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
Jean-Philippe Lang
svn browser merged in trunk...
r103 end
def entry
Jean-Philippe Lang
Fixed: view file at given revision with CVS....
r1539 @entry = @repository.entry(@path, @rev)
Jean-Philippe Lang
Removes "xxx and return" calls (#4446)....
r3071 (show_error_not_found; return) unless @entry
Jean-Philippe Lang
Fixed: Links to repository directories don't work (#1119)....
r1350 # If the entry is a dir, show the browser
Jean-Philippe Lang
Removes "xxx and return" calls (#4446)....
r3071 (show; return) if @entry.is_dir?
Jean-Philippe Lang
Fixed: view file at given revision with CVS....
r1539 @content = @repository.cat(@path, @rev)
Jean-Philippe Lang
Removes "xxx and return" calls (#4446)....
r3071 (show_error_not_found; return) unless @content
Jean-Philippe Lang
Limit the size of repository files displayed inline too....
r2442 if 'raw' == params[:format] || @content.is_binary_data? || (@entry.size && @entry.size > Setting.file_max_size_displayed.to_i.kilobyte)
# Force the download
Jean-Philippe Lang
Text files can now be viewed online when browsing the repository....
r518 send_data @content, :filename => @path.split('/').last
Jean-Philippe Lang
Fixed: empty lines when displaying repository files with Windows style eol....
r980 else
# Prevent empty lines when displaying a file with Windows style eol
@content.gsub!("\r\n", "\n")
Jean-Philippe Lang
Display svn properties in the browser, svn >= 1.5.0 only (#1581)....
r1613 end
Jean-Philippe Lang
svn browser merged in trunk...
r103 end
Jean-Philippe Lang
Added Annotate/Blame view for Subversion, CVS and Mercurial repositories....
r934 def annotate
Jean-Philippe Lang
Show view/annotate/download links on repositories/entries and repositories/annotate views (#2367)....
r2165 @entry = @repository.entry(@path, @rev)
Jean-Philippe Lang
Removes "xxx and return" calls (#4446)....
r3071 (show_error_not_found; return) unless @entry
Jean-Philippe Lang
Show view/annotate/download links on repositories/entries and repositories/annotate views (#2367)....
r2165
Jean-Philippe Lang
Added Annotate/Blame view for Subversion, CVS and Mercurial repositories....
r934 @annotate = @repository.scm.annotate(@path, @rev)
Jean-Philippe Lang
Removes "xxx and return" calls (#4446)....
r3071 (render_error l(:error_scm_annotate); return) if @annotate.nil? || @annotate.empty?
Jean-Philippe Lang
Added Annotate/Blame view for Subversion, CVS and Mercurial repositories....
r934 end
Jean-Philippe Lang
svn browser merged in trunk...
r103 def revision
Jean-Philippe Lang
Fixed: RepositoriesController#revision may show wrong revision (#3779)....
r2784 @changeset = @repository.find_changeset_by_name(@rev)
Jean-Philippe Lang
* Added links to previous and next revisions on revision view (patch by Cyril Mougel slightly edited)...
r925 raise ChangesetNotFound unless @changeset
respond_to do |format|
format.html
format.js {render :layout => false}
end
rescue ChangesetNotFound
Jean-Philippe Lang
Fixed RepositoriesController: undefined local variable or method `show_error' (broken by r1094)....
r1090 show_error_not_found
Jean-Philippe Lang
svn browser merged in trunk...
r103 end
def diff
Jean-Philippe Lang
SCM browser: ability to download raw unified diffs....
r1500 if params[:format] == 'diff'
Jean-Philippe Lang
Move unified diff parser out of the scm abstract adapter so it can be reused for viewing attached diffs (#1403)....
r1499 @diff = @repository.diff(@path, @rev, @rev_to)
Jean-Philippe Lang
Removes "xxx and return" calls (#4446)....
r3071 (show_error_not_found; return) unless @diff
Jean-Philippe Lang
SCM browser: ability to download raw unified diffs....
r1500 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
Jean-Philippe Lang
Added fragment caching for svn diffs....
r496 end
Jean-Philippe Lang
svn browser merged in trunk...
r103 end
Jean-Philippe Lang
added simple svn statistics graphs, rendered using SVG::Graph...
r377 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
Jean-Philippe Lang
svn browser merged in trunk...
r103 private
def find_project
@project = Project.find(params[:id])
Jean-Philippe Lang
Added project module concept....
r714 rescue ActiveRecord::RecordNotFound
render_404
end
def find_repository
@project = Project.find(params[:id])
Jean-Philippe Lang
svn browser merged in trunk...
r103 @repository = @project.repository
Jean-Philippe Lang
Removes "xxx and return" calls (#4446)....
r3071 (render_404; return false) unless @repository
Jean-Philippe Lang
Pretty URL for the repository browser (Cyril Mougel)...
r867 @path = params[:path].join('/') unless params[:path].nil?
Jean-Philippe Lang
svn browser merged in trunk...
r103 @path ||= ''
Eric Davis
Added branch and tag support to the git repository viewer. (#1406)...
r2735 @rev = params[:rev].blank? ? @repository.default_branch : params[:rev].strip
Jean-Philippe Lang
Verify rev and rev_to params format in RepositoriesController. And turn revision arguments into integers in SubversionAdapter....
r1309 @rev_to = params[:rev_to]
Jean-Philippe Lang
ActiveRecord::RecordNotFound exceptions handled more gracefully...
r130 rescue ActiveRecord::RecordNotFound
render_404
Jean-Philippe Lang
Verify rev and rev_to params format in RepositoriesController. And turn revision arguments into integers in SubversionAdapter....
r1309 rescue InvalidRevisionParam
show_error_not_found
Jean-Philippe Lang
svn browser merged in trunk...
r103 end
Jean-Philippe Lang
Show explicit error message when the scm command failed (eg. when svn binary is not available)....
r1080 def show_error_not_found
render_error l(:error_scm_not_found)
end
Jean-Philippe Lang
RepositoriesController cleanup with rescue_from....
r1541 # Handler for Redmine::Scm::Adapters::CommandFailed exception
def show_error_command_failed(exception)
render_error l(:error_scm_command_failed, exception.message)
Jean-Philippe Lang
svn browser merged in trunk...
r103 end
Jean-Philippe Lang
added simple svn statistics graphs, rendered using SVG::Graph...
r377
def graph_commits_per_month(repository)
@date_to = Date.today
Jean-Philippe Lang
Fixed: nil error on 'commits per month' graph....
r639 @date_from = @date_to << 11
@date_from = Date.civil(@date_from.year, @date_from.month, 1)
Jean-Philippe Lang
added simple svn statistics graphs, rendered using SVG::Graph...
r377 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 }
Jean-Philippe Lang
Fixed: nil error on 'commits per month' graph....
r639 changes_by_day = repository.changes.count(:all, :group => :commit_date, :conditions => ["commit_date BETWEEN ? AND ?", @date_from, @date_to])
Jean-Philippe Lang
added simple svn statistics graphs, rendered using SVG::Graph...
r377 changes_by_month = [0] * 12
changes_by_day.each {|c| changes_by_month[c.first.to_date.months_ago] += c.last }
fields = []
Jean-Philippe Lang
Merged Rails 2.2 branch. Redmine now requires Rails 2.2.2....
r2430 12.times {|m| fields << month_name(((Date.today.month - 1 - m) % 12) + 1)}
Jean-Philippe Lang
added simple svn statistics graphs, rendered using SVG::Graph...
r377
graph = SVG::Graph::Bar.new(
:height => 300,
Jean-Philippe Lang
Wider SVG graphs in repository stats....
r1587 :width => 800,
Jean-Philippe Lang
added simple svn statistics graphs, rendered using SVG::Graph...
r377 :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)
Eric Davis
Upgraded to Rails 2.3.4 (#3597)...
r2773 commits_by_author.to_a.sort! {|x, y| x.last <=> y.last}
Jean-Philippe Lang
added changes counts on the "commits per author" svn stat graph...
r382
changes_by_author = repository.changes.count(:all, :group => :committer)
h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o}
Jean-Philippe Lang
added simple svn statistics graphs, rendered using SVG::Graph...
r377
fields = commits_by_author.collect {|r| r.first}
Jean-Philippe Lang
added changes counts on the "commits per author" svn stat graph...
r382 commits_data = commits_by_author.collect {|r| r.last}
changes_data = commits_by_author.collect {|r| h[r.first] || 0}
Jean-Philippe Lang
added simple svn statistics graphs, rendered using SVG::Graph...
r377
fields = fields + [""]*(10 - fields.length) if fields.length<10
Jean-Philippe Lang
added changes counts on the "commits per author" svn stat graph...
r382 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
Jean-Philippe Lang
added simple svn statistics graphs, rendered using SVG::Graph...
r377
Jean-Philippe Lang
Commits per author graph: remove email adress in usernames (#1066)....
r1342 # Remove email adress in usernames
fields = fields.collect {|c| c.gsub(%r{<.+@.+>}, '') }
Jean-Philippe Lang
added simple svn statistics graphs, rendered using SVG::Graph...
r377 graph = SVG::Graph::BarHorizontal.new(
Jean-Philippe Lang
Wider SVG graphs in repository stats....
r1587 :height => 400,
:width => 800,
Jean-Philippe Lang
added simple svn statistics graphs, rendered using SVG::Graph...
r377 :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(
Jean-Philippe Lang
added changes counts on the "commits per author" svn stat graph...
r382 :data => commits_data,
Jean-Philippe Lang
added simple svn statistics graphs, rendered using SVG::Graph...
r377 :title => l(:label_revision_plural)
)
Jean-Philippe Lang
added changes counts on the "commits per author" svn stat graph...
r382
graph.add_data(
:data => changes_data,
:title => l(:label_change_plural)
)
Jean-Philippe Lang
added simple svn statistics graphs, rendered using SVG::Graph...
r377 graph.burn
end
Jean-Philippe Lang
svn browser merged in trunk...
r103 end
Jean-Philippe Lang
added simple svn statistics graphs, rendered using SVG::Graph...
r377
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
Jean-Philippe Lang
patch #9627 Add Side by Side in Diff view (Cyril Mougel)...
r387 end
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556
class String
def with_leading_slash
starts_with?('/') ? self : "/#{self}"
end
end