commit_controller.rb 1.22 KB
Newer Older
Robert Speicher's avatar
Robert Speicher committed
1 2 3
# Controller for a specific Commit
#
# Not to be confused with CommitsController, plural.
4
class Projects::CommitController < Projects::ApplicationController
Robert Speicher's avatar
Robert Speicher committed
5 6 7 8 9 10
  # Authorize
  before_filter :authorize_read_project!
  before_filter :authorize_code_access!
  before_filter :require_non_empty_project

  def show
11
    result = CommitLoadContext.new(project, current_user, params).execute
Robert Speicher's avatar
Robert Speicher committed
12 13

    @commit = result[:commit]
14

15 16 17 18
    if @commit.nil?
      git_not_found!
      return
    end
Robert Speicher's avatar
Robert Speicher committed
19

Riyad Preukschas's avatar
Riyad Preukschas committed
20
    @suppress_diff = result[:suppress_diff]
21
    @force_suppress_diff = result[:force_suppress_diff]
Riyad Preukschas's avatar
Riyad Preukschas committed
22 23 24

    @note        = result[:note]
    @line_notes  = result[:line_notes]
25
    @branches    = result[:branches]
Riyad Preukschas's avatar
Riyad Preukschas committed
26
    @notes_count = result[:notes_count]
27
    @notes = project.notes.for_commit_id(@commit.id).not_inline.fresh
28
    @noteable = @commit
Riyad Preukschas's avatar
Riyad Preukschas committed
29

30 31
    @comments_allowed = @reply_allowed = true
    @comments_target  = { noteable_type: 'Commit',
32
                          commit_id: @commit.id }
33 34 35 36 37 38 39

    respond_to do |format|
      format.html do
        if result[:status] == :huge_commit
          render "huge_commit" and return
        end
      end
Robert Speicher's avatar
Robert Speicher committed
40

41
      format.diff  { render text: @commit.to_diff }
42
      format.patch { render text: @commit.to_patch }
Robert Speicher's avatar
Robert Speicher committed
43 44 45
    end
  end
end