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
ad176055
Commit
ad176055
authored
Oct 16, 2020
by
Kerri Miller
Committed by
Ash McKenzie
Oct 16, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Automatically expand file on merge request with changes to single file
parent
554d2366
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
50 additions
and
12 deletions
+50
-12
changelogs/unreleased/254823-automatically-expand-file-on-merge-request-with-changes-to-single-.yml
...-expand-file-on-merge-request-with-changes-to-single-.yml
+5
-0
lib/gitlab/diff/highlight_cache.rb
lib/gitlab/diff/highlight_cache.rb
+4
-0
lib/gitlab/git/diff_collection.rb
lib/gitlab/git/diff_collection.rb
+9
-5
lib/gitlab/gitaly_client/diff_stitcher.rb
lib/gitlab/gitaly_client/diff_stitcher.rb
+8
-2
spec/lib/gitlab/git/diff_collection_spec.rb
spec/lib/gitlab/git/diff_collection_spec.rb
+24
-5
No files found.
changelogs/unreleased/254823-automatically-expand-file-on-merge-request-with-changes-to-single-.yml
0 → 100644
View file @
ad176055
---
title
:
Automatically expand diffs for merge requests with changes to a single file
merge_request
:
44629
author
:
type
:
changed
lib/gitlab/diff/highlight_cache.rb
View file @
ad176055
...
@@ -24,6 +24,10 @@ module Gitlab
...
@@ -24,6 +24,10 @@ module Gitlab
return
[]
unless
content
return
[]
unless
content
# TODO: We could add some kind of flag to #initialize that would allow
# us to force re-caching
# https://gitlab.com/gitlab-org/gitlab/-/issues/263508
#
if
content
.
empty?
&&
recache_due_to_size?
(
diff_file
)
if
content
.
empty?
&&
recache_due_to_size?
(
diff_file
)
# If the file is missing from the cache and there's reason to believe
# If the file is missing from the cache and there's reason to believe
# it is uncached due to a size issue around changing the values for
# it is uncached due to a size issue around changing the values for
...
...
lib/gitlab/git/diff_collection.rb
View file @
ad176055
...
@@ -118,11 +118,17 @@ module Gitlab
...
@@ -118,11 +118,17 @@ module Gitlab
files
>=
safe_max_files
||
@line_count
>
safe_max_lines
||
@byte_count
>=
safe_max_bytes
files
>=
safe_max_files
||
@line_count
>
safe_max_lines
||
@byte_count
>=
safe_max_bytes
end
end
def
expand_diff?
# Force single-entry diff collections to always present as expanded
#
@iterator
.
size
==
1
||
!
@enforce_limits
||
@expanded
end
def
each_gitaly_patch
def
each_gitaly_patch
i
=
@array
.
length
i
=
@array
.
length
@iterator
.
each
do
|
raw
|
@iterator
.
each
do
|
raw
|
diff
=
Gitlab
::
Git
::
Diff
.
new
(
raw
,
expanded:
!
@enforce_limits
||
@expanded
)
diff
=
Gitlab
::
Git
::
Diff
.
new
(
raw
,
expanded:
expand_diff?
)
if
raw
.
overflow_marker
if
raw
.
overflow_marker
@overflow
=
true
@overflow
=
true
...
@@ -145,11 +151,9 @@ module Gitlab
...
@@ -145,11 +151,9 @@ module Gitlab
break
break
end
end
expanded
=
!
@enforce_limits
||
@expanded
diff
=
Gitlab
::
Git
::
Diff
.
new
(
raw
,
expanded:
expand_diff?
)
diff
=
Gitlab
::
Git
::
Diff
.
new
(
raw
,
expanded:
expanded
)
if
!
expand
ed
&&
over_safe_limits?
(
i
)
&&
diff
.
line_count
>
0
if
!
expand
_diff?
&&
over_safe_limits?
(
i
)
&&
diff
.
line_count
>
0
diff
.
collapse!
diff
.
collapse!
end
end
...
...
lib/gitlab/gitaly_client/diff_stitcher.rb
View file @
ad176055
...
@@ -5,8 +5,10 @@ module Gitlab
...
@@ -5,8 +5,10 @@ module Gitlab
class
DiffStitcher
class
DiffStitcher
include
Enumerable
include
Enumerable
def
initialize
(
rpc_response
)
delegate
:size
,
to: :rpc_response
@rpc_response
=
rpc_response
def
initialize
(
rpc_response_param
)
@rpc_response
=
rpc_response_param
end
end
def
each
def
each
...
@@ -31,6 +33,10 @@ module Gitlab
...
@@ -31,6 +33,10 @@ module Gitlab
end
end
end
end
end
end
private
attr_reader
:rpc_response
end
end
end
end
end
end
spec/lib/gitlab/git/diff_collection_spec.rb
View file @
ad176055
...
@@ -9,8 +9,11 @@ RSpec.describe Gitlab::Git::DiffCollection, :seed_helper do
...
@@ -9,8 +9,11 @@ RSpec.describe Gitlab::Git::DiffCollection, :seed_helper do
MutatingConstantIterator
.
class_eval
do
MutatingConstantIterator
.
class_eval
do
include
Enumerable
include
Enumerable
attr_reader
:size
def
initialize
(
count
,
value
)
def
initialize
(
count
,
value
)
@count
=
count
@count
=
count
@size
=
count
@value
=
value
@value
=
value
end
end
...
@@ -517,14 +520,30 @@ RSpec.describe Gitlab::Git::DiffCollection, :seed_helper do
...
@@ -517,14 +520,30 @@ RSpec.describe Gitlab::Git::DiffCollection, :seed_helper do
.
to
yield_with_args
(
an_instance_of
(
Gitlab
::
Git
::
Diff
))
.
to
yield_with_args
(
an_instance_of
(
Gitlab
::
Git
::
Diff
))
end
end
it
'prunes diffs that are quite big'
do
context
'single-file collections'
do
diff
=
nil
it
'does not prune diffs'
do
diff
=
nil
subject
.
each
do
|
d
|
subject
.
each
do
|
d
|
diff
=
d
diff
=
d
end
expect
(
diff
.
diff
).
not_to
eq
(
''
)
end
end
end
context
'multi-file collections'
do
let
(
:iterator
)
{
[{
diff:
'b'
},
{
diff:
'a'
*
20480
}]}
it
'prunes diffs that are quite big'
do
diff
=
nil
expect
(
diff
.
diff
).
to
eq
(
''
)
subject
.
each
do
|
d
|
diff
=
d
end
expect
(
diff
.
diff
).
to
eq
(
''
)
end
end
end
context
'when go over safe limits on files'
do
context
'when go over safe limits on files'
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