diff options
author | Robert Speicher <robert@gitlab.com> | 2016-07-21 20:56:23 +0300 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2016-07-21 20:56:23 +0300 |
commit | 89292551295418cf4b5b90ce904a6b41f19a8be3 (patch) | |
tree | 838aba8af56513d28760ae15516479a7eaf34e15 /lib | |
parent | 0606b92c8532a0268a919bd3d0c5a083bad5ecf9 (diff) | |
parent | 79214be727aaa0704a1be5b50aa6dd3011629bc2 (diff) |
Merge branch 'discussion-model' into 'master'
Add Discussion model to represent MR/diff discussion
Related to https://gitlab.com/gitlab-org/gitlab-ce/issues/10325.
See merge request !5376
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/diff/parallel_diff.rb | 63 |
1 files changed, 10 insertions, 53 deletions
diff --git a/lib/gitlab/diff/parallel_diff.rb b/lib/gitlab/diff/parallel_diff.rb index b069afdd28c..481536a380b 100644 --- a/lib/gitlab/diff/parallel_diff.rb +++ b/lib/gitlab/diff/parallel_diff.rb @@ -8,72 +8,35 @@ module Gitlab end def parallelize - i = 0 free_right_index = nil lines = [] highlighted_diff_lines = diff_file.highlighted_diff_lines highlighted_diff_lines.each do |line| - line_code = diff_file.line_code(line) - position = diff_file.position(line) - - case line.type - when 'match', nil + if line.meta? || line.unchanged? # line in the right panel is the same as in the left one lines << { - left: { - type: line.type, - number: line.old_pos, - text: line.text, - line_code: line_code, - position: position - }, - right: { - type: line.type, - number: line.new_pos, - text: line.text, - line_code: line_code, - position: position - } + left: line, + right: line } free_right_index = nil i += 1 - when 'old' + elsif line.removed? lines << { - left: { - type: line.type, - number: line.old_pos, - text: line.text, - line_code: line_code, - position: position - }, - right: { - type: nil, - number: nil, - text: "", - line_code: line_code, - position: position - } + left: line, + right: nil } # Once we come upon a new line it can be put on the right of this old line free_right_index ||= i i += 1 - when 'new' - data = { - type: line.type, - number: line.new_pos, - text: line.text, - line_code: line_code, - position: position - } - + elsif line.added? if free_right_index # If an old line came before this without a line on the right, this # line can be put to the right of it. - lines[free_right_index][:right] = data + lines[free_right_index][:right] = line # If there are any other old lines on the left that don't yet have # a new counterpart on the right, update the free_right_index @@ -81,14 +44,8 @@ module Gitlab free_right_index = next_free_right_index < i ? next_free_right_index : nil else lines << { - left: { - type: nil, - number: nil, - text: "", - line_code: line_code, - position: position - }, - right: data + left: nil, + right: line } free_right_index = nil |