increased awesomness of blobs controller

This commit is contained in:
Timothy N. Tsvetkov 2011-04-04 20:50:43 +04:00
parent 8692995969
commit 6b26715e22
1 changed files with 13 additions and 25 deletions

View File

@ -1,43 +1,19 @@
class Git::BlobsController < Git::BaseController class Git::BlobsController < Git::BaseController
before_filter :set_path before_filter :set_path
before_filter :set_commit_hash before_filter :set_commit_hash
before_filter :find_tree
def show def show
if @commit_hash
@tree = @git_repository.tree(@commit_hash)
@commit = @git_repository.commits(@treeish, 1).first
else
@tree = @git_repository.tree(@treeish)
@commit = @git_repository.log(@treeish, @path).first
@commit_hash = @commit.id if @commit
end
@blob = @tree / @path @blob = @tree / @path
end end
def blame def blame
if @commit_hash
@tree = @git_repository.tree(@commit_hash)
@commit = @git_repository.commits(@commit_hash).first
else
@tree = @git_repository.tree(@treeish)
@commit = @git_repository.repo.log(@treeish, @path).first
end
@blob = @tree / @path @blob = @tree / @path
@blame = Grit::Blob.blame(@git_repository.repo, @commit.id, @path) @blame = Grit::Blob.blame(@git_repository.repo, @commit.id, @path)
end end
def raw def raw
if @commit_hash
@tree = @git_repository.tree(@commit_hash)
else
@tree = @git_repository.tree(@treeish)
@commit_hash = @git_repository.repo.log(@treeish, @path).first.id
end
@blob = @tree / @path @blob = @tree / @path
headers["Content-Disposition"] = %[attachment;filename="#{@blob.name}"] headers["Content-Disposition"] = %[attachment;filename="#{@blob.name}"]
@ -52,4 +28,16 @@ class Git::BlobsController < Git::BaseController
def set_commit_hash def set_commit_hash
@commit_hash = params[:commit_hash].present? ? params[:commit_hash] : nil @commit_hash = params[:commit_hash].present? ? params[:commit_hash] : nil
end end
def find_tree
if @commit_hash
@tree = @git_repository.tree(@commit_hash)
@commit = @git_repository.commits(@treeish, 1).first
else
@tree = @git_repository.tree(@treeish)
@commit = @git_repository.log(@treeish, @path).first
@commit_hash = @commit.id if @commit
end
end
end end