##// END OF EJS Templates
Applied 'register notice' patch by Matt Jones....
Applied 'register notice' patch by Matt Jones. The user is now redirected to the login screen after having registered. git-svn-id: http://redmine.rubyforge.org/svn/trunk@601 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r597:2d5ac54d2eb9
r598:acebceb1d74b
Show More
repositories_controller.rb
231 lines | 7.4 KiB | text/x-ruby | RubyLexer
/ app / controllers / repositories_controller.rb
Jean-Philippe Lang
svn browser merged in trunk...
r103 # redMine - project management software
Jean-Philippe Lang
SVN commits are now stored in the database, and added to the activity view and the search engine....
r374 # Copyright (C) 2006-2007 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
svn browser merged in trunk...
r103 class RepositoriesController < ApplicationController
layout 'base'
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556 before_filter :find_project, :except => [:update_form]
before_filter :authorize, :except => [:update_form, :stats, :graph]
Jean-Philippe Lang
added simple svn statistics graphs, rendered using SVG::Graph...
r377 before_filter :check_project_privacy, :only => [:stats, :graph]
Jean-Philippe Lang
svn browser merged in trunk...
r103 def show
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556 # check if new revisions have been committed in the repository
@repository.fetch_changesets if Setting.autofetch_changesets?
Jean-Philippe Lang
SVN commits are now stored in the database, and added to the activity view and the search engine....
r374 # get entries for the browse frame
Jean-Philippe Lang
Changesets stored in the database are now displayed on the repository page even if the repository can not be reached (eg. svnserve down)....
r576 @entries = @repository.entries('')
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556 # latest changesets
@changesets = @repository.changesets.find(:all, :limit => 10, :order => "committed_on DESC")
Jean-Philippe Lang
Changesets stored in the database are now displayed on the repository page even if the repository can not be reached (eg. svnserve down)....
r576 show_error and return unless @entries || @changesets.any?
Jean-Philippe Lang
svn browser merged in trunk...
r103 end
def browse
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556 @entries = @repository.entries(@path, @rev)
show_error and return unless @entries
end
def changes
@entry = @repository.scm.entry(@path, @rev)
show_error and return unless @entry
@changes = Change.find(:all, :include => :changeset,
:conditions => ["repository_id = ? AND path = ?", @repository.id, @path.with_leading_slash],
:order => "committed_on DESC")
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,
25,
params['page']
@changesets = @repository.changesets.find(:all,
:limit => @changeset_pages.items_per_page,
:offset => @changeset_pages.current.offset)
Jean-Philippe Lang
added pagination on revisions list...
r378 render :action => "revisions", :layout => false if request.xhr?
Jean-Philippe Lang
svn browser merged in trunk...
r103 end
def entry
Jean-Philippe Lang
Text files can now be viewed online when browsing the repository....
r518 @content = @repository.scm.cat(@path, @rev)
show_error and return unless @content
if 'raw' == params[:format]
send_data @content, :filename => @path.split('/').last
Jean-Philippe Lang
svn browser merged in trunk...
r103 end
end
def revision
Jean-Philippe Lang
SVN commits are now stored in the database, and added to the activity view and the search engine....
r374 @changeset = @repository.changesets.find_by_revision(@rev)
show_error and return unless @changeset
Jean-Philippe Lang
Fixed: performance issue on RepositoriesController#revisions when a changeset has a great number of changes (eg. 100,000)....
r532 @changes_count = @changeset.changes.size
@changes_pages = Paginator.new self, @changes_count, 150, params['page']
@changes = @changeset.changes.find(:all,
:limit => @changes_pages.items_per_page,
:offset => @changes_pages.current.offset)
render :action => "revision", :layout => false if request.xhr?
Jean-Philippe Lang
svn browser merged in trunk...
r103 end
def diff
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556 @rev_to = params[:rev_to] ? params[:rev_to].to_i : (@rev - 1)
Jean-Philippe Lang
Added fragment caching for svn diffs....
r496 @diff_type = ('sbs' == params[:type]) ? 'sbs' : 'inline'
@cache_key = "repositories/diff/#{@repository.id}/" + Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}")
unless read_fragment(@cache_key)
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556 @diff = @repository.diff(@path, @rev, @rev_to, type)
Jean-Philippe Lang
Added fragment caching for svn diffs....
r496 show_error and return unless @diff
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
Added basic support for CVS and Mercurial SCMs....
r556 def update_form
@repository = Repository.factory(params[:repository_scm])
render :partial => 'projects/repository', :locals => {:repository => @repository}
end
Jean-Philippe Lang
svn browser merged in trunk...
r103 private
def find_project
@project = Project.find(params[:id])
@repository = @project.repository
Jean-Philippe Lang
send a 404 when trying to access an unexisting repository...
r325 render_404 and return false unless @repository
Jean-Philippe Lang
Fixed: error when viewing a file diff from a revision view (only if repository url doesn't point to the root of the repository)....
r525 @path = params[:path].squeeze('/') if params[:path]
Jean-Philippe Lang
svn browser merged in trunk...
r103 @path ||= ''
Jean-Philippe Lang
Added basic support for CVS and Mercurial SCMs....
r556 @rev = params[:rev].to_i if params[:rev]
Jean-Philippe Lang
ActiveRecord::RecordNotFound exceptions handled more gracefully...
r130 rescue ActiveRecord::RecordNotFound
render_404
Jean-Philippe Lang
svn browser merged in trunk...
r103 end
def show_error
Jean-Philippe Lang
Applied the flash notices patch by Matt Jones (slightly edited)....
r597 flash.now[:error] = l(:notice_scm_error)
Jean-Philippe Lang
svn browser merged in trunk...
r103 render :nothing => true, :layout => true
end
Jean-Philippe Lang
added simple svn statistics graphs, rendered using SVG::Graph...
r377
def graph_commits_per_month(repository)
@date_to = Date.today
@date_from = @date_to << 12
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)
changes_by_month = [0] * 12
changes_by_day.each {|c| changes_by_month[c.first.to_date.months_ago] += c.last }
fields = []
month_names = l(:actionview_datehelper_select_month_names_abbr).split(',')
12.times {|m| fields << month_names[((Date.today.month - 1 - m) % 12)]}
graph = SVG::Graph::Bar.new(
:height => 300,
:width => 500,
: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)
commits_by_author.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
graph = SVG::Graph::BarHorizontal.new(
:height => 300,
:width => 500,
: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