commits_controller.rb 1.63 KB
Newer Older
gitlabhq's avatar
gitlabhq committed
1 2 3 4
require "base64"

class CommitsController < ApplicationController
  before_filter :project
gitlabhq's avatar
gitlabhq committed
5
  layout "project"
gitlabhq's avatar
gitlabhq committed
6 7 8 9

  # Authorize
  before_filter :add_project_abilities
  before_filter :authorize_read_project!
10
  before_filter :authorize_code_access!
gitlabhq's avatar
gitlabhq committed
11
  before_filter :require_non_empty_project
12
  before_filter :load_refs, only: :index # load @branch, @tag & @ref
13
  before_filter :render_full_content
gitlabhq's avatar
gitlabhq committed
14

15
  def index
gitlabhq's avatar
gitlabhq committed
16
    @repo = project.repo
17
    @limit, @offset = (params[:limit] || 40), (params[:offset] || 0)
18

19
    @commits = @project.commits(@ref, params[:path], @limit, @offset)
20
    @commits = CommitDecorator.decorate(@commits)
gitlabhq's avatar
gitlabhq committed
21 22 23 24

    respond_to do |format|
      format.html # index.html.erb
      format.js
25
      format.atom { render layout: false }
gitlabhq's avatar
gitlabhq committed
26 27 28 29
    end
  end

  def show
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
30 31 32 33 34 35 36 37 38 39 40 41
    result = CommitLoad.new(project, current_user, params).execute

    @commit = result[:commit]

    if @commit
      @suppress_diff = result[:suppress_diff]
      @note          = result[:note]
      @line_notes    = result[:line_notes]
      @notes_count   = result[:notes_count]
      @comments_allowed = true
    else
      return git_not_found!
42
    end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
43

randx's avatar
randx committed
44 45
  rescue Grit::Git::GitTimeout
    render "huge_commit"
gitlabhq's avatar
gitlabhq committed
46
  end
47 48

  def compare
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
49
    result = Commit.compare(project, params[:from], params[:to])
50

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
51 52 53
    @commits = result[:commits]
    @commit  = result[:commit]
    @diffs   = result[:diffs]
54
    @line_notes = []
55 56

    @commits = CommitDecorator.decorate(@commits)
57
  end
58 59 60 61 62 63

  def patch
    @commit = project.commit(params[:id])
    
    send_data(
      @commit.to_patch,
64 65 66
      type: "text/plain",
      disposition: 'attachment',
      filename: (@commit.id.to_s + ".patch")
67 68
    )
  end
gitlabhq's avatar
gitlabhq committed
69
end