Skip to content
Snippets Groups Projects
Commit 79214be7 authored by Douwe Maan's avatar Douwe Maan
Browse files

Add Discussion model to represent MR/diff discussion

parent 5a77eb15
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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
Loading
Loading
@@ -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
Loading
Loading
This diff is collapsed.
Loading
Loading
@@ -11,11 +11,51 @@ describe Gitlab::Diff::ParallelDiff, lib: true do
let(:diff_file) { Gitlab::Diff::File.new(diff, diff_refs: commit.diff_refs, repository: repository) }
subject { described_class.new(diff_file) }
 
let(:parallel_diff_result_array) { YAML.load_file("#{Rails.root}/spec/fixtures/parallel_diff_result.yml") }
describe '#parallelize' do
it 'should return an array of arrays containing the parsed diff' do
expect(subject.parallelize).to match_array(parallel_diff_result_array)
diff_lines = diff_file.highlighted_diff_lines
expected = [
# Unchanged lines
{ left: diff_lines[0], right: diff_lines[0] },
{ left: diff_lines[1], right: diff_lines[1] },
{ left: diff_lines[2], right: diff_lines[2] },
{ left: diff_lines[3], right: diff_lines[3] },
{ left: diff_lines[4], right: diff_lines[5] },
{ left: diff_lines[6], right: diff_lines[6] },
{ left: diff_lines[7], right: diff_lines[7] },
{ left: diff_lines[8], right: diff_lines[8] },
# Changed lines
{ left: diff_lines[9], right: diff_lines[11] },
{ left: diff_lines[10], right: diff_lines[12] },
# Added lines
{ left: nil, right: diff_lines[13] },
{ left: nil, right: diff_lines[14] },
{ left: nil, right: diff_lines[15] },
{ left: nil, right: diff_lines[16] },
{ left: nil, right: diff_lines[17] },
{ left: nil, right: diff_lines[18] },
# Unchanged lines
{ left: diff_lines[19], right: diff_lines[19] },
{ left: diff_lines[20], right: diff_lines[20] },
{ left: diff_lines[21], right: diff_lines[21] },
{ left: diff_lines[22], right: diff_lines[22] },
{ left: diff_lines[23], right: diff_lines[23] },
{ left: diff_lines[24], right: diff_lines[24] },
{ left: diff_lines[25], right: diff_lines[25] },
# Added line
{ left: nil, right: diff_lines[26] },
# Unchanged lines
{ left: diff_lines[27], right: diff_lines[27] },
{ left: diff_lines[28], right: diff_lines[28] },
{ left: diff_lines[29], right: diff_lines[29] }
]
expect(subject.parallelize).to eq(expected)
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment