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