Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
1e530120
Commit
1e530120
authored
Jun 16, 2021
by
Kerri Miller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Carry line_range info forward on unchanged positions
Changelog: fixed
parent
28a19b15
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
9 deletions
+56
-9
lib/gitlab/diff/position_tracer/line_strategy.rb
lib/gitlab/diff/position_tracer/line_strategy.rb
+12
-9
spec/lib/gitlab/diff/position_tracer/line_strategy_spec.rb
spec/lib/gitlab/diff/position_tracer/line_strategy_spec.rb
+44
-0
No files found.
lib/gitlab/diff/position_tracer/line_strategy.rb
View file @
1e530120
...
...
@@ -95,7 +95,7 @@ module Gitlab
if
c_line
# If the line is still in D but also in C, it has turned from an
# 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 the line is still in the MR, we don't treat this as outdated.
{
position:
new_position
,
outdated:
false
}
...
...
@@ -108,7 +108,7 @@ module Gitlab
end
else
# 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
else
# If the line is no longer in D, it has been removed from the MR.
...
...
@@ -143,7 +143,7 @@ module Gitlab
{
position:
new_position
(
bd_diff
,
nil
,
d_line
),
outdated:
true
}
else
# 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
else
# If the line is no longer in C, it has been removed outside of the MR.
...
...
@@ -174,7 +174,7 @@ module Gitlab
if
c_line
&&
d_line
# 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 the line is still in the MR, we don't treat this as outdated.
{
position:
new_position
,
outdated:
false
}
...
...
@@ -188,7 +188,7 @@ module Gitlab
# If the line is still in D but no longer in C, it has turned from
# an unchanged line into an added one.
# 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)
# If the line is no longer in D, it has turned from an unchanged line
# into a removed one.
...
...
@@ -196,12 +196,15 @@ module Gitlab
end
end
def
new_position
(
diff_file
,
old_line
,
new_line
)
Position
.
new
(
def
new_position
(
diff_file
,
old_line
,
new_line
,
line_range
=
nil
)
params
=
{
diff_file:
diff_file
,
old_line:
old_line
,
new_line:
new_line
)
new_line:
new_line
,
line_range:
line_range
}.
compact
Position
.
new
(
**
params
)
end
def
valid_position?
(
position
)
...
...
spec/lib/gitlab/diff/position_tracer/line_strategy_spec.rb
View file @
1e530120
...
...
@@ -288,6 +288,27 @@ RSpec.describe Gitlab::Diff::PositionTracer::LineStrategy, :clean_gitlab_redis_c
new_line:
old_position
.
new_line
)
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
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
new_line:
2
)
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
context
"when the file's content was changed between the old and the new diff"
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment