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
|
2013-02-14 06:55:47 +00:00
|
|
|
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
|
2012-11-19 19:15:15 +00:00
|
|
|
else # get only one parameter
|
|
|
|
params1 = @project.default_branch
|
2013-02-14 06:55:47 +00:00
|
|
|
params2 = res.first
|
2012-11-19 19:15:15 +00:00
|
|
|
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
|
2012-11-19 19:15:15 +00:00
|
|
|
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
|
2012-11-19 19:15:15 +00:00
|
|
|
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-12-03 11:11:55 +00:00
|
|
|
@stats = @project.repo.diff_stats @commit1.id, @commit.id
|
2012-11-19 19:15:15 +00:00
|
|
|
end
|
2012-01-11 18:15:35 +00:00
|
|
|
end
|