2015-04-27 06:42:29 +00:00
|
|
|
require 'addressable/uri'
|
|
|
|
|
2013-06-23 16:47:22 +00:00
|
|
|
class Projects::CompareController < Projects::ApplicationController
|
2016-03-03 17:38:44 +00:00
|
|
|
include DiffHelper
|
|
|
|
|
2012-09-20 19:20:48 +00:00
|
|
|
# Authorize
|
2015-04-16 12:03:37 +00:00
|
|
|
before_action :require_non_empty_project
|
|
|
|
before_action :authorize_download_code!
|
2016-06-28 16:25:32 +00:00
|
|
|
before_action :assign_ref_vars, only: [:index, :show, :diff_for_path]
|
2016-02-01 23:43:51 +00:00
|
|
|
before_action :merge_request, only: [:index, :show]
|
2012-09-20 19:20:48 +00:00
|
|
|
|
2012-09-26 03:10:50 +00:00
|
|
|
def index
|
|
|
|
end
|
|
|
|
|
2012-09-20 19:20:48 +00:00
|
|
|
def show
|
2016-03-03 17:38:44 +00:00
|
|
|
compare = CompareService.new.
|
2016-07-06 16:51:02 +00:00
|
|
|
execute(@project, @head_ref, @project, @start_ref)
|
2014-07-29 09:33:51 +00:00
|
|
|
|
2016-03-03 17:38:44 +00:00
|
|
|
if compare
|
|
|
|
@commits = Commit.decorate(compare.commits, @project)
|
2016-06-20 16:51:48 +00:00
|
|
|
|
|
|
|
@start_commit = @project.commit(@start_ref)
|
2016-02-01 23:43:51 +00:00
|
|
|
@commit = @project.commit(@head_ref)
|
2016-06-20 16:51:48 +00:00
|
|
|
@base_commit = @project.merge_base_commit(@start_ref, @head_ref)
|
|
|
|
|
2016-03-03 17:38:44 +00:00
|
|
|
@diffs = compare.diffs(diff_options)
|
2016-06-20 16:51:48 +00:00
|
|
|
@diff_refs = Gitlab::Diff::DiffRefs.new(
|
|
|
|
base_sha: @base_commit.try(:sha),
|
|
|
|
start_sha: @start_commit.try(:sha),
|
|
|
|
head_sha: @commit.try(:sha)
|
|
|
|
)
|
|
|
|
|
2016-05-13 19:53:04 +00:00
|
|
|
@diff_notes_disabled = true
|
2016-05-10 22:41:46 +00:00
|
|
|
@grouped_diff_notes = {}
|
2015-09-18 19:02:01 +00:00
|
|
|
end
|
2012-09-20 19:20:48 +00:00
|
|
|
end
|
2012-09-26 03:10:50 +00:00
|
|
|
|
2016-06-28 16:25:32 +00:00
|
|
|
def diff_for_path
|
|
|
|
compare = CompareService.new.
|
2016-07-06 16:51:02 +00:00
|
|
|
execute(@project, @head_ref, @project, @start_ref)
|
2016-06-28 16:25:32 +00:00
|
|
|
|
|
|
|
return render_404 unless compare
|
|
|
|
|
2016-07-06 16:51:02 +00:00
|
|
|
@start_commit = @project.commit(@start_ref)
|
2016-06-28 16:25:32 +00:00
|
|
|
@commit = @project.commit(@head_ref)
|
2016-07-06 16:51:02 +00:00
|
|
|
@base_commit = @project.merge_base_commit(@start_ref, @head_ref)
|
2016-06-28 16:25:32 +00:00
|
|
|
diffs = compare.diffs(diff_options.merge(paths: [params[:path]]))
|
2016-07-06 16:51:02 +00:00
|
|
|
diff_refs = Gitlab::Diff::DiffRefs.new(
|
|
|
|
base_sha: @base_commit.try(:sha),
|
|
|
|
start_sha: @start_commit.try(:sha),
|
|
|
|
head_sha: @commit.try(:sha)
|
|
|
|
)
|
2016-06-28 16:25:32 +00:00
|
|
|
|
|
|
|
@diff_notes_disabled = true
|
|
|
|
@grouped_diff_notes = {}
|
|
|
|
|
2016-07-06 16:51:02 +00:00
|
|
|
render_diff_for_path(diffs, diff_refs, @project)
|
2016-06-28 16:25:32 +00:00
|
|
|
end
|
|
|
|
|
2012-09-26 03:10:50 +00:00
|
|
|
def create
|
2015-01-24 18:02:58 +00:00
|
|
|
redirect_to namespace_project_compare_path(@project.namespace, @project,
|
|
|
|
params[:from], params[:to])
|
2012-09-26 03:10:50 +00:00
|
|
|
end
|
2016-02-01 23:43:51 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def assign_ref_vars
|
2016-06-20 16:51:48 +00:00
|
|
|
@start_ref = Addressable::URI.unescape(params[:from])
|
2016-02-01 23:43:51 +00:00
|
|
|
@ref = @head_ref = Addressable::URI.unescape(params[:to])
|
|
|
|
end
|
|
|
|
|
|
|
|
def merge_request
|
|
|
|
@merge_request ||= @project.merge_requests.opened.
|
2016-06-20 16:51:48 +00:00
|
|
|
find_by(source_project: @project, source_branch: @head_ref, target_branch: @start_ref)
|
2016-02-01 23:43:51 +00:00
|
|
|
end
|
2012-09-20 19:20:48 +00:00
|
|
|
end
|