diff options
author | Adam Niedzielski <adamsunday@gmail.com> | 2016-10-12 16:34:47 +0300 |
---|---|---|
committer | Adam Niedzielski <adamsunday@gmail.com> | 2016-10-17 19:09:34 +0300 |
commit | 317e48193fe5d75d6671c900a765ead719e6b4df (patch) | |
tree | 9fd025431f5d05c7b0ae4e5bfe7fb31f7bf218b4 /lib/gitlab | |
parent | d4feb781387a843586d5a01740c43f50ce7ad084 (diff) |
Fix the diff in the merge request view when converting a symlink to a regular file.
In this specific case using file_path as a cache key is not enough,
because there are two entries with the same path.
Closes #21610.
Diffstat (limited to 'lib/gitlab')
-rw-r--r-- | lib/gitlab/diff/file.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/diff/file_collection/merge_request_diff.rb | 10 |
2 files changed, 9 insertions, 5 deletions
diff --git a/lib/gitlab/diff/file.rb b/lib/gitlab/diff/file.rb index e47df508ca2..ce85e5e0123 100644 --- a/lib/gitlab/diff/file.rb +++ b/lib/gitlab/diff/file.rb @@ -125,6 +125,10 @@ module Gitlab repository.blob_at(commit.id, file_path) end + + def cache_key + "#{file_path}-#{new_file}-#{deleted_file}-#{renamed_file}" + end end end end diff --git a/lib/gitlab/diff/file_collection/merge_request_diff.rb b/lib/gitlab/diff/file_collection/merge_request_diff.rb index 36348b33943..dc4d47c878b 100644 --- a/lib/gitlab/diff/file_collection/merge_request_diff.rb +++ b/lib/gitlab/diff/file_collection/merge_request_diff.rb @@ -35,16 +35,16 @@ module Gitlab # for the highlighted ones, so we just skip their execution. # If the highlighted diff files lines are not cached we calculate and cache them. # - # The content of the cache is a Hash where the key correspond to the file_path and the values are Arrays of + # The content of the cache is a Hash where the key identifies the file and the values are Arrays of # hashes that represent serialized diff lines. # def cache_highlight!(diff_file) - file_path = diff_file.file_path + item_key = diff_file.cache_key - if highlight_cache[file_path] - highlight_diff_file_from_cache!(diff_file, highlight_cache[file_path]) + if highlight_cache[item_key] + highlight_diff_file_from_cache!(diff_file, highlight_cache[item_key]) else - highlight_cache[file_path] = diff_file.highlighted_diff_lines.map(&:to_hash) + highlight_cache[item_key] = diff_file.highlighted_diff_lines.map(&:to_hash) end end |