Commit 970d86b7 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Refactor blob finding

parent 68d89548
...@@ -8,7 +8,7 @@ class Projects::BlameController < Projects::ApplicationController ...@@ -8,7 +8,7 @@ class Projects::BlameController < Projects::ApplicationController
before_filter :require_non_empty_project before_filter :require_non_empty_project
def show def show
@blob = Gitlab::Git::Blob.find(@repository, @commit.id, @path) @blob = @repository.blob_at(@commit.id, @path)
@blame = Gitlab::Git::Blame.new(project.repository, @commit.id, @path) @blame = Gitlab::Git::Blame.new(project.repository, @commit.id, @path)
end end
end end
...@@ -8,7 +8,7 @@ class Projects::BlobController < Projects::ApplicationController ...@@ -8,7 +8,7 @@ class Projects::BlobController < Projects::ApplicationController
before_filter :require_non_empty_project before_filter :require_non_empty_project
def show def show
@blob = Gitlab::Git::Blob.find(@repository, @commit.id, @path) @blob = @repository.blob_at(@commit.id, @path)
not_found! unless @blob not_found! unless @blob
end end
......
...@@ -10,7 +10,7 @@ class Projects::EditTreeController < Projects::ApplicationController ...@@ -10,7 +10,7 @@ class Projects::EditTreeController < Projects::ApplicationController
before_filter :edit_requirements, only: [:show, :update] before_filter :edit_requirements, only: [:show, :update]
def show def show
@last_commit = Gitlab::Git::Commit.last_for_path(@project.repository, @ref, @path).sha @last_commit = Gitlab::Git::Commit.last_for_path(@repository, @ref, @path).sha
end end
def update def update
...@@ -32,7 +32,7 @@ class Projects::EditTreeController < Projects::ApplicationController ...@@ -32,7 +32,7 @@ class Projects::EditTreeController < Projects::ApplicationController
private private
def edit_requirements def edit_requirements
@blob = Gitlab::Git::Blob.find(@repository, @commit.id, @path) @blob = @repository.blob_at(@commit.id, @path)
unless @blob unless @blob
redirect_to project_blob_path(@project, @id), notice: "You can only edit text files" redirect_to project_blob_path(@project, @id), notice: "You can only edit text files"
......
...@@ -8,7 +8,7 @@ class Projects::RawController < Projects::ApplicationController ...@@ -8,7 +8,7 @@ class Projects::RawController < Projects::ApplicationController
before_filter :require_non_empty_project before_filter :require_non_empty_project
def show def show
@blob = Gitlab::Git::Blob.find(@repository, @commit.id, @path) @blob = @repository.blob_at(@commit.id, @path)
if @blob if @blob
type = if @blob.mime_type =~ /html|javascript/ type = if @blob.mime_type =~ /html|javascript/
......
module BlobsHelper
def find_blob(repository, sha, path)
Gitlab::Git::Blob.find(repository, sha, path)
end
end
...@@ -155,4 +155,8 @@ class Repository ...@@ -155,4 +155,8 @@ class Repository
super super
end end
def blob_at(sha, path)
Gitlab::Git::Blob.find(self, sha, path)
end
end end
...@@ -37,8 +37,8 @@ ...@@ -37,8 +37,8 @@
- unless @suppress_diff - unless @suppress_diff
- diffs.each_with_index do |diff, i| - diffs.each_with_index do |diff, i|
- next if diff.diff.empty? - next if diff.diff.empty?
- file = find_blob(project.repository, @commit.id, diff.new_path) - file = project.repository.blob_at(@commit.id, diff.new_path)
- file = find_blob(project.repository, @commit.parent_id, diff.old_path) unless file - file = project.repository.blob_at(@commit.parent_id, diff.old_path) unless file
- next unless file - next unless file
.file{id: "diff-#{i}"} .file{id: "diff-#{i}"}
.header .header
...@@ -64,7 +64,7 @@ ...@@ -64,7 +64,7 @@
- if file.text? - if file.text?
= render "projects/commits/text_file", diff: diff, index: i = render "projects/commits/text_file", diff: diff, index: i
- elsif file.image? - elsif file.image?
- old_file = find_blob(project.repository, @commit.parent_id, diff.old_path) if @commit.parent_id - old_file = project.repository.blob_at(@commit.parent_id, diff.old_path) if @commit.parent_id
= render "projects/commits/image", diff: diff, old_file: old_file, file: file, index: i = render "projects/commits/image", diff: diff, old_file: old_file, file: file, index: i
- else - else
%p.nothing_here_message No preview for this file type %p.nothing_here_message No preview for this file type
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