diff options
author | Robert Speicher <robert@gitlab.com> | 2017-05-25 22:15:57 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2017-05-25 22:15:57 +0000 |
commit | 8e2fefc6c44fc3c6140e5cbc4b56c58c90dc07f3 (patch) | |
tree | 2fe8ce678f1183fe778454dfa39e3dcc277d3fd8 /app/models/merge_request_diff.rb | |
parent | e20eb71203aa29458d7f51a27d42a3d8208e2494 (diff) | |
parent | d88a5c1db1c6cca639039188a26c6e6d5bc68831 (diff) | |
download | gitlab-ce-8e2fefc6c44fc3c6140e5cbc4b56c58c90dc07f3.tar.gz |
Merge branch 'dm-diff-cleanup' into 'master'
Clean up diff rendering
See merge request !11390
Diffstat (limited to 'app/models/merge_request_diff.rb')
-rw-r--r-- | app/models/merge_request_diff.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb index 6e3917a10a3..1bd61c1d465 100644 --- a/app/models/merge_request_diff.rb +++ b/app/models/merge_request_diff.rb @@ -150,6 +150,29 @@ class MergeRequestDiff < ActiveRecord::Base ) end + # MRs created before 8.4 don't store their true diff refs (start and base), + # but we need to get a commit SHA for the "View file @ ..." link by a file, + # so we use an approximation of the diff refs if we can't get the actual one. + # + # These will not be the actual diff refs if the target branch was merged into + # the source branch after the merge request was created, but it is good enough + # for the specific purpose of linking to a commit. + # + # It is not good enough for highlighting diffs, so we can't simply pass + # these as `diff_refs.` + def fallback_diff_refs + real_refs = diff_refs + return real_refs if real_refs + + likely_base_commit_sha = (first_commit&.parent || first_commit)&.sha + + Gitlab::Diff::DiffRefs.new( + base_sha: likely_base_commit_sha, + start_sha: safe_start_commit_sha, + head_sha: head_commit_sha + ) + end + def diff_refs_by_sha? base_commit_sha? && head_commit_sha? && start_commit_sha? end |