Commit 29ac60d7 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Change the way old merge request diff handled

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent a8fe213e
...@@ -261,7 +261,7 @@ class MergeRequest < ActiveRecord::Base ...@@ -261,7 +261,7 @@ class MergeRequest < ActiveRecord::Base
end end
def diff_refs def diff_refs
if merge_request_diff if persisted?
merge_request_diff.diff_refs merge_request_diff.diff_refs
else else
start_sha = target_branch_sha start_sha = target_branch_sha
......
...@@ -22,10 +22,6 @@ class MergeRequestDiff < ActiveRecord::Base ...@@ -22,10 +22,6 @@ class MergeRequestDiff < ActiveRecord::Base
serialize :st_commits serialize :st_commits
serialize :st_diffs serialize :st_diffs
# For compatibility with old MergeRequestDiff which
# does not store those variables in database
after_initialize :ensure_commits_sha, if: :persisted?
# All diff information is collected from repository after object is created. # All diff information is collected from repository after object is created.
# It allows you to override variables like head_commit_sha before getting diff. # It allows you to override variables like head_commit_sha before getting diff.
after_create :save_git_content, unless: :importing? after_create :save_git_content, unless: :importing?
...@@ -50,6 +46,20 @@ class MergeRequestDiff < ActiveRecord::Base ...@@ -50,6 +46,20 @@ class MergeRequestDiff < ActiveRecord::Base
self.base_commit_sha ||= find_base_sha self.base_commit_sha ||= find_base_sha
end end
# This method will rely on repository branch sha
# in case start_commit_sha is nil. Its necesarry for old merge request diff
# created before version 8.4 to work
def safe_start_commit_sha
start_commit_sha || merge_request.target_branch_sha
end
# This method will rely on repository branch sha
# in case head_commit_sha is nil. Its necesarry for old merge request diff
# created before version 8.4 to work
def safe_head_commit_sha
head_commit_sha || last_commit.try(:sha) || merge_request.source_branch_sha
end
def size def size
real_size.presence || diffs.size real_size.presence || diffs.size
end end
...@@ -60,8 +70,8 @@ class MergeRequestDiff < ActiveRecord::Base ...@@ -60,8 +70,8 @@ class MergeRequestDiff < ActiveRecord::Base
begin begin
compare = Gitlab::Git::Compare.new( compare = Gitlab::Git::Compare.new(
repository.raw_repository, repository.raw_repository,
start_commit_sha, safe_start_commit_sha,
head_commit_sha safe_head_commit_sha
) )
compare.diffs(options) compare.diffs(options)
end end
...@@ -126,8 +136,8 @@ class MergeRequestDiff < ActiveRecord::Base ...@@ -126,8 +136,8 @@ class MergeRequestDiff < ActiveRecord::Base
Gitlab::Git::Compare.new( Gitlab::Git::Compare.new(
repository.raw_repository, repository.raw_repository,
start_commit_sha, safe_start_commit_sha,
head_commit_sha safe_head_commit_sha
) )
end end
end end
...@@ -216,9 +226,6 @@ class MergeRequestDiff < ActiveRecord::Base ...@@ -216,9 +226,6 @@ class MergeRequestDiff < ActiveRecord::Base
return unless head_commit_sha && start_commit_sha return unless head_commit_sha && start_commit_sha
project.merge_base_commit(head_commit_sha, start_commit_sha).try(:sha) project.merge_base_commit(head_commit_sha, start_commit_sha).try(:sha)
rescue Rugged::OdbError
# In case head or start commit does not exist in the repository any more
nil
end end
def utf8_st_diffs def utf8_st_diffs
......
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