Commit aad0dbee authored by Max Woolf's avatar Max Woolf

Merge branch '322188-carry-line_range-information-forward-on-unchanged-positions' into 'master'

Carry line_range info forward on unchanged positions

See merge request gitlab-org/gitlab!64267
parents 329dee47 1e530120
...@@ -95,7 +95,7 @@ module Gitlab ...@@ -95,7 +95,7 @@ module Gitlab
if c_line if c_line
# If the line is still in D but also in C, it has turned from an # If the line is still in D but also in C, it has turned from an
# added line into an unchanged one. # added line into an unchanged one.
new_position = new_position(cd_diff, c_line, d_line) new_position = new_position(cd_diff, c_line, d_line, position.line_range)
if valid_position?(new_position) if valid_position?(new_position)
# If the line is still in the MR, we don't treat this as outdated. # If the line is still in the MR, we don't treat this as outdated.
{ position: new_position, outdated: false } { position: new_position, outdated: false }
...@@ -108,7 +108,7 @@ module Gitlab ...@@ -108,7 +108,7 @@ module Gitlab
end end
else else
# If the line is still in D and not in C, it is still added. # If the line is still in D and not in C, it is still added.
{ position: new_position(cd_diff, nil, d_line), outdated: false } { position: new_position(cd_diff, nil, d_line, position.line_range), outdated: false }
end end
else else
# If the line is no longer in D, it has been removed from the MR. # If the line is no longer in D, it has been removed from the MR.
...@@ -143,7 +143,7 @@ module Gitlab ...@@ -143,7 +143,7 @@ module Gitlab
{ position: new_position(bd_diff, nil, d_line), outdated: true } { position: new_position(bd_diff, nil, d_line), outdated: true }
else else
# If the line is still in C and not in D, it is still removed. # If the line is still in C and not in D, it is still removed.
{ position: new_position(cd_diff, c_line, nil), outdated: false } { position: new_position(cd_diff, c_line, nil, position.line_range), outdated: false }
end end
else else
# If the line is no longer in C, it has been removed outside of the MR. # If the line is no longer in C, it has been removed outside of the MR.
...@@ -174,7 +174,7 @@ module Gitlab ...@@ -174,7 +174,7 @@ module Gitlab
if c_line && d_line if c_line && d_line
# If the line is still in C and D, it is still unchanged. # If the line is still in C and D, it is still unchanged.
new_position = new_position(cd_diff, c_line, d_line) new_position = new_position(cd_diff, c_line, d_line, position.line_range)
if valid_position?(new_position) if valid_position?(new_position)
# If the line is still in the MR, we don't treat this as outdated. # If the line is still in the MR, we don't treat this as outdated.
{ position: new_position, outdated: false } { position: new_position, outdated: false }
...@@ -188,7 +188,7 @@ module Gitlab ...@@ -188,7 +188,7 @@ module Gitlab
# If the line is still in D but no longer in C, it has turned from # If the line is still in D but no longer in C, it has turned from
# an unchanged line into an added one. # an unchanged line into an added one.
# We don't treat this as outdated since the line is still in the MR. # We don't treat this as outdated since the line is still in the MR.
{ position: new_position(cd_diff, nil, d_line), outdated: false } { position: new_position(cd_diff, nil, d_line, position.line_range), outdated: false }
else # !d_line && (c_line || !c_line) else # !d_line && (c_line || !c_line)
# If the line is no longer in D, it has turned from an unchanged line # If the line is no longer in D, it has turned from an unchanged line
# into a removed one. # into a removed one.
...@@ -196,12 +196,15 @@ module Gitlab ...@@ -196,12 +196,15 @@ module Gitlab
end end
end end
def new_position(diff_file, old_line, new_line) def new_position(diff_file, old_line, new_line, line_range = nil)
Position.new( params = {
diff_file: diff_file, diff_file: diff_file,
old_line: old_line, old_line: old_line,
new_line: new_line new_line: new_line,
) line_range: line_range
}.compact
Position.new(**params)
end end
def valid_position?(position) def valid_position?(position)
......
...@@ -288,6 +288,27 @@ RSpec.describe Gitlab::Diff::PositionTracer::LineStrategy, :clean_gitlab_redis_c ...@@ -288,6 +288,27 @@ RSpec.describe Gitlab::Diff::PositionTracer::LineStrategy, :clean_gitlab_redis_c
new_line: old_position.new_line new_line: old_position.new_line
) )
end end
context "when the position is multiline" do
let(:old_position) do
position(
new_path: file_name,
new_line: 2,
line_range: {
"start_line_code" => 1,
"end_line_code" => 2
}
)
end
it "returns the new position along with line_range" do
expect_new_position(
new_path: old_position.new_path,
new_line: old_position.new_line,
line_range: old_position.line_range
)
end
end
end end
context "when the file's content was changed between the old and the new diff" do context "when the file's content was changed between the old and the new diff" do
...@@ -547,6 +568,29 @@ RSpec.describe Gitlab::Diff::PositionTracer::LineStrategy, :clean_gitlab_redis_c ...@@ -547,6 +568,29 @@ RSpec.describe Gitlab::Diff::PositionTracer::LineStrategy, :clean_gitlab_redis_c
new_line: 2 new_line: 2
) )
end end
context "when the position is multiline" do
let(:old_position) do
position(
new_path: file_name,
new_line: 2,
line_range: {
"start_line_code" => 1,
"end_line_code" => 2
}
)
end
it "returns the new position but drops line_range information" do
expect_change_position(
old_path: file_name,
new_path: file_name,
old_line: nil,
new_line: 2,
line_range: nil
)
end
end
end end
context "when the file's content was changed between the old and the new diff" do context "when the file's content was changed between the old and the new diff" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment