2011-11-16 06:38:53 +01:00
|
|
|
class RefsController < ApplicationController
|
|
|
|
before_filter :project
|
|
|
|
|
|
|
|
# Authorize
|
|
|
|
before_filter :add_project_abilities
|
|
|
|
before_filter :authorize_read_project!
|
|
|
|
before_filter :require_non_empty_project
|
|
|
|
|
2011-12-04 21:34:39 +01:00
|
|
|
before_filter :ref
|
|
|
|
before_filter :define_tree_vars, :only => [:tree, :blob]
|
|
|
|
layout "project"
|
|
|
|
|
2011-11-16 18:19:18 +01:00
|
|
|
def switch
|
|
|
|
new_path = if params[:destination] == "tree"
|
|
|
|
tree_project_ref_path(@project, params[:ref])
|
|
|
|
else
|
|
|
|
project_commits_path(@project, :ref => params[:ref])
|
|
|
|
end
|
|
|
|
|
|
|
|
redirect_to new_path
|
|
|
|
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
|
|
|
|
rescue
|
|
|
|
return render_404
|
|
|
|
end
|
|
|
|
|
|
|
|
def blob
|
2011-11-21 07:16:10 +01:00
|
|
|
if @tree.is_blob?
|
2012-01-25 08:15:08 +01:00
|
|
|
send_data(
|
|
|
|
@tree.data,
|
|
|
|
:type => @tree.text? ? "text/plain" : @tree.mime_type,
|
|
|
|
:disposition => 'inline',
|
|
|
|
:filename => @tree.name
|
|
|
|
)
|
2011-11-16 06:38:53 +01:00
|
|
|
else
|
|
|
|
head(404)
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
return render_404
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
2011-11-21 07:16:10 +01:00
|
|
|
def define_tree_vars
|
|
|
|
@repo = project.repo
|
|
|
|
@commit = project.commit(@ref)
|
|
|
|
@tree = Tree.new(@commit.tree, project, @ref, params[:path])
|
|
|
|
@tree = TreeDecorator.new(@tree)
|
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
|