commits_controller.rb 1.51 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
    @commits = @project.commits(@ref, params[:path], @limit, @offset)
gitlabhq's avatar
gitlabhq committed
19 20 21 22

    respond_to do |format|
      format.html # index.html.erb
      format.js
Nihad Abbasov's avatar
Nihad Abbasov committed
23
      format.atom { render :layout => false }
gitlabhq's avatar
gitlabhq committed
24 25 26 27
    end
  end

  def show
28
    @commit = project.commit(params[:id])
29 30
    @notes = project.commit_notes(@commit).fresh.limit(20)
    @note = @project.build_commit_note(@commit)
gitlabhq's avatar
gitlabhq committed
31

32
    @comments_allowed = true
33 34
    @line_notes = project.commit_line_notes(@commit)

Nihad Abbasov's avatar
Nihad Abbasov committed
35
    respond_to do |format|
gitlabhq's avatar
gitlabhq committed
36
      format.html
37
      format.js { respond_with_notes }
gitlabhq's avatar
gitlabhq committed
38 39
    end
  end
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56

  def compare
    first = project.commit(params[:to])
    last = project.commit(params[:from])

    @diffs = []
    @commits = []
    @line_notes = []

    if first && last
      commits = [first, last].sort_by(&:created_at)
      younger = commits.first
      older = commits.last


      @commits = project.repo.commits_between(younger.id, older.id).map {|c| Commit.new(c)}
      @diffs = project.repo.diff(younger.id, older.id) rescue []
57
      @commit = Commit.new(older)
58 59
    end
  end
gitlabhq's avatar
gitlabhq committed
60
end