Commit ac4db380 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Use straight diff approach when compare merge request versions

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent c143003b
...@@ -11,9 +11,10 @@ class Compare ...@@ -11,9 +11,10 @@ class Compare
end end
end end
def initialize(compare, project) def initialize(compare, project, straight = false)
@compare = compare @compare = compare
@project = project @project = project
@straight = straight
end end
def commits def commits
...@@ -36,6 +37,8 @@ class Compare ...@@ -36,6 +37,8 @@ class Compare
alias_method :commit, :head_commit alias_method :commit, :head_commit
def base_commit def base_commit
return start_commit if @straight
return @base_commit if defined?(@base_commit) return @base_commit if defined?(@base_commit)
@base_commit = if start_commit && head_commit @base_commit = if start_commit && head_commit
......
...@@ -167,8 +167,11 @@ class MergeRequestDiff < ActiveRecord::Base ...@@ -167,8 +167,11 @@ class MergeRequestDiff < ActiveRecord::Base
self == merge_request.merge_request_diff self == merge_request.merge_request_diff
end end
def compare_with(sha) def compare_with(sha, straight = true)
CompareService.new.execute(project, head_commit_sha, project, sha) # When compare merge request versions we want diff A..B instead of A...B
# so we handle cases when user squash and rebase commits in one of versions.
# For this reason we set straight to true by default.
CompareService.new.execute(project, head_commit_sha, project, sha, straight)
end end
private private
......
...@@ -3,7 +3,7 @@ require 'securerandom' ...@@ -3,7 +3,7 @@ require 'securerandom'
# Compare 2 branches for one repo or between repositories # Compare 2 branches for one repo or between repositories
# and return Gitlab::Git::Compare object that responds to commits and diffs # and return Gitlab::Git::Compare object that responds to commits and diffs
class CompareService class CompareService
def execute(source_project, source_branch, target_project, target_branch) def execute(source_project, source_branch, target_project, target_branch, straight = false)
source_commit = source_project.commit(source_branch) source_commit = source_project.commit(source_branch)
return unless source_commit return unless source_commit
...@@ -23,9 +23,10 @@ class CompareService ...@@ -23,9 +23,10 @@ class CompareService
raw_compare = Gitlab::Git::Compare.new( raw_compare = Gitlab::Git::Compare.new(
target_project.repository.raw_repository, target_project.repository.raw_repository,
target_branch, target_branch,
source_sha source_sha,
straight
) )
Compare.new(raw_compare, target_project) Compare.new(raw_compare, target_project, straight)
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment