Commit 0cc95ef2f56c4b779fca613c61789483fa8d2ae8
Exists in
master
and in
4 other branches
Merge pull request #2889 from kennytm/master
Show only ≤16 lines of codes in a discussion in a MR (issue #2860).
Showing
2 changed files
with
26 additions
and
2 deletions
Show diff stats
app/helpers/commits_helper.rb
@@ -57,6 +57,31 @@ module CommitsHelper | @@ -57,6 +57,31 @@ module CommitsHelper | ||
57 | end | 57 | end |
58 | end | 58 | end |
59 | 59 | ||
60 | + def each_diff_line_near(diff, index, expected_line_code) | ||
61 | + max_number_of_lines = 16 | ||
62 | + | ||
63 | + prev_match_line = nil | ||
64 | + prev_lines = [] | ||
65 | + | ||
66 | + each_diff_line(diff, index) do |full_line, type, line_code, line_new, line_old| | ||
67 | + line = [full_line, type, line_code, line_new, line_old] | ||
68 | + if line_code != expected_line_code | ||
69 | + if type == "match" | ||
70 | + prev_lines.clear | ||
71 | + prev_match_line = line | ||
72 | + else | ||
73 | + prev_lines.push(line) | ||
74 | + prev_lines.shift if prev_lines.length >= max_number_of_lines | ||
75 | + end | ||
76 | + else | ||
77 | + yield(prev_match_line) if !prev_match_line.nil? | ||
78 | + prev_lines.each { |ln| yield(ln) } | ||
79 | + yield(line) | ||
80 | + break | ||
81 | + end | ||
82 | + end | ||
83 | + end | ||
84 | + | ||
60 | def image_diff_class(diff) | 85 | def image_diff_class(diff) |
61 | if diff.deleted_file | 86 | if diff.deleted_file |
62 | "deleted" | 87 | "deleted" |
app/views/notes/_discussion_diff.html.haml
@@ -9,7 +9,7 @@ | @@ -9,7 +9,7 @@ | ||
9 | %br/ | 9 | %br/ |
10 | .content | 10 | .content |
11 | %table | 11 | %table |
12 | - - each_diff_line(diff, note.diff_file_index) do |line, type, line_code, line_new, line_old| | 12 | + - each_diff_line_near(diff, note.diff_file_index, note.line_code) do |line, type, line_code, line_new, line_old| |
13 | %tr.line_holder{ id: line_code } | 13 | %tr.line_holder{ id: line_code } |
14 | - if type == "match" | 14 | - if type == "match" |
15 | %td.old_line= "..." | 15 | %td.old_line= "..." |
@@ -22,4 +22,3 @@ | @@ -22,4 +22,3 @@ | ||
22 | 22 | ||
23 | - if line_code == note.line_code | 23 | - if line_code == note.line_code |
24 | = render "notes/diff_notes_with_reply", notes: discussion_notes | 24 | = render "notes/diff_notes_with_reply", notes: discussion_notes |
25 | - - break # cut off diff after notes |