diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 10:00:54 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 10:00:54 +0000 |
commit | 3cccd102ba543e02725d247893729e5c73b38295 (patch) | |
tree | f36a04ec38517f5deaaacb5acc7d949688d1e187 /app/helpers/diff_helper.rb | |
parent | 205943281328046ef7b4528031b90fbda70c75ac (diff) | |
download | gitlab-ce-3cccd102ba543e02725d247893729e5c73b38295.tar.gz |
Add latest changes from gitlab-org/gitlab@14-10-stable-eev14.10.0-rc42
Diffstat (limited to 'app/helpers/diff_helper.rb')
-rw-r--r-- | app/helpers/diff_helper.rb | 69 |
1 files changed, 25 insertions, 44 deletions
diff --git a/app/helpers/diff_helper.rb b/app/helpers/diff_helper.rb index 100d5c0281c..522593dd487 100644 --- a/app/helpers/diff_helper.rb +++ b/app/helpers/diff_helper.rb @@ -60,6 +60,18 @@ module DiffHelper html.join.html_safe end + def diff_nomappinginraw_line(line, first_line_num_class, second_line_num_class, content_line_class) + css_class = '' + css_class = 'old' if line.type == 'old-nomappinginraw' + css_class = 'new' if line.type == 'new-nomappinginraw' + + html = [content_tag(:td, '', class: [*first_line_num_class, css_class])] + html << content_tag(:td, '', class: [*second_line_num_class, css_class]) if second_line_num_class + html << content_tag(:td, diff_line_content(line.rich_text), class: [*content_line_class, 'nomappinginraw', css_class]) + + html.join.html_safe + end + def diff_line_content(line) if line.blank? " ".html_safe @@ -74,7 +86,7 @@ module DiffHelper end def diff_link_number(line_type, match, text) - line_type == match || text == 0 ? " " : text + line_type == match ? " " : text end def parallel_diff_discussions(left, right, diff_file) @@ -167,26 +179,20 @@ module DiffHelper } end - def editable_diff?(diff_file) - !diff_file.deleted_file? && @merge_request && @merge_request.source_project - end - - def diff_file_changed_icon(diff_file) - if diff_file.deleted_file? - "file-deletion" - elsif diff_file.new_file? - "file-addition" - else - "file-modified" - end + def diff_file_stats_data(diff_file) + old_blob = diff_file.old_blob + new_blob = diff_file.new_blob + { + old_size: old_blob&.size, + new_size: new_blob&.size, + added_lines: diff_file.added_lines, + removed_lines: diff_file.removed_lines, + viewer_name: diff_file.viewer.partial_name + } end - def diff_file_changed_icon_color(diff_file) - if diff_file.deleted_file? - "danger" - elsif diff_file.new_file? - "success" - end + def editable_diff?(diff_file) + !diff_file.deleted_file? && @merge_request && @merge_request.source_project end def render_overflow_warning?(diffs_collection) @@ -248,23 +254,6 @@ module DiffHelper toggle_whitespace_link(url, options) end - def diff_files_data(diff_files) - diffs_map = diff_files.map do |f| - { - href: "##{hexdigest(f.file_path)}", - title: f.new_path, - name: f.file_path, - path: diff_file_path_text(f), - icon: diff_file_changed_icon(f), - iconColor: "#{diff_file_changed_icon_color(f)}", - added: f.added_lines, - removed: f.removed_lines - } - end - - diffs_map.to_json - end - def hide_whitespace? params[:w] == '1' end @@ -278,14 +267,6 @@ module DiffHelper link_to "#{hide_whitespace? ? 'Show' : 'Hide'} whitespace changes", url, class: options[:class] end - def diff_file_path_text(diff_file, max: 60) - path = diff_file.new_path - - return path unless path.size > max && max > 3 - - "...#{path[-(max - 3)..]}" - end - def code_navigation_path(diffs) Gitlab::CodeNavigationPath.new(merge_request.project, merge_request.diff_head_sha) end |