2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2012-05-02 10:18:07 +01:00
|
|
|
class Projects::Git::CommitsController < Projects::Git::BaseController
|
2011-03-10 12:39:24 +00:00
|
|
|
def index
|
2011-04-04 14:49:08 +01:00
|
|
|
if @path.present?
|
2012-07-17 09:02:56 +01:00
|
|
|
@commits = @project.repo.log(@treeish, @path)
|
2011-04-04 14:49:08 +01:00
|
|
|
else
|
2012-07-17 09:02:56 +01:00
|
|
|
@commits, @page, @last_page = @project.paginate_commits(@treeish, :page => params[:page])
|
2011-04-04 14:49:08 +01:00
|
|
|
end
|
2011-03-10 12:39:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2012-10-12 20:59:14 +01:00
|
|
|
@commit = @commentable = @project.repo.commit(params[:id]) || raise(ActiveRecord::RecordNotFound)
|
2012-10-26 15:03:46 +01:00
|
|
|
@comments = Comment.for_commit(@commit)
|
2012-10-04 19:40:12 +01:00
|
|
|
|
2011-03-10 12:39:24 +00:00
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
2012-10-26 15:03:46 +01: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-11-19 19:15:15 +00:00
|
|
|
|
|
|
|
def diff
|
|
|
|
if params[:commit2].present?
|
|
|
|
params1 = params[:commit1]
|
|
|
|
params2 = params[:commit2] == 'HEAD' ? @project.default_branch : params[:commit2]
|
|
|
|
else # get only one parameter
|
|
|
|
params1 = @project.default_branch
|
|
|
|
params2 = params[:commit1]
|
|
|
|
end
|
|
|
|
params1.sub! 'HEAD', @project.default_branch
|
|
|
|
params2.sub! 'HEAD', @project.default_branch
|
|
|
|
|
|
|
|
ref1 = if @project.repo.branches_and_tags.include? params1
|
|
|
|
@project.repo.commits(params1).first
|
|
|
|
else
|
|
|
|
params1 #FIXME git has other ref?
|
|
|
|
end
|
|
|
|
@commit1 = @project.repo.commit(ref1) || raise(ActiveRecord::RecordNotFound)
|
|
|
|
|
|
|
|
ref = if @project.repo.branches_and_tags.include? params2
|
|
|
|
@project.repo.commits(params2).first
|
|
|
|
else
|
|
|
|
params2 #FIXME git has other ref?
|
|
|
|
end
|
|
|
|
@commit = @project.repo.commit(ref) || raise(ActiveRecord::RecordNotFound)
|
2012-11-27 17:35:58 +00:00
|
|
|
@common_ancestor = @project.repo.commit(@project.repo.git.merge_base({}, @commit1, @commit)) || @commit1
|
2012-11-19 19:15:15 +00:00
|
|
|
end
|
2012-01-11 18:15:35 +00:00
|
|
|
end
|