From 351f205c0580e43ace9d5a47e0b923ffb7cda3b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Rodr=C3=ADguez?= Date: Tue, 5 Dec 2017 16:42:04 -0300 Subject: Incorporate ConflictsService.ListConflictFiles Gitaly RPC --- lib/gitlab/git/conflict/resolver.rb | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'lib/gitlab/git/conflict/resolver.rb') diff --git a/lib/gitlab/git/conflict/resolver.rb b/lib/gitlab/git/conflict/resolver.rb index 03e5c0fcd6f..6a7ce4e3490 100644 --- a/lib/gitlab/git/conflict/resolver.rb +++ b/lib/gitlab/git/conflict/resolver.rb @@ -13,12 +13,18 @@ module Gitlab def conflicts @conflicts ||= begin - target_index = @target_repository.rugged.merge_commits(@our_commit_oid, @their_commit_oid) - - # We don't need to do `with_repo_branch_commit` here, because the target - # project always fetches source refs when creating merge request diffs. - conflict_files(@target_repository, target_index) + @target_repository.gitaly_migrate(:conflicts_list_conflict_files) do |is_enabled| + if is_enabled + @target_repository.gitaly_conflicts_client.list_conflict_files(@our_commit_oid, @their_commit_oid) + else + rugged_list_conflict_files + end + end end + rescue GRPC::FailedPrecondition => e + raise Gitlab::Git::Conflict::Resolver::ConflictSideMissing.new(e.message) + rescue Rugged::OdbError, GRPC::BadStatus => e + raise Gitlab::Git::CommandError.new(e) end def resolve_conflicts(source_repository, user, files, source_branch:, target_branch:, commit_message:) @@ -84,6 +90,14 @@ module Gitlab index.add(path: our_path, oid: oid, mode: file.our_mode) index.conflict_remove(our_path) end + + def rugged_list_conflict_files + target_index = @target_repository.rugged.merge_commits(@our_commit_oid, @their_commit_oid) + + # We don't need to do `with_repo_branch_commit` here, because the target + # project always fetches source refs when creating merge request diffs. + conflict_files(@target_repository, target_index) + end end end end -- cgit v1.2.1 From 0aa87bbe13ca74a791bf5c70a12d8e7f6876fd5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Rodr=C3=ADguez?= Date: Tue, 5 Dec 2017 19:18:20 -0300 Subject: Incorporate ConflictsService.ResolveConflicts Gitaly RPC --- lib/gitlab/git/conflict/resolver.rb | 58 +++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 22 deletions(-) (limited to 'lib/gitlab/git/conflict/resolver.rb') diff --git a/lib/gitlab/git/conflict/resolver.rb b/lib/gitlab/git/conflict/resolver.rb index 6a7ce4e3490..48e672ad3fb 100644 --- a/lib/gitlab/git/conflict/resolver.rb +++ b/lib/gitlab/git/conflict/resolver.rb @@ -15,7 +15,7 @@ module Gitlab @conflicts ||= begin @target_repository.gitaly_migrate(:conflicts_list_conflict_files) do |is_enabled| if is_enabled - @target_repository.gitaly_conflicts_client.list_conflict_files(@our_commit_oid, @their_commit_oid) + gitaly_conflicts_client(@target_repository).list_conflict_files else rugged_list_conflict_files end @@ -28,28 +28,12 @@ module Gitlab end def resolve_conflicts(source_repository, user, files, source_branch:, target_branch:, commit_message:) - source_repository.with_repo_branch_commit(@target_repository, target_branch) do - index = source_repository.rugged.merge_commits(@our_commit_oid, @their_commit_oid) - conflicts = conflict_files(source_repository, index) - - files.each do |file_params| - conflict_file = conflict_for_path(conflicts, file_params[:old_path], file_params[:new_path]) - - write_resolved_file_to_index(source_repository, index, conflict_file, file_params) - end - - unless index.conflicts.empty? - missing_files = index.conflicts.map { |file| file[:ours][:path] } - - raise ResolutionError, "Missing resolutions for the following files: #{missing_files.join(', ')}" + source_repository.gitaly_migrate(:conflicts_resolve_conflicts) do |is_enabled| + if is_enabled + gitaly_conflicts_client(source_repository).resolve_conflicts(@target_repository, user, files, source_branch, target_branch, commit_message) + else + rugged_resolve_conflicts(source_repository, user, files, source_branch, target_branch, commit_message) end - - commit_params = { - message: commit_message, - parents: [@our_commit_oid, @their_commit_oid] - } - - source_repository.commit_index(user, source_branch, index, commit_params) end end @@ -74,6 +58,10 @@ module Gitlab end end + def gitaly_conflicts_client(repository) + repository.gitaly_conflicts_client(@our_commit_oid, @their_commit_oid) + end + def write_resolved_file_to_index(repository, index, file, params) if params[:sections] resolved_lines = file.resolve_lines(params[:sections]) @@ -98,6 +86,32 @@ module Gitlab # project always fetches source refs when creating merge request diffs. conflict_files(@target_repository, target_index) end + + def rugged_resolve_conflicts(source_repository, user, files, source_branch, target_branch, commit_message) + source_repository.with_repo_branch_commit(@target_repository, target_branch) do + index = source_repository.rugged.merge_commits(@our_commit_oid, @their_commit_oid) + conflicts = conflict_files(source_repository, index) + + files.each do |file_params| + conflict_file = conflict_for_path(conflicts, file_params[:old_path], file_params[:new_path]) + + write_resolved_file_to_index(source_repository, index, conflict_file, file_params) + end + + unless index.conflicts.empty? + missing_files = index.conflicts.map { |file| file[:ours][:path] } + + raise ResolutionError, "Missing resolutions for the following files: #{missing_files.join(', ')}" + end + + commit_params = { + message: commit_message, + parents: [@our_commit_oid, @their_commit_oid] + } + + source_repository.commit_index(user, source_branch, index, commit_params) + end + end end end end -- cgit v1.2.1 From 65e3a1e9e9a316a2bbbcd49e22b858b8b1bd9890 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Rodr=C3=ADguez?= Date: Wed, 27 Dec 2017 16:49:05 -0300 Subject: Simplify conflict resolution interface and code - Add a Gitlab::Git::Conflict::Resolution class to encapsulate resolution data - Simplify conflict file collection assembly --- lib/gitlab/git/conflict/resolver.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'lib/gitlab/git/conflict/resolver.rb') diff --git a/lib/gitlab/git/conflict/resolver.rb b/lib/gitlab/git/conflict/resolver.rb index 48e672ad3fb..74c9874d590 100644 --- a/lib/gitlab/git/conflict/resolver.rb +++ b/lib/gitlab/git/conflict/resolver.rb @@ -27,12 +27,12 @@ module Gitlab raise Gitlab::Git::CommandError.new(e) end - def resolve_conflicts(source_repository, user, files, source_branch:, target_branch:, commit_message:) + def resolve_conflicts(source_repository, resolution, source_branch:, target_branch:) source_repository.gitaly_migrate(:conflicts_resolve_conflicts) do |is_enabled| if is_enabled - gitaly_conflicts_client(source_repository).resolve_conflicts(@target_repository, user, files, source_branch, target_branch, commit_message) + gitaly_conflicts_client(source_repository).resolve_conflicts(@target_repository, resolution, source_branch, target_branch) else - rugged_resolve_conflicts(source_repository, user, files, source_branch, target_branch, commit_message) + rugged_resolve_conflicts(source_repository, resolution, source_branch, target_branch) end end end @@ -87,12 +87,12 @@ module Gitlab conflict_files(@target_repository, target_index) end - def rugged_resolve_conflicts(source_repository, user, files, source_branch, target_branch, commit_message) + def rugged_resolve_conflicts(source_repository, resolution, source_branch, target_branch) source_repository.with_repo_branch_commit(@target_repository, target_branch) do index = source_repository.rugged.merge_commits(@our_commit_oid, @their_commit_oid) conflicts = conflict_files(source_repository, index) - files.each do |file_params| + resolution.files.each do |file_params| conflict_file = conflict_for_path(conflicts, file_params[:old_path], file_params[:new_path]) write_resolved_file_to_index(source_repository, index, conflict_file, file_params) @@ -105,11 +105,11 @@ module Gitlab end commit_params = { - message: commit_message, + message: resolution.commit_message, parents: [@our_commit_oid, @their_commit_oid] } - source_repository.commit_index(user, source_branch, index, commit_params) + source_repository.commit_index(resolution.user, source_branch, index, commit_params) end end end -- cgit v1.2.1 From b4b267b7395ca524f4251f6eefe91e502b086ab0 Mon Sep 17 00:00:00 2001 From: Ahmad Sherif Date: Tue, 9 Jan 2018 13:53:35 +0100 Subject: Migrate Repository#can_be_merged? to Gitaly --- lib/gitlab/git/conflict/resolver.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/gitlab/git/conflict/resolver.rb') diff --git a/lib/gitlab/git/conflict/resolver.rb b/lib/gitlab/git/conflict/resolver.rb index 74c9874d590..07b7e811a34 100644 --- a/lib/gitlab/git/conflict/resolver.rb +++ b/lib/gitlab/git/conflict/resolver.rb @@ -15,7 +15,7 @@ module Gitlab @conflicts ||= begin @target_repository.gitaly_migrate(:conflicts_list_conflict_files) do |is_enabled| if is_enabled - gitaly_conflicts_client(@target_repository).list_conflict_files + gitaly_conflicts_client(@target_repository).list_conflict_files.to_a else rugged_list_conflict_files end -- cgit v1.2.1