commits_controller.rb 1.02 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!
gitlabhq's avatar
gitlabhq committed
10
  before_filter :require_non_empty_project
gitlabhq's avatar
gitlabhq committed
11 12

  def index
13 14
    load_refs # load @branch, @tag & @ref

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

    if params[:path]
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
19
      @commits = @repo.log(@ref, params[:path], :max_count => limit, :skip => offset)
gitlabhq's avatar
gitlabhq committed
20
    else
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
21
      @commits = @repo.commits(@ref, limit, offset)
gitlabhq's avatar
gitlabhq committed
22 23 24 25 26 27 28 29 30 31
    end

    respond_to do |format|
      format.html # index.html.erb
      format.js
    end
  end

  def show
    @commit = project.repo.commits(params[:id]).first
gitlabhq's avatar
gitlabhq committed
32
    @notes = project.notes.where(:noteable_id => @commit.id, :noteable_type => "Commit").order("created_at DESC").limit(20)
gitlabhq's avatar
gitlabhq committed
33 34
    @note = @project.notes.new(:noteable_id => @commit.id, :noteable_type => "Commit")

gitlabhq's avatar
gitlabhq committed
35 36
    respond_to do |format| 
      format.html
37
      format.js { respond_with_notes }
gitlabhq's avatar
gitlabhq committed
38 39 40
    end
  end
end