2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2011-03-10 12:39:24 +00:00
|
|
|
class Git::CommitsController < Git::BaseController
|
2012-02-27 17:40:46 +00:00
|
|
|
helper_method :split_commits_by_date
|
|
|
|
|
2011-03-10 12:39:24 +00:00
|
|
|
def index
|
2012-02-27 17:40:46 +00:00
|
|
|
@branch_name = params[:treeish] || @project.default_branch
|
|
|
|
@branch = @project.branch(@branch_name)
|
2011-03-10 12:39:24 +00:00
|
|
|
@path = params[:path]
|
|
|
|
|
2011-04-04 14:49:08 +01:00
|
|
|
if @path.present?
|
|
|
|
@commits = @git_repository.repo.log(@branch_name, @path)
|
|
|
|
@render_paginate = false
|
|
|
|
else
|
|
|
|
@commits, @page, @last_page = @git_repository.paginate_commits(@branch_name, :page => params[:page])
|
|
|
|
@render_paginate = true
|
|
|
|
end
|
2011-03-10 12:39:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2011-11-01 18:12:41 +00:00
|
|
|
@commit = @git_repository.commit(params[:id]) # @git_repository.commits(params[:id]).first
|
2011-03-10 12:39:24 +00:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
2012-03-21 19:55:14 +00:00
|
|
|
format.diff { render :text => (@commit.diffs.map(&:diff).join("\n") rescue ''), :content_type => "text/plain" }
|
2011-11-01 18:12:41 +00:00
|
|
|
format.patch { render :text => (@commit.to_patch rescue ''), :content_type => "text/plain" }
|
2011-03-10 12:39:24 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-02-27 17:40:46 +00:00
|
|
|
protected
|
|
|
|
|
|
|
|
def split_commits_by_date(commits)
|
|
|
|
res = commits.sort{|x, y| y.authored_date <=> x.authored_date}.inject({}) do |h, commit|
|
|
|
|
dt = commit.authored_date
|
|
|
|
h[dt.year] ||= {}
|
|
|
|
h[dt.year][dt.month] ||= {}
|
|
|
|
h[dt.year][dt.month][dt.day] ||= []
|
|
|
|
h[dt.year][dt.month][dt.day] << commit
|
|
|
|
h
|
|
|
|
end
|
|
|
|
return res
|
|
|
|
end
|
2012-01-11 18:15:35 +00:00
|
|
|
end
|