diff options
author | Douwe Maan <douwe@selenight.nl> | 2017-05-15 13:19:49 -0500 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2017-05-23 15:37:05 -0500 |
commit | 7c479d88a92233790bc0fb63146fe004f8b9b5d7 (patch) | |
tree | 3691c9e55229b145ea631bca724ba4da8c467d70 /app/models/merge_request_diff.rb | |
parent | 7e09a9b7dcef125af2e775869754a3327935b12d (diff) | |
download | gitlab-ce-7c479d88a92233790bc0fb63146fe004f8b9b5d7.tar.gz |
Pass fallback_diff_refs to Diff::File instead of using view helpers
Diffstat (limited to 'app/models/merge_request_diff.rb')
-rw-r--r-- | app/models/merge_request_diff.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb index f0a3c30ea74..a6f3994166b 100644 --- a/app/models/merge_request_diff.rb +++ b/app/models/merge_request_diff.rb @@ -150,6 +150,24 @@ 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 find 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 + 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 |