Commit 8f05fbbab5754b2a05547bae7ed3f9c409d8a640
1 parent
2d75b454
Exists in
master
and in
4 other branches
Dont show comment on diff if diff line was changed after comment left
Showing
4 changed files
with
27 additions
and
12 deletions
Show diff stats
app/helpers/commits_helper.rb
@@ -38,6 +38,8 @@ module CommitsHelper | @@ -38,6 +38,8 @@ module CommitsHelper | ||
38 | 38 | ||
39 | lines_arr = ::Gitlab::InlineDiff.processing diff_arr | 39 | lines_arr = ::Gitlab::InlineDiff.processing diff_arr |
40 | lines_arr.each do |line| | 40 | lines_arr.each do |line| |
41 | + raw_line = line.dup | ||
42 | + | ||
41 | next if line.match(/^\-\-\- \/dev\/null/) | 43 | next if line.match(/^\-\-\- \/dev\/null/) |
42 | next if line.match(/^\+\+\+ \/dev\/null/) | 44 | next if line.match(/^\+\+\+ \/dev\/null/) |
43 | next if line.match(/^\-\-\- a/) | 45 | next if line.match(/^\-\-\- a/) |
@@ -58,7 +60,7 @@ module CommitsHelper | @@ -58,7 +60,7 @@ module CommitsHelper | ||
58 | else | 60 | else |
59 | type = identification_type(line) | 61 | type = identification_type(line) |
60 | line_code = build_line_anchor(diff, line_new, line_old) | 62 | line_code = build_line_anchor(diff, line_new, line_old) |
61 | - yield(full_line, type, line_code, line_new, line_old) | 63 | + yield(full_line, type, line_code, line_new, line_old, raw_line) |
62 | end | 64 | end |
63 | 65 | ||
64 | 66 |
app/models/note.rb
@@ -99,10 +99,21 @@ class Note < ActiveRecord::Base | @@ -99,10 +99,21 @@ class Note < ActiveRecord::Base | ||
99 | diff.new_path if diff | 99 | diff.new_path if diff |
100 | end | 100 | end |
101 | 101 | ||
102 | + def diff_old_line | ||
103 | + line_code.split('_')[1].to_i | ||
104 | + end | ||
105 | + | ||
102 | def diff_new_line | 106 | def diff_new_line |
103 | line_code.split('_')[2].to_i | 107 | line_code.split('_')[2].to_i |
104 | end | 108 | end |
105 | 109 | ||
110 | + def diff_line | ||
111 | + if diff | ||
112 | + @diff_line ||= diff.diff.lines.select { |line| line =~ /\A\+/ }[diff_new_line] || | ||
113 | + diff.diff.lines.select { |line| line =~ /\A\-/ }[diff_old_line] | ||
114 | + end | ||
115 | + end | ||
116 | + | ||
106 | def discussion_id | 117 | def discussion_id |
107 | @discussion_id ||= [:discussion, noteable_type.try(:underscore), noteable_id || commit_id, line_code].join("-").to_sym | 118 | @discussion_id ||= [:discussion, noteable_type.try(:underscore), noteable_id || commit_id, line_code].join("-").to_sym |
108 | end | 119 | end |
app/views/projects/commits/_text_file.html.haml
@@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
3 | %a.supp_diff_link Diff suppressed. Click to show | 3 | %a.supp_diff_link Diff suppressed. Click to show |
4 | 4 | ||
5 | %table.text-file{class: "#{'hide' if too_big}"} | 5 | %table.text-file{class: "#{'hide' if too_big}"} |
6 | - - each_diff_line(diff, index) do |line, type, line_code, line_new, line_old| | 6 | + - each_diff_line(diff, index) do |line, type, line_code, line_new, line_old, raw_line| |
7 | %tr.line_holder{ id: line_code, class: "#{type}" } | 7 | %tr.line_holder{ id: line_code, class: "#{type}" } |
8 | - if type == "match" | 8 | - if type == "match" |
9 | %td.old_line= "..." | 9 | %td.old_line= "..." |
@@ -20,4 +20,4 @@ | @@ -20,4 +20,4 @@ | ||
20 | - if @reply_allowed | 20 | - if @reply_allowed |
21 | - comments = @line_notes.select { |n| n.line_code == line_code }.sort_by(&:created_at) | 21 | - comments = @line_notes.select { |n| n.line_code == line_code }.sort_by(&:created_at) |
22 | - unless comments.empty? | 22 | - unless comments.empty? |
23 | - = render "projects/notes/diff_notes_with_reply", notes: comments | 23 | + = render "projects/notes/diff_notes_with_reply", notes: comments, raw_line: raw_line |
app/views/projects/notes/_diff_notes_with_reply.html.haml
1 | - note = notes.first # example note | 1 | - note = notes.first # example note |
2 | -%tr.notes_holder | ||
3 | - %td.notes_line{ colspan: 2 } | ||
4 | - %span.btn.disabled | ||
5 | - %i.icon-comment | ||
6 | - = notes.count | ||
7 | - %td.notes_content | ||
8 | - %ul.notes{ rel: note.discussion_id } | ||
9 | - = render notes | 2 | +-# Check if line want not changed since comment was left |
3 | +- if !defined?(raw_line) || raw_line == note.diff_line | ||
4 | + %tr.notes_holder | ||
5 | + %td.notes_line{ colspan: 2 } | ||
6 | + %span.btn.disabled | ||
7 | + %i.icon-comment | ||
8 | + = notes.count | ||
9 | + %td.notes_content | ||
10 | + %ul.notes{ rel: note.discussion_id } | ||
11 | + = render notes | ||
10 | 12 | ||
11 | - = render "projects/notes/discussion_reply_button", note: note | 13 | + = render "projects/notes/discussion_reply_button", note: note |