rosa-build/app/controllers/projects/git/commits_controller.rb

51 lines
1.8 KiB
Ruby
Raw Normal View History

2012-01-30 20:39:34 +00:00
# -*- encoding : utf-8 -*-
class Projects::Git::CommitsController < Projects::Git::BaseController
def index
2011-04-04 14:49:08 +01:00
if @path.present?
@commits = @project.repo.log(@treeish, @path)
2011-04-04 14:49:08 +01:00
else
@commits, @page, @last_page = @project.paginate_commits(@treeish, :page => params[:page])
2011-04-04 14:49:08 +01:00
end
end
def show
@commit = @commentable = @project.repo.commit(params[:id]) || raise(ActiveRecord::RecordNotFound)
@comments = Comment.for_commit(@commit)
respond_to do |format|
format.html
format.diff { render :text => (@commit.diffs.map(&:diff).join("\n") rescue ''), :content_type => "text/plain" }
format.patch { render :text => (@commit.to_patch rescue ''), :content_type => "text/plain" }
end
end
def diff
res = params[:diff].split(/\A(.*)\.\.\.(.*)\z/).select {|e| e.present?}
if res[1].present?
params1 = res[0]
params2 = res[1] == 'HEAD' ? @project.default_branch : res.last
else # get only one parameter
params1 = @project.default_branch
params2 = res.first
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
2012-12-03 18:06:31 +00:00
params1 # possible commit hash
end
@commit1 = @project.repo.commit(ref1) || raise(ActiveRecord::RecordNotFound)
ref = if @project.repo.branches_and_tags.include? params2
@project.repo.commits(params2).first
else
2012-12-03 18:06:31 +00:00
params2 # possible commit hash
end
@commit = @project.repo.commit(ref) || raise(ActiveRecord::RecordNotFound)
@common_ancestor = @project.repo.commit(@project.repo.git.merge_base({}, @commit1, @commit)) || @commit1
2012-12-03 11:11:55 +00:00
@stats = @project.repo.diff_stats @commit1.id, @commit.id
end
2012-01-11 18:15:35 +00:00
end