2011-11-16 06:38:53 +01:00
|
|
|
class RefsController < ApplicationController
|
2012-05-27 11:34:25 +02:00
|
|
|
include Gitlab::Encode
|
2011-11-16 06:38:53 +01:00
|
|
|
before_filter :project
|
|
|
|
|
|
|
|
# Authorize
|
|
|
|
before_filter :add_project_abilities
|
|
|
|
before_filter :authorize_read_project!
|
2012-02-21 23:31:18 +01:00
|
|
|
before_filter :authorize_code_access!
|
2011-11-16 06:38:53 +01:00
|
|
|
before_filter :require_non_empty_project
|
|
|
|
|
2011-12-04 21:34:39 +01:00
|
|
|
before_filter :ref
|
2012-07-10 21:52:38 +02:00
|
|
|
before_filter :define_tree_vars, :only => [:tree, :blob, :blame, :logs_tree]
|
2012-01-28 00:49:14 +01:00
|
|
|
before_filter :render_full_content
|
|
|
|
|
2011-12-04 21:34:39 +01:00
|
|
|
layout "project"
|
|
|
|
|
2011-11-16 18:19:18 +01:00
|
|
|
def switch
|
2012-01-29 20:30:03 +01:00
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
|
|
|
new_path = if params[:destination] == "tree"
|
|
|
|
tree_project_ref_path(@project, params[:ref])
|
|
|
|
else
|
|
|
|
project_commits_path(@project, :ref => params[:ref])
|
|
|
|
end
|
2011-11-16 18:19:18 +01:00
|
|
|
|
2012-01-29 20:30:03 +01:00
|
|
|
redirect_to new_path
|
|
|
|
end
|
|
|
|
format.js do
|
|
|
|
@ref = params[:ref]
|
|
|
|
define_tree_vars
|
|
|
|
render "tree"
|
|
|
|
end
|
|
|
|
end
|
2011-11-16 18:19:18 +01:00
|
|
|
end
|
|
|
|
|
2011-11-16 06:38:53 +01:00
|
|
|
#
|
|
|
|
# Repository preview
|
|
|
|
#
|
|
|
|
def tree
|
|
|
|
respond_to do |format|
|
2011-11-20 21:32:12 +01:00
|
|
|
format.html
|
2011-12-20 07:49:14 +01:00
|
|
|
format.js do
|
|
|
|
# disable cache to allow back button works
|
|
|
|
no_cache_headers
|
|
|
|
end
|
2011-11-16 06:38:53 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-07-10 21:52:38 +02: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 13:08:24 +02:00
|
|
|
last_commit = CommitDecorator.decorate(last_commit)
|
|
|
|
{
|
2012-07-10 21:52:38 +02:00
|
|
|
:file_name => content.name,
|
|
|
|
:commit => last_commit
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-11-16 06:38:53 +01:00
|
|
|
def blob
|
2011-11-21 07:16:10 +01:00
|
|
|
if @tree.is_blob?
|
2012-05-26 20:20:35 +02:00
|
|
|
if @tree.text?
|
|
|
|
encoding = detect_encoding(@tree.data)
|
|
|
|
mime_type = encoding ? "text/plain; charset=#{encoding}" : "text/plain"
|
|
|
|
else
|
|
|
|
mime_type = @tree.mime_type
|
|
|
|
end
|
|
|
|
|
2012-01-25 08:15:08 +01:00
|
|
|
send_data(
|
|
|
|
@tree.data,
|
2012-05-26 20:20:35 +02:00
|
|
|
:type => mime_type,
|
2012-01-25 08:15:08 +01:00
|
|
|
:disposition => 'inline',
|
|
|
|
:filename => @tree.name
|
|
|
|
)
|
2011-11-16 06:38:53 +01:00
|
|
|
else
|
|
|
|
head(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-05-17 18:11:45 +02:00
|
|
|
def blame
|
|
|
|
@blame = Grit::Blob.blame(@repo, @commit.id, params[:path])
|
|
|
|
end
|
|
|
|
|
2011-11-16 06:38:53 +01:00
|
|
|
protected
|
|
|
|
|
2011-11-21 07:16:10 +01:00
|
|
|
def define_tree_vars
|
2012-02-05 11:23:14 +01:00
|
|
|
params[:path] = nil if params[:path].blank?
|
|
|
|
|
2011-11-21 07:16:10 +01:00
|
|
|
@repo = project.repo
|
|
|
|
@commit = project.commit(@ref)
|
2012-08-02 02:31:45 +02:00
|
|
|
@commit = CommitDecorator.decorate(@commit)
|
2011-11-21 07:16:10 +01:00
|
|
|
@tree = Tree.new(@commit.tree, project, @ref, params[:path])
|
|
|
|
@tree = TreeDecorator.new(@tree)
|
2012-07-10 21:52:38 +02:00
|
|
|
@hex_path = Digest::SHA1.hexdigest(params[:path] || "/")
|
|
|
|
|
|
|
|
if params[:path]
|
|
|
|
@history_path = tree_file_project_ref_path(@project, @ref, params[:path])
|
|
|
|
@logs_path = logs_file_project_ref_path(@project, @ref, params[:path])
|
|
|
|
else
|
|
|
|
@history_path = tree_project_ref_path(@project, @ref)
|
|
|
|
@logs_path = logs_tree_project_ref_path(@project, @ref)
|
|
|
|
end
|
2011-12-05 08:23:53 +01:00
|
|
|
rescue
|
|
|
|
return render_404
|
2011-11-21 07:16:10 +01:00
|
|
|
end
|
|
|
|
|
2011-11-16 06:38:53 +01:00
|
|
|
def ref
|
|
|
|
@ref = params[:id]
|
|
|
|
end
|
|
|
|
end
|