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-07-06 17:15:27 +00:00
|
|
|
include DiffForPath
|
2016-03-03 17:38:44 +00:00
|
|
|
include DiffHelper
|
2017-08-23 16:53:29 +00:00
|
|
|
include RendersCommits
|
2016-03-03 17:38:44 +00:00
|
|
|
|
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-07-06 17:15:27 +00:00
|
|
|
before_action :define_ref_vars, only: [:index, :show, :diff_for_path]
|
|
|
|
before_action :define_diff_vars, only: [: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-07-07 11:36:33 +00:00
|
|
|
apply_diff_view_cookie!
|
2017-09-19 10:55:37 +00:00
|
|
|
# n+1: https://gitlab.com/gitlab-org/gitlab-ce/issues/37430
|
|
|
|
Gitlab::GitalyClient.allow_n_plus_1_calls do
|
|
|
|
render
|
|
|
|
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
|
2016-07-06 17:15:27 +00:00
|
|
|
return render_404 unless @compare
|
2016-06-28 16:25:32 +00:00
|
|
|
|
2016-08-03 16:32:01 +00:00
|
|
|
render_diff_for_path(@compare.diffs(diff_options))
|
2016-06-28 16:25:32 +00:00
|
|
|
end
|
|
|
|
|
2012-09-26 03:10:50 +00:00
|
|
|
def create
|
2017-01-10 22:11:36 +00:00
|
|
|
if params[:from].blank? || params[:to].blank?
|
2017-09-12 14:56:22 +00:00
|
|
|
flash[:alert] = "You must select a Source and a Target revision"
|
2017-01-16 19:23:30 +00:00
|
|
|
from_to_vars = {
|
|
|
|
from: params[:from].presence,
|
|
|
|
to: params[:to].presence
|
|
|
|
}
|
2017-06-29 17:06:35 +00:00
|
|
|
redirect_to project_compare_index_path(@project, from_to_vars)
|
2017-01-10 22:11:36 +00:00
|
|
|
else
|
2017-06-29 17:06:35 +00:00
|
|
|
redirect_to project_compare_path(@project,
|
2015-01-24 18:02:58 +00:00
|
|
|
params[:from], params[:to])
|
2017-01-10 22:11:36 +00:00
|
|
|
end
|
2012-09-26 03:10:50 +00:00
|
|
|
end
|
2016-02-01 23:43:51 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-07-06 17:15:27 +00:00
|
|
|
def define_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
|
|
|
|
|
2016-07-06 17:15:27 +00:00
|
|
|
def define_diff_vars
|
2017-01-04 14:32:36 +00:00
|
|
|
@compare = CompareService.new(@project, @head_ref)
|
|
|
|
.execute(@project, @start_ref)
|
2016-07-06 17:15:27 +00:00
|
|
|
|
|
|
|
if @compare
|
2017-08-23 16:53:29 +00:00
|
|
|
@commits = prepare_commits_for_rendering(@compare.commits)
|
2016-08-03 16:32:01 +00:00
|
|
|
@diffs = @compare.diffs(diff_options)
|
2016-07-06 17:15:27 +00:00
|
|
|
|
2017-05-15 18:44:15 +00:00
|
|
|
environment_params = @repository.branch_exists?(@head_ref) ? { ref: @head_ref } : { commit: @compare.commit }
|
2017-02-07 00:06:46 +00:00
|
|
|
@environment = EnvironmentsFinder.new(@project, current_user, environment_params).execute.last
|
2017-01-29 19:38:00 +00:00
|
|
|
|
2016-07-06 17:15:27 +00:00
|
|
|
@diff_notes_disabled = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-01 23:43:51 +00:00
|
|
|
def merge_request
|
2017-06-21 13:48:12 +00:00
|
|
|
@merge_request ||= MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened
|
|
|
|
.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
|