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

90 lines
1.9 KiB
Ruby
Raw Normal View History

2011-11-16 00:38:53 -05:00
class RefsController < ApplicationController
2012-05-27 05:34:25 -04:00
include Gitlab::Encode
2011-11-16 00:38:53 -05:00
before_filter :project
# Authorize
before_filter :add_project_abilities
before_filter :authorize_read_project!
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-05-17 12:11:45 -04:00
before_filter :define_tree_vars, :only => [:tree, :blob, :blame]
2012-01-27 18:49:14 -05:00
before_filter :render_full_content
2011-12-04 15:34:39 -05:00
layout "project"
2011-11-16 12:19:18 -05:00
def switch
2012-01-29 14:30:03 -05: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 12:19:18 -05:00
2012-01-29 14:30:03 -05:00
redirect_to new_path
end
format.js do
@ref = params[:ref]
define_tree_vars
render "tree"
end
end
2011-11-16 12:19:18 -05:00
end
2011-11-16 00:38:53 -05:00
#
# Repository preview
#
def tree
respond_to do |format|
2011-11-20 15:32:12 -05:00
format.html
format.js do
# disable cache to allow back button works
no_cache_headers
end
2011-11-16 00:38:53 -05:00
end
end
def blob
2011-11-21 01:16:10 -05:00
if @tree.is_blob?
if @tree.text?
encoding = detect_encoding(@tree.data)
mime_type = encoding ? "text/plain; charset=#{encoding}" : "text/plain"
else
mime_type = @tree.mime_type
end
send_data(
@tree.data,
:type => mime_type,
:disposition => 'inline',
:filename => @tree.name
)
2011-11-16 00:38:53 -05:00
else
head(404)
end
end
2012-05-17 12:11:45 -04:00
def blame
@blame = Grit::Blob.blame(@repo, @commit.id, params[:path])
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)
@tree = Tree.new(@commit.tree, project, @ref, params[:path])
@tree = TreeDecorator.new(@tree)
2011-12-05 02:23:53 -05:00
rescue
return render_404
2011-11-21 01:16:10 -05:00
end
2011-11-16 00:38:53 -05:00
def ref
@ref = params[:id]
end
end