diff options
author | Douwe Maan <douwe@selenight.nl> | 2017-06-06 11:46:28 -0500 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2017-06-06 14:48:05 -0500 |
commit | 3a5d375e49b808ca203cb40b5f907aafb40f53aa (patch) | |
tree | b6083a59d35cfd4bef6a54df9aa7f95a82d6d193 /lib | |
parent | 4ab1e07fd3fef373a83137ca851558b0f327bfd5 (diff) | |
download | gitlab-ce-3a5d375e49b808ca203cb40b5f907aafb40f53aa.tar.gz |
Fix Diff::Position#diff_file for positions on straight diffsdm-diff-file-straight-diff
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/diff/diff_refs.rb | 10 | ||||
-rw-r--r-- | lib/gitlab/diff/position.rb | 18 | ||||
-rw-r--r-- | lib/gitlab/diff/position_tracer.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/git/compare.rb | 2 |
4 files changed, 14 insertions, 18 deletions
diff --git a/lib/gitlab/diff/diff_refs.rb b/lib/gitlab/diff/diff_refs.rb index 7948782aecc..371cbe04b9b 100644 --- a/lib/gitlab/diff/diff_refs.rb +++ b/lib/gitlab/diff/diff_refs.rb @@ -37,6 +37,16 @@ module Gitlab def complete? start_sha && head_sha end + + def compare_in(project) + # We're at the initial commit, so just get that as we can't compare to anything. + if Gitlab::Git.blank_ref?(start_sha) + project.commit(head_sha) + else + straight = start_sha == base_sha + CompareService.new(project, head_sha).execute(project, start_sha, straight: straight) + end + end end end end diff --git a/lib/gitlab/diff/position.rb b/lib/gitlab/diff/position.rb index 4d96778a2b2..f80afb20f0c 100644 --- a/lib/gitlab/diff/position.rb +++ b/lib/gitlab/diff/position.rb @@ -145,23 +145,9 @@ module Gitlab private def find_diff_file(repository) - # We're at the initial commit, so just get that as we can't compare to anything. - compare = - if Gitlab::Git.blank_ref?(start_sha) - Gitlab::Git::Commit.find(repository.raw_repository, head_sha) - else - Gitlab::Git::Compare.new( - repository.raw_repository, - start_sha, - head_sha - ) - end - - diff = compare.diffs(paths: paths).first - - return unless diff + return unless diff_refs.complete? - Gitlab::Diff::File.new(diff, repository: repository, diff_refs: diff_refs) + diff_refs.compare_in(repository.project).diffs(paths: paths, expanded: true).diff_files.first end end end diff --git a/lib/gitlab/diff/position_tracer.rb b/lib/gitlab/diff/position_tracer.rb index dcabb5f7fe5..b68a1636814 100644 --- a/lib/gitlab/diff/position_tracer.rb +++ b/lib/gitlab/diff/position_tracer.rb @@ -216,7 +216,7 @@ module Gitlab def compare(start_sha, head_sha, straight: false) compare = CompareService.new(project, head_sha).execute(project, start_sha, straight: straight) - compare.diffs(paths: paths) + compare.diffs(paths: paths, expanded: true) end def position(diff_file, old_line, new_line) diff --git a/lib/gitlab/git/compare.rb b/lib/gitlab/git/compare.rb index 696a2acd5e3..78e440395a5 100644 --- a/lib/gitlab/git/compare.rb +++ b/lib/gitlab/git/compare.rb @@ -3,7 +3,7 @@ module Gitlab class Compare attr_reader :head, :base, :straight - def initialize(repository, base, head, straight = false) + def initialize(repository, base, head, straight: false) @repository = repository @straight = straight |