diff --git a/app/controllers/git/blobs_controller.rb b/app/controllers/git/blobs_controller.rb index 0b3bf43ac..95f0c0e5a 100644 --- a/app/controllers/git/blobs_controller.rb +++ b/app/controllers/git/blobs_controller.rb @@ -1,43 +1,19 @@ class Git::BlobsController < Git::BaseController before_filter :set_path before_filter :set_commit_hash + before_filter :find_tree 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 end 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 @blame = Grit::Blob.blame(@git_repository.repo, @commit.id, @path) end 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 headers["Content-Disposition"] = %[attachment;filename="#{@blob.name}"] @@ -52,4 +28,16 @@ class Git::BlobsController < Git::BaseController def set_commit_hash @commit_hash = params[:commit_hash].present? ? params[:commit_hash] : nil 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 \ No newline at end of file