Commit 3f35cccf authored by gitlabhq's avatar gitlabhq

ref controller refactored

parent 4bf4efe7
class RefsController < ApplicationController class RefsController < ApplicationController
before_filter :project before_filter :project
before_filter :ref before_filter :ref
before_filter :define_tree_vars, :only => [:tree, :blob]
layout "project" layout "project"
# Authorize # Authorize
...@@ -22,12 +23,6 @@ class RefsController < ApplicationController ...@@ -22,12 +23,6 @@ class RefsController < ApplicationController
# Repository preview # Repository preview
# #
def tree def tree
@repo = project.repo
@commit = @repo.commits(@ref).first
@tree = Tree.new(@commit.tree, project, @ref, params[:path])
@tree = TreeDecorator.new(@tree)
respond_to do |format| respond_to do |format|
format.html format.html
format.js do format.js do
...@@ -40,11 +35,7 @@ class RefsController < ApplicationController ...@@ -40,11 +35,7 @@ class RefsController < ApplicationController
end end
def blob def blob
@repo = project.repo if @tree.is_blob?
@commit = project.commit(@ref)
@tree = project.tree(@commit, params[:path])
if @tree.is_a?(Grit::Blob)
send_data(@tree.data, :type => @tree.mime_type, :disposition => 'inline', :filename => @tree.name) send_data(@tree.data, :type => @tree.mime_type, :disposition => 'inline', :filename => @tree.name)
else else
head(404) head(404)
...@@ -55,6 +46,13 @@ class RefsController < ApplicationController ...@@ -55,6 +46,13 @@ class RefsController < ApplicationController
protected protected
def define_tree_vars
@repo = project.repo
@commit = project.commit(@ref)
@tree = Tree.new(@commit.tree, project, @ref, params[:path])
@tree = TreeDecorator.new(@tree)
end
def ref def ref
@ref = params[:id] @ref = params[:id]
end end
......
...@@ -5,6 +5,7 @@ class Tree ...@@ -5,6 +5,7 @@ class Tree
:basename, :basename,
:name, :name,
:data, :data,
:mime_type,
:text?, :text?,
:colorize, :colorize,
:to => :tree :to => :tree
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment