diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-10-01 17:02:53 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-10-01 17:02:53 +0200 |
commit | e0609a7800000196e561f54124f4ac06e6d780f0 (patch) | |
tree | fc99a9dbad6eb97bcfab63ec5aae692fe0b8ceff | |
parent | 958e727f7074b323609019bba086b66da9cf17e0 (diff) | |
parent | e2576d588fef876e743f55b0b5b0620da43ab1c1 (diff) | |
download | gitlab-ce-e0609a7800000196e561f54124f4ac06e6d780f0.tar.gz |
Merge branch 'show-diff-stats-for-mr'
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | app/views/projects/diffs/_diffs.html.haml | 6 | ||||
-rw-r--r-- | app/views/projects/diffs/_stats.html.haml | 30 | ||||
-rw-r--r-- | lib/gitlab/diff/file.rb | 8 | ||||
-rw-r--r-- | lib/gitlab/diff/line.rb | 8 |
5 files changed, 34 insertions, 19 deletions
diff --git a/CHANGELOG b/CHANGELOG index 6729a3bb046..33451e51ad1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -23,6 +23,7 @@ v 8.1.0 (unreleased) - Note the original location of a moved project when notifying users of the move - Improve error message when merging fails - Add support of multibyte characters in LDAP UID (Roman Petrov) + - Show additions/deletions stats on merge request diff v 8.0.3 - Fix URL shown in Slack notifications diff --git a/app/views/projects/diffs/_diffs.html.haml b/app/views/projects/diffs/_diffs.html.haml index c5acafa2630..4f1965bfb39 100644 --- a/app/views/projects/diffs/_diffs.html.haml +++ b/app/views/projects/diffs/_diffs.html.haml @@ -1,14 +1,14 @@ - if params[:view] == 'parallel' - fluid_layout true +- diff_files = safe_diff_files(diffs) + .gray-content-block.second-block .inline-parallel-buttons .btn-group = inline_diff_btn = parallel_diff_btn - = render 'projects/diffs/stats', diffs: diffs - -- diff_files = safe_diff_files(diffs) + = render 'projects/diffs/stats', diff_files: diff_files - if diff_files.count < diffs.size = render 'projects/diffs/warning', diffs: diffs, shown_files_count: diff_files.count diff --git a/app/views/projects/diffs/_stats.html.haml b/app/views/projects/diffs/_stats.html.haml index c4d7f26430b..ea2a3e01277 100644 --- a/app/views/projects/diffs/_stats.html.haml +++ b/app/views/projects/diffs/_stats.html.haml @@ -2,37 +2,35 @@ .commit-stat-summary Showing = link_to '#', class: 'js-toggle-button' do - %strong #{pluralize(diffs.count, "changed file")} - - if current_controller?(:commit) - - unless @commit.has_zero_stats? - with - %strong.cgreen #{@commit.stats.additions} additions - and - %strong.cred #{@commit.stats.deletions} deletions + %strong #{pluralize(diff_files.count, "changed file")} + with + %strong.cgreen #{diff_files.sum(&:added_lines)} additions + and + %strong.cred #{diff_files.sum(&:removed_lines)} deletions .file-stats.js-toggle-content.hide %ul - - diffs.each_with_index do |diff, i| + - diff_files.each_with_index do |diff_file, i| %li - - if diff.deleted_file + - if diff_file.deleted_file %span.deleted-file %a{href: "#diff-#{i}"} %i.fa.fa-minus - = diff.old_path - - elsif diff.renamed_file + = diff_file.old_path + - elsif diff_file.renamed_file %span.renamed-file %a{href: "#diff-#{i}"} %i.fa.fa-minus - = diff.old_path + = diff_file.old_path → - = diff.new_path - - elsif diff.new_file + = diff_file.new_path + - elsif diff_file.new_file %span.new-file %a{href: "#diff-#{i}"} %i.fa.fa-plus - = diff.new_path + = diff_file.new_path - else %span.edit-file %a{href: "#diff-#{i}"} %i.fa.fa-adjust - = diff.new_path + = diff_file.new_path diff --git a/lib/gitlab/diff/file.rb b/lib/gitlab/diff/file.rb index 4daf65331e8..142058aa69d 100644 --- a/lib/gitlab/diff/file.rb +++ b/lib/gitlab/diff/file.rb @@ -44,6 +44,14 @@ module Gitlab diff.old_path end end + + def added_lines + diff_lines.select(&:added?).size + end + + def removed_lines + diff_lines.select(&:removed?).size + end end end end diff --git a/lib/gitlab/diff/line.rb b/lib/gitlab/diff/line.rb index 8ac1b15e88a..0072194606e 100644 --- a/lib/gitlab/diff/line.rb +++ b/lib/gitlab/diff/line.rb @@ -7,6 +7,14 @@ module Gitlab @text, @type, @index = text, type, index @old_pos, @new_pos = old_pos, new_pos end + + def added? + type == 'new' + end + + def removed? + type == 'old' + end end end end |