gitlab-org--gitlab-foss/app/controllers/refs_controller.rb

70 lines
1.8 KiB
Ruby
Raw Normal View History

class RefsController < ProjectResourceController
2011-11-16 05:38:53 +00:00
# Authorize
before_filter :authorize_read_project!
before_filter :authorize_code_access!
2011-11-16 05:38:53 +00:00
before_filter :require_non_empty_project
2011-12-04 20:34:39 +00:00
before_filter :ref
before_filter :define_tree_vars, only: [:blob, :logs_tree]
2012-01-27 23:49:14 +00:00
def switch
respond_to do |format|
format.html do
2012-01-29 19:30:03 +00:00
new_path = if params[:destination] == "tree"
project_tree_path(@project, (@ref + "/" + params[:path]))
elsif params[:destination] == "graph"
project_graph_path(@project, @ref)
2012-01-29 19:30:03 +00:00
else
project_commits_path(@project, @ref)
2012-01-29 19:30:03 +00:00
end
2011-11-16 17:19:18 +00:00
2012-09-17 17:49:57 +00:00
redirect_to new_path
2012-01-29 19:30:03 +00:00
end
2012-09-17 17:49:57 +00:00
format.js do
2012-01-29 19:30:03 +00:00
@ref = params[:ref]
define_tree_vars
render "tree"
end
end
2011-11-16 17:19:18 +00:00
end
2012-07-10 19:52:38 +00:00
def logs_tree
contents = @tree.contents
@logs = contents.map do |content|
file = params[:path] ? File.join(params[:path], content.name) : content.name
2013-01-03 19:09:18 +00:00
last_commit = @repo.commits(@commit.id, file, 1).last
2012-07-22 11:08:24 +00:00
last_commit = CommitDecorator.decorate(last_commit)
{
2012-09-17 17:49:57 +00:00
file_name: content.name,
commit: last_commit
2012-07-10 19:52:38 +00:00
}
end
end
2011-11-16 05:38:53 +00:00
protected
2011-11-21 06:16:10 +00:00
def define_tree_vars
2012-02-05 10:23:14 +00:00
params[:path] = nil if params[:path].blank?
2013-01-03 19:09:18 +00:00
@repo = project.repository
@commit = @repo.commit(@ref)
2012-08-02 00:31:45 +00:00
@commit = CommitDecorator.decorate(@commit)
2013-01-03 19:09:18 +00:00
@tree = Tree.new(@commit.tree, @ref, params[:path])
2011-11-21 06:16:10 +00:00
@tree = TreeDecorator.new(@tree)
@hex_path = Digest::SHA1.hexdigest(params[:path] || "")
2012-07-10 19:52:38 +00:00
if params[:path]
2012-09-17 17:49:57 +00:00
@logs_path = logs_file_project_ref_path(@project, @ref, params[:path])
2012-07-10 19:52:38 +00:00
else
2012-09-17 17:49:57 +00:00
@logs_path = logs_tree_project_ref_path(@project, @ref)
2012-07-10 19:52:38 +00:00
end
2011-12-05 07:23:53 +00:00
rescue
return render_404
2011-11-21 06:16:10 +00:00
end
2012-09-17 17:49:57 +00:00
2011-11-16 05:38:53 +00:00
def ref
@ref = params[:id] || params[:ref]
2011-11-16 05:38:53 +00:00
end
end