Commit f19cdee8cc1e85066154d008ee2653d845c9f3cd
1 parent
8bfc62fb
Exists in
spb-stable
and in
3 other branches
Remove commit_load_context.rb
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
3 changed files
with
23 additions
and
52 deletions
Show diff stats
app/contexts/commit_load_context.rb
| ... | ... | @@ -1,34 +0,0 @@ |
| 1 | -class CommitLoadContext < BaseContext | |
| 2 | - def execute | |
| 3 | - result = { | |
| 4 | - commit: nil, | |
| 5 | - suppress_diff: false, | |
| 6 | - line_notes: [], | |
| 7 | - notes_count: 0, | |
| 8 | - note: nil, | |
| 9 | - status: :ok | |
| 10 | - } | |
| 11 | - | |
| 12 | - commit = project.repository.commit(params[:id]) | |
| 13 | - | |
| 14 | - if commit | |
| 15 | - line_notes = project.notes.for_commit_id(commit.id).inline | |
| 16 | - | |
| 17 | - result[:commit] = commit | |
| 18 | - result[:note] = project.build_commit_note(commit) | |
| 19 | - result[:line_notes] = line_notes | |
| 20 | - result[:notes_count] = project.notes.for_commit_id(commit.id).count | |
| 21 | - result[:branches] = project.repository.branch_names_contains(commit.id) | |
| 22 | - | |
| 23 | - begin | |
| 24 | - result[:suppress_diff] = true if commit.diff_suppress? && !params[:force_show_diff] | |
| 25 | - result[:force_suppress_diff] = commit.diff_force_suppress? | |
| 26 | - rescue Grit::Git::GitTimeout | |
| 27 | - result[:suppress_diff] = true | |
| 28 | - result[:status] = :huge_commit | |
| 29 | - end | |
| 30 | - end | |
| 31 | - | |
| 32 | - result | |
| 33 | - end | |
| 34 | -end |
app/controllers/projects/commit_controller.rb
| ... | ... | @@ -6,30 +6,31 @@ class Projects::CommitController < Projects::ApplicationController |
| 6 | 6 | before_filter :authorize_read_project! |
| 7 | 7 | before_filter :authorize_code_access! |
| 8 | 8 | before_filter :require_non_empty_project |
| 9 | + before_filter :commit | |
| 9 | 10 | |
| 10 | 11 | def show |
| 11 | - result = CommitLoadContext.new(project, current_user, params).execute | |
| 12 | + return git_not_found! unless @commit | |
| 12 | 13 | |
| 13 | - @commit = result[:commit] | |
| 14 | + @line_notes = project.notes.for_commit_id(commit.id).inline | |
| 15 | + @branches = project.repository.branch_names_contains(commit.id) | |
| 14 | 16 | |
| 15 | - if @commit.nil? | |
| 16 | - git_not_found! | |
| 17 | - return | |
| 17 | + begin | |
| 18 | + @suppress_diff = true if commit.diff_suppress? && !params[:force_show_diff] | |
| 19 | + @force_suppress_diff = commit.diff_force_suppress? | |
| 20 | + rescue Grit::Git::GitTimeout | |
| 21 | + @suppress_diff = true | |
| 22 | + @status = :huge_commit | |
| 18 | 23 | end |
| 19 | 24 | |
| 20 | - @suppress_diff = result[:suppress_diff] | |
| 21 | - @force_suppress_diff = result[:force_suppress_diff] | |
| 22 | - | |
| 23 | - @note = result[:note] | |
| 24 | - @line_notes = result[:line_notes] | |
| 25 | - @branches = result[:branches] | |
| 26 | - @notes_count = result[:notes_count] | |
| 25 | + @note = project.build_commit_note(commit) | |
| 26 | + @notes_count = project.notes.for_commit_id(commit.id).count | |
| 27 | 27 | @notes = project.notes.for_commit_id(@commit.id).not_inline.fresh |
| 28 | 28 | @noteable = @commit |
| 29 | - | |
| 30 | 29 | @comments_allowed = @reply_allowed = true |
| 31 | - @comments_target = { noteable_type: 'Commit', | |
| 32 | - commit_id: @commit.id } | |
| 30 | + @comments_target = { | |
| 31 | + noteable_type: 'Commit', | |
| 32 | + commit_id: @commit.id | |
| 33 | + } | |
| 33 | 34 | |
| 34 | 35 | respond_to do |format| |
| 35 | 36 | format.html do |
| ... | ... | @@ -42,4 +43,8 @@ class Projects::CommitController < Projects::ApplicationController |
| 42 | 43 | format.patch { render text: @commit.to_patch } |
| 43 | 44 | end |
| 44 | 45 | end |
| 46 | + | |
| 47 | + def commit | |
| 48 | + @commit ||= project.repository.commit(params[:id]) | |
| 49 | + end | |
| 45 | 50 | end | ... | ... |
lib/api/repositories.rb
| ... | ... | @@ -124,9 +124,9 @@ module API |
| 124 | 124 | # GET /projects/:id/repository/commits/:sha/diff |
| 125 | 125 | get ":id/repository/commits/:sha/diff" do |
| 126 | 126 | sha = params[:sha] |
| 127 | - result = CommitLoadContext.new(user_project, current_user, {id: sha}).execute | |
| 128 | - not_found! "Commit" unless result[:commit] | |
| 129 | - result[:commit].diffs | |
| 127 | + commit = user_project.repository.commit(sha) | |
| 128 | + not_found! "Commit" unless commit | |
| 129 | + commit.diffs | |
| 130 | 130 | end |
| 131 | 131 | |
| 132 | 132 | # Get a project repository tree | ... | ... |