Commit 970d86b7c5d0be871d8ab8d7cbd51997fd62e28a

Authored by Dmitriy Zaporozhets
1 parent 68d89548

Refactor blob finding

app/controllers/projects/blame_controller.rb
... ... @@ -8,7 +8,7 @@ class Projects::BlameController < Projects::ApplicationController
8 8 before_filter :require_non_empty_project
9 9  
10 10 def show
11   - @blob = Gitlab::Git::Blob.find(@repository, @commit.id, @path)
  11 + @blob = @repository.blob_at(@commit.id, @path)
12 12 @blame = Gitlab::Git::Blame.new(project.repository, @commit.id, @path)
13 13 end
14 14 end
... ...
app/controllers/projects/blob_controller.rb
... ... @@ -8,7 +8,7 @@ class Projects::BlobController < Projects::ApplicationController
8 8 before_filter :require_non_empty_project
9 9  
10 10 def show
11   - @blob = Gitlab::Git::Blob.find(@repository, @commit.id, @path)
  11 + @blob = @repository.blob_at(@commit.id, @path)
12 12  
13 13 not_found! unless @blob
14 14 end
... ...
app/controllers/projects/edit_tree_controller.rb
... ... @@ -10,7 +10,7 @@ class Projects::EditTreeController < Projects::ApplicationController
10 10 before_filter :edit_requirements, only: [:show, :update]
11 11  
12 12 def show
13   - @last_commit = Gitlab::Git::Commit.last_for_path(@project.repository, @ref, @path).sha
  13 + @last_commit = Gitlab::Git::Commit.last_for_path(@repository, @ref, @path).sha
14 14 end
15 15  
16 16 def update
... ... @@ -32,7 +32,7 @@ class Projects::EditTreeController < Projects::ApplicationController
32 32 private
33 33  
34 34 def edit_requirements
35   - @blob = Gitlab::Git::Blob.find(@repository, @commit.id, @path)
  35 + @blob = @repository.blob_at(@commit.id, @path)
36 36  
37 37 unless @blob
38 38 redirect_to project_blob_path(@project, @id), notice: "You can only edit text files"
... ...
app/controllers/projects/raw_controller.rb
... ... @@ -8,7 +8,7 @@ class Projects::RawController < Projects::ApplicationController
8 8 before_filter :require_non_empty_project
9 9  
10 10 def show
11   - @blob = Gitlab::Git::Blob.find(@repository, @commit.id, @path)
  11 + @blob = @repository.blob_at(@commit.id, @path)
12 12  
13 13 if @blob
14 14 type = if @blob.mime_type =~ /html|javascript/
... ...
app/helpers/blobs_helper.rb
... ... @@ -1,5 +0,0 @@
1   -module BlobsHelper
2   - def find_blob(repository, sha, path)
3   - Gitlab::Git::Blob.find(repository, sha, path)
4   - end
5   -end
app/models/repository.rb
... ... @@ -155,4 +155,8 @@ class Repository
155 155  
156 156 super
157 157 end
  158 +
  159 + def blob_at(sha, path)
  160 + Gitlab::Git::Blob.find(self, sha, path)
  161 + end
158 162 end
... ...
app/views/projects/commits/_diffs.html.haml
... ... @@ -37,8 +37,8 @@
37 37 - unless @suppress_diff
38 38 - diffs.each_with_index do |diff, i|
39 39 - next if diff.diff.empty?
40   - - file = find_blob(project.repository, @commit.id, diff.new_path)
41   - - file = find_blob(project.repository, @commit.parent_id, diff.old_path) unless file
  40 + - file = project.repository.blob_at(@commit.id, diff.new_path)
  41 + - file = project.repository.blob_at(@commit.parent_id, diff.old_path) unless file
42 42 - next unless file
43 43 .file{id: "diff-#{i}"}
44 44 .header
... ... @@ -64,7 +64,7 @@
64 64 - if file.text?
65 65 = render "projects/commits/text_file", diff: diff, index: i
66 66 - elsif file.image?
67   - - old_file = find_blob(project.repository, @commit.parent_id, diff.old_path) if @commit.parent_id
  67 + - old_file = project.repository.blob_at(@commit.parent_id, diff.old_path) if @commit.parent_id
68 68 = render "projects/commits/image", diff: diff, old_file: old_file, file: file, index: i
69 69 - else
70 70 %p.nothing_here_message No preview for this file type
... ...