huang 10 years ago
parent b1ba6d576a
commit f189e3cde8

@ -29,7 +29,7 @@ class RepositoriesController < ApplicationController
menu_item :repository menu_item :repository
menu_item :settings, :only => [:new, :create, :edit, :update, :destroy, :committers] menu_item :settings, :only => [:new, :create, :edit, :update, :destroy, :committers]
default_search_scope :changesets default_search_scope :changesets
before_filter :find_project_by_project_id, :only => [:new, :create, :newrepo] before_filter :find_project_by_project_id, :only => [:new, :create, :newrepo]
before_filter :find_repository, :only => [:edit, :update, :destroy, :committers] before_filter :find_repository, :only => [:edit, :update, :destroy, :committers]
before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo] before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo]
@ -42,7 +42,7 @@ class RepositoriesController < ApplicationController
include RepositoriesHelper include RepositoriesHelper
helper :project_score helper :project_score
#@root_path = RepositoriesHelper::ROOT_PATH #@root_path = RepositoriesHelper::ROOT_PATH
rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed
def new def new
@ -62,8 +62,8 @@ class RepositoriesController < ApplicationController
end end
end end
def newrepo def newrepo
scm = params[:repository_scm] || (Redmine::Scm::Base.all & Setting.enabled_scm).first scm = params[:repository_scm] || (Redmine::Scm::Base.all & Setting.enabled_scm).first
@repository = Repository.factory(scm) @repository = Repository.factory(scm)
@ -76,23 +76,23 @@ class RepositoriesController < ApplicationController
render :layout => 'base_projects' render :layout => 'base_projects'
end end
end end
def fork def fork
@repository_url = params[:repository_url] @repository_url = params[:repository_url]
# @repository.url # @repository.url
# system "htpasswd -mb "+@root_path+"user.passwd "+params[:repository][:identifier]+" "+@upasswd # system "htpasswd -mb "+@root_path+"user.passwd "+params[:repository][:identifier]+" "+@upasswd
# system "echo -e '"+params[:project_id]+"-"+params[:repository][:identifier]+"-write:"+ # system "echo -e '"+params[:project_id]+"-"+params[:repository][:identifier]+"-write:"+
# " "+params[:repository][:identifier]+"' >> "+@root_path+"group.passwd" # " "+params[:repository][:identifier]+"' >> "+@root_path+"group.passwd"
system "git clone --bare "+@repository_url system "git clone --bare "+@repository_url
# system "mv "+@project_path+"/hooks/post-update{.sample,}" # system "mv "+@project_path+"/hooks/post-update{.sample,}"
# system "chmod a+x "+@project_path+"/hooks/post-update" # system "chmod a+x "+@project_path+"/hooks/post-update"
# system "."+@project_path+"/hooks/post-update" # system "."+@project_path+"/hooks/post-update"
# system "echo -e 'Allow from all \n Order Deny,Allow \n "+ # system "echo -e 'Allow from all \n Order Deny,Allow \n "+
# "<Limit PUT POST DELETE PROPPATCH MKCOL COPY MOVE LOCK UNLOCK> \n"+ # "<Limit PUT POST DELETE PROPPATCH MKCOL COPY MOVE LOCK UNLOCK> \n"+
# "Require group "+params[:project_id]+"-"+params[:repository][:identifier]+"-write \n "+ # "Require group "+params[:project_id]+"-"+params[:repository][:identifier]+"-write \n "+
# "</Limit> \n ' >>"+ # "</Limit> \n ' >>"+
# @project_path+"/.htaccess" # @project_path+"/.htaccess"
flash[:notice] = l(:label_notice_fork_successed) flash[:notice] = l(:label_notice_fork_successed)
@repositories = @project.repositories @repositories = @project.repositories
render :action => 'show', :layout => 'base_projects' render :action => 'show', :layout => 'base_projects'
@ -141,7 +141,7 @@ update
logger.info "the value of create repository"+@root_path+": "+@repository_name+": "+@project_path+": "+@repo_name logger.info "the value of create repository"+@root_path+": "+@repository_name+": "+@project_path+": "+@repo_name
attrs = pickup_extra_info attrs = pickup_extra_info
if((@repository_tag!="")&&params[:repository_scm]=="Git") if((@repository_tag!="")&&params[:repository_scm]=="Git")
params[:repository][:url]=@project_path params[:repository][:url]=@project_path
end end
###xianbo ###xianbo
@repository = Repository.factory(params[:repository_scm]) @repository = Repository.factory(params[:repository_scm])
@ -175,7 +175,7 @@ update
end end
redirect_to settings_project_url(@project, :tab => 'repositories',:repository_error_message=>@repository.errors.full_messages) redirect_to settings_project_url(@project, :tab => 'repositories',:repository_error_message=>@repository.errors.full_messages)
else if(@repository_tag.blank?) else if(@repository_tag.blank?)
#render :action => 'newrepo', :layout =>'base_projects' #render :action => 'newrepo', :layout =>'base_projects'
redirect_to settings_project_url(@project, :tab => 'repositories',:repository => "pswd_is_null",:repository_error_message=>@repository.errors.full_messages) redirect_to settings_project_url(@project, :tab => 'repositories',:repository => "pswd_is_null",:repository_error_message=>@repository.errors.full_messages)
else else
redirect_to settings_project_url(@project, :tab => 'repositories',:repository => @repository,:repository_error_message=>@repository.errors.full_messages) redirect_to settings_project_url(@project, :tab => 'repositories',:repository => @repository,:repository_error_message=>@repository.errors.full_messages)
@ -185,7 +185,7 @@ update
end end
end end
def edit def edit
end end
@ -230,11 +230,11 @@ update
flash[:notice] = l(:notice_successful_update) flash[:notice] = l(:notice_successful_update)
redirect_to settings_project_url(@project, :tab => 'repositories') redirect_to settings_project_url(@project, :tab => 'repositories')
elsif request.get? elsif request.get?
respond_to do |format| respond_to do |format|
format.html{ format.html{
render :layout => "base_projects" render :layout => "base_projects"
} }
end end
end end
@ -275,7 +275,7 @@ update
@entries ? render(:partial => 'dir_list_content') : render(:nothing => true) @entries ? render(:partial => 'dir_list_content') : render(:nothing => true)
else else
#Modified by young #Modified by young
# (show_error_not_found; return) unless @entries # (show_error_not_found; return) unless @entries
@changesets = @repository.latest_changesets(@path, @rev) @changesets = @repository.latest_changesets(@path, @rev)
@properties = @repository.properties(@path, @rev) @properties = @repository.properties(@path, @rev)
@repositories = @project.repositories @repositories = @project.repositories
@ -283,7 +283,7 @@ update
project_path_cut = RepositoriesHelper::PROJECT_PATH_CUT project_path_cut = RepositoriesHelper::PROJECT_PATH_CUT
ip = RepositoriesHelper::REPO_IP_ADDRESS ip = RepositoriesHelper::REPO_IP_ADDRESS
@repos_url = "http://"+@repository.login.to_s+"_"+@repository.identifier.to_s+"@"+ip.to_s+ @repos_url = "http://"+@repository.login.to_s+"_"+@repository.identifier.to_s+"@"+ip.to_s+
@repository.url.slice(project_path_cut, @repository.url.length).to_s @repository.url.slice(project_path_cut, @repository.url.length).to_s
if @course_tag == 1 if @course_tag == 1
render :action => 'show', :layout => 'base_courses' render :action => 'show', :layout => 'base_courses'
else else
@ -309,10 +309,10 @@ update
per_page_option, per_page_option,
params['page'] params['page']
@changesets = @repository.changesets. @changesets = @repository.changesets.
limit(@changeset_pages.per_page). limit(@changeset_pages.per_page).
offset(@changeset_pages.offset). offset(@changeset_pages.offset).
includes(:user, :repository, :parents). includes(:user, :repository, :parents).
all all
respond_to do |format| respond_to do |format|
format.html { render :layout => 'base_projects' } format.html { render :layout => 'base_projects' }
@ -338,8 +338,8 @@ update
@content = @repository.cat(@path, @rev) @content = @repository.cat(@path, @rev)
(show_error_not_found; return) unless @content (show_error_not_found; return) unless @content
if is_raw || if is_raw ||
(@content.size && @content.size > Setting.file_max_size_displayed.to_i.kilobyte) || (@content.size && @content.size > Setting.file_max_size_displayed.to_i.kilobyte) ||
! is_entry_text_data?(@content, @path) ! is_entry_text_data?(@content, @path)
# Force the download # Force the download
send_opt = { :filename => filename_for_content_disposition(@path.split('/').last) } send_opt = { :filename => filename_for_content_disposition(@path.split('/').last) }
send_type = Redmine::MimeType.of(@path) send_type = Redmine::MimeType.of(@path)
@ -422,8 +422,8 @@ update
filename = "changeset_r#{@rev}" filename = "changeset_r#{@rev}"
filename << "_r#{@rev_to}" if @rev_to filename << "_r#{@rev_to}" if @rev_to
send_data @diff.join, :filename => "#{filename}.diff", send_data @diff.join, :filename => "#{filename}.diff",
:type => 'text/x-patch', :type => 'text/x-patch',
:disposition => 'attachment' :disposition => 'attachment'
else else
@diff_type = params[:type] || User.current.pref[:diff_type] || 'inline' @diff_type = params[:type] || User.current.pref[:diff_type] || 'inline'
@diff_type = 'inline' unless %w(inline sbs).include?(@diff_type) @diff_type = 'inline' unless %w(inline sbs).include?(@diff_type)
@ -434,7 +434,7 @@ update
User.current.preference.save User.current.preference.save
end end
@cache_key = "repositories/diff/#{@repository.id}/" + @cache_key = "repositories/diff/#{@repository.id}/" +
Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}-#{current_language}") Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}-#{current_language}")
unless read_fragment(@cache_key) unless read_fragment(@cache_key)
@diff = @repository.diff(@path, @rev, @rev_to) @diff = @repository.diff(@path, @rev, @rev_to)
unless @diff unless @diff
@ -461,16 +461,16 @@ update
def graph def graph
data = nil data = nil
case params[:graph] case params[:graph]
when "commits_per_month" when "commits_per_month"
data = graph_commits_per_month(@repository) data = graph_commits_per_month(@repository)
when "commits_per_author" when "commits_per_author"
data = graph_commits_per_author(@repository) data = graph_commits_per_author(@repository)
when "author_commits_per_month" when "author_commits_per_month"
data = graph_author_commits_per_month(@repository) data = graph_author_commits_per_month(@repository)
when "author_commits_six_month" when "author_commits_six_month"
data = author_commits_six_month(@repository) data = author_commits_six_month(@repository)
when "author_code_six_months" when "author_code_six_months"
data = author_code_six_month(@repository) data = author_code_six_month(@repository)
end end
if data if data
headers["Content-Type"] = "image/svg+xml" headers["Content-Type"] = "image/svg+xml"
@ -550,14 +550,14 @@ update
@date_from = @date_to << 11 @date_from = @date_to << 11
@date_from = Date.civil(@date_from.year, @date_from.month, 1) @date_from = Date.civil(@date_from.year, @date_from.month, 1)
commits_by_day = Changeset.count( commits_by_day = Changeset.count(
:all, :group => :commit_date, :all, :group => :commit_date,
:conditions => ["repository_id = ? AND commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to]) :conditions => ["repository_id = ? AND commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to])
commits_by_month = [0] * 12 commits_by_month = [0] * 12
commits_by_day.each {|c| commits_by_month[(@date_to.month - c.first.to_date.month) % 12] += c.last } commits_by_day.each {|c| commits_by_month[(@date_to.month - c.first.to_date.month) % 12] += c.last }
changes_by_day = Change.count( changes_by_day = Change.count(
:all, :group => :commit_date, :include => :changeset, :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]) :conditions => ["#{Changeset.table_name}.repository_id = ? AND #{Changeset.table_name}.commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to])
changes_by_month = [0] * 12 changes_by_month = [0] * 12
changes_by_day.each {|c| changes_by_month[(@date_to.month - c.first.to_date.month) % 12] += c.last } changes_by_day.each {|c| changes_by_month[(@date_to.month - c.first.to_date.month) % 12] += c.last }
@ -565,26 +565,26 @@ update
12.times {|m| fields << month_name(((Date.today.month - 1 - m) % 12) + 1)} 12.times {|m| fields << month_name(((Date.today.month - 1 - m) % 12) + 1)}
graph = SVG::Graph::Bar.new( graph = SVG::Graph::Bar.new(
:height => 300, :height => 300,
:width => 600, :width => 600,
:fields => fields.reverse, :fields => fields.reverse,
:stack => :side, :stack => :side,
:scale_integers => true, :scale_integers => true,
:step_x_labels => 2, :step_x_labels => 2,
:show_data_values => true, :show_data_values => true,
:graph_title => l(:label_commits_per_month), :graph_title => l(:label_commits_per_month),
:show_graph_title => true :show_graph_title => true
) )
# 具状图 # 具状图
graph.add_data( graph.add_data(
:data => commits_by_month[0..11].reverse, :data => commits_by_month[0..11].reverse,
:title => l(:label_revision_plural) :title => l(:label_revision_plural)
) )
graph.add_data( graph.add_data(
:data => changes_by_month[0..11].reverse, :data => changes_by_month[0..11].reverse,
:title => l(:label_change_plural) :title => l(:label_change_plural)
) )
graph.burn graph.burn
@ -609,23 +609,23 @@ update
fields = fields.collect {|c| c.gsub(%r{<.+@.+>}, '') } fields = fields.collect {|c| c.gsub(%r{<.+@.+>}, '') }
graph = SVG::Graph::BarHorizontal.new( graph = SVG::Graph::BarHorizontal.new(
:height => 400, :height => 400,
:width => 600, :width => 600,
:fields => fields, :fields => fields,
:stack => :side, :stack => :side,
:scale_integers => true, :scale_integers => true,
:show_data_values => true, :show_data_values => true,
:rotate_y_labels => false, :rotate_y_labels => false,
:graph_title => l(:label_commits_per_author), :graph_title => l(:label_commits_per_author),
:show_graph_title => true :show_graph_title => true
) )
graph.add_data( graph.add_data(
:data => commits_data, :data => commits_data,
:title => l(:label_revision_plural) :title => l(:label_revision_plural)
) )
graph.add_data( graph.add_data(
:data => changes_data, :data => changes_data,
:title => l(:label_change_plural) :title => l(:label_change_plural)
) )
graph.burn graph.burn
end end
@ -636,7 +636,7 @@ update
@date_from = @date_to << 12 @date_from = @date_to << 12
@date_from = Date.civil(@date_from.year, @date_from.month, @date_from.day) @date_from = Date.civil(@date_from.year, @date_from.month, @date_from.day)
commits_by_author = Changeset.count(:all, :group => :committer, commits_by_author = Changeset.count(:all, :group => :committer,
:conditions => ["#{Changeset.table_name}.repository_id = ? AND #{Changeset.table_name}.commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to]) :conditions => ["#{Changeset.table_name}.repository_id = ? AND #{Changeset.table_name}.commit_date BETWEEN ? AND ?", repository.id, @date_from, @date_to])
commits_by_author = commits_by_author.to_a.sort! {|x, y| x.last <=> y.last}.last(25) commits_by_author = commits_by_author.to_a.sort! {|x, y| x.last <=> y.last}.last(25)
fields = commits_by_author.collect {|r| r.first} fields = commits_by_author.collect {|r| r.first}

Loading…
Cancel
Save