commit_controller.rb 1.3 KB
Newer Older
R
Robert Speicher 已提交
1 2 3
# Controller for a specific Commit
#
# Not to be confused with CommitsController, plural.
4
class Projects::CommitController < Projects::ApplicationController
R
Robert Speicher 已提交
5 6 7 8
  # Authorize
  before_filter :authorize_read_project!
  before_filter :authorize_code_access!
  before_filter :require_non_empty_project
9
  before_filter :commit
R
Robert Speicher 已提交
10 11

  def show
12
    return git_not_found! unless @commit
R
Robert Speicher 已提交
13

14
    @line_notes = project.notes.for_commit_id(commit.id).inline
15 16 17 18 19 20

    @branches = begin
                  project.repository.branch_names_contains(commit.id)
                rescue Grit::Git::GitTimeout
                  []
                end
21

22
    begin
23
      @diffs = @commit.diffs
24
    rescue Grit::Git::GitTimeout
25 26
      @diffs = []
      @diff_timeout = true
27
    end
R
Robert Speicher 已提交
28

29 30
    @note = project.build_commit_note(commit)
    @notes_count = project.notes.for_commit_id(commit.id).count
31
    @notes = project.notes.for_commit_id(@commit.id).not_inline.fresh
32
    @noteable = @commit
33
    @comments_allowed = @reply_allowed = true
34 35 36 37
    @comments_target  = {
      noteable_type: 'Commit',
      commit_id: @commit.id
    }
38 39

    respond_to do |format|
40
      format.html
R
Riyad Preukschas 已提交
41
      format.diff  { render text: @commit.to_diff }
R
Riyad Preukschas 已提交
42
      format.patch { render text: @commit.to_patch }
R
Robert Speicher 已提交
43 44
    end
  end
45 46 47 48

  def commit
    @commit ||= project.repository.commit(params[:id])
  end
R
Robert Speicher 已提交
49
end