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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
04251829
Commit
04251829
authored
Jun 01, 2017
by
Sean McGivern
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dm-collapsed-blob' into 'master'
Consistent diff and blob size limit names See merge request !11776
parents
dd7449b9
04cf618b
Changes
32
Show whitespace changes
Inline
Side-by-side
Showing
32 changed files
with
161 additions
and
199 deletions
+161
-199
app/controllers/concerns/renders_blob.rb
app/controllers/concerns/renders_blob.rb
+2
-2
app/controllers/projects/artifacts_controller.rb
app/controllers/projects/artifacts_controller.rb
+1
-1
app/controllers/projects/blob_controller.rb
app/controllers/projects/blob_controller.rb
+1
-1
app/controllers/projects/snippets_controller.rb
app/controllers/projects/snippets_controller.rb
+1
-1
app/controllers/snippets_controller.rb
app/controllers/snippets_controller.rb
+1
-1
app/helpers/blob_helper.rb
app/helpers/blob_helper.rb
+5
-9
app/helpers/diff_helper.rb
app/helpers/diff_helper.rb
+4
-4
app/models/blob.rb
app/models/blob.rb
+4
-8
app/models/blob_viewer/auxiliary.rb
app/models/blob_viewer/auxiliary.rb
+2
-2
app/models/blob_viewer/base.rb
app/models/blob_viewer/base.rb
+10
-16
app/models/blob_viewer/client_side.rb
app/models/blob_viewer/client_side.rb
+2
-2
app/models/blob_viewer/server_side.rb
app/models/blob_viewer/server_side.rb
+2
-2
app/models/blob_viewer/text.rb
app/models/blob_viewer/text.rb
+2
-2
app/models/merge_request.rb
app/models/merge_request.rb
+2
-2
app/views/projects/diffs/_content.html.haml
app/views/projects/diffs/_content.html.haml
+1
-1
app/views/projects/diffs/_diffs.html.haml
app/views/projects/diffs/_diffs.html.haml
+2
-2
lib/api/commits.rb
lib/api/commits.rb
+1
-1
lib/api/entities.rb
lib/api/entities.rb
+3
-3
lib/api/v3/commits.rb
lib/api/v3/commits.rb
+1
-1
lib/api/v3/entities.rb
lib/api/v3/entities.rb
+1
-1
lib/gitlab/diff/file_collection/base.rb
lib/gitlab/diff/file_collection/base.rb
+1
-1
lib/gitlab/email/message/repository_push.rb
lib/gitlab/email/message/repository_push.rb
+1
-1
lib/gitlab/git/blob.rb
lib/gitlab/git/blob.rb
+1
-0
lib/gitlab/git/diff.rb
lib/gitlab/git/diff.rb
+32
-27
lib/gitlab/git/diff_collection.rb
lib/gitlab/git/diff_collection.rb
+10
-10
spec/helpers/blob_helper_spec.rb
spec/helpers/blob_helper_spec.rb
+13
-15
spec/helpers/diff_helper_spec.rb
spec/helpers/diff_helper_spec.rb
+5
-5
spec/lib/gitlab/git/diff_collection_spec.rb
spec/lib/gitlab/git/diff_collection_spec.rb
+13
-13
spec/lib/gitlab/git/diff_spec.rb
spec/lib/gitlab/git/diff_spec.rb
+12
-12
spec/models/blob_viewer/base_spec.rb
spec/models/blob_viewer/base_spec.rb
+21
-49
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+2
-2
spec/views/projects/blob/_viewer.html.haml_spec.rb
spec/views/projects/blob/_viewer.html.haml_spec.rb
+2
-2
No files found.
app/controllers/concerns/renders_blob.rb
View file @
04251829
...
@@ -18,7 +18,7 @@ module RendersBlob
...
@@ -18,7 +18,7 @@ module RendersBlob
}
}
end
end
def
override_max_blob_size
(
blob
)
def
conditionally_expand_blob
(
blob
)
blob
.
override_max_size!
if
params
[
:override_max_size
]
==
'true'
blob
.
expand!
if
params
[
:expanded
]
==
'true'
end
end
end
end
app/controllers/projects/artifacts_controller.rb
View file @
04251829
...
@@ -27,7 +27,7 @@ class Projects::ArtifactsController < Projects::ApplicationController
...
@@ -27,7 +27,7 @@ class Projects::ArtifactsController < Projects::ApplicationController
def
file
def
file
blob
=
@entry
.
blob
blob
=
@entry
.
blob
override_max_blob_size
(
blob
)
conditionally_expand_blob
(
blob
)
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
html
do
format
.
html
do
...
...
app/controllers/projects/blob_controller.rb
View file @
04251829
...
@@ -35,7 +35,7 @@ class Projects::BlobController < Projects::ApplicationController
...
@@ -35,7 +35,7 @@ class Projects::BlobController < Projects::ApplicationController
end
end
def
show
def
show
override_max_blob_size
(
@blob
)
conditionally_expand_blob
(
@blob
)
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
html
do
format
.
html
do
...
...
app/controllers/projects/snippets_controller.rb
View file @
04251829
...
@@ -56,7 +56,7 @@ class Projects::SnippetsController < Projects::ApplicationController
...
@@ -56,7 +56,7 @@ class Projects::SnippetsController < Projects::ApplicationController
def
show
def
show
blob
=
@snippet
.
blob
blob
=
@snippet
.
blob
override_max_blob_size
(
blob
)
conditionally_expand_blob
(
blob
)
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
html
do
format
.
html
do
...
...
app/controllers/snippets_controller.rb
View file @
04251829
...
@@ -58,7 +58,7 @@ class SnippetsController < ApplicationController
...
@@ -58,7 +58,7 @@ class SnippetsController < ApplicationController
def
show
def
show
blob
=
@snippet
.
blob
blob
=
@snippet
.
blob
override_max_blob_size
(
blob
)
conditionally_expand_blob
(
blob
)
@note
=
Note
.
new
(
noteable:
@snippet
)
@note
=
Note
.
new
(
noteable:
@snippet
)
@noteable
=
@snippet
@noteable
=
@snippet
...
...
app/helpers/blob_helper.rb
View file @
04251829
...
@@ -240,14 +240,10 @@ module BlobHelper
...
@@ -240,14 +240,10 @@ module BlobHelper
def
blob_render_error_reason
(
viewer
)
def
blob_render_error_reason
(
viewer
)
case
viewer
.
render_error
case
viewer
.
render_error
when
:collapsed
"it is larger than
#{
number_to_human_size
(
viewer
.
collapse_limit
)
}
"
when
:too_large
when
:too_large
max_size
=
"it is larger than
#{
number_to_human_size
(
viewer
.
size_limit
)
}
"
if
viewer
.
can_override_max_size?
viewer
.
overridable_max_size
else
viewer
.
max_size
end
"it is larger than
#{
number_to_human_size
(
max_size
)
}
"
when
:server_side_but_stored_externally
when
:server_side_but_stored_externally
case
viewer
.
blob
.
external_storage
case
viewer
.
blob
.
external_storage
when
:lfs
when
:lfs
...
@@ -264,8 +260,8 @@ module BlobHelper
...
@@ -264,8 +260,8 @@ module BlobHelper
error
=
viewer
.
render_error
error
=
viewer
.
render_error
options
=
[]
options
=
[]
if
error
==
:
too_large
&&
viewer
.
can_override_max_size?
if
error
==
:
collapsed
options
<<
link_to
(
'load it anyway'
,
url_for
(
params
.
merge
(
viewer:
viewer
.
type
,
override_max_size
:
true
,
format:
nil
)))
options
<<
link_to
(
'load it anyway'
,
url_for
(
params
.
merge
(
viewer:
viewer
.
type
,
expanded
:
true
,
format:
nil
)))
end
end
# If the error is `:server_side_but_stored_externally`, the simple viewer will show the same error,
# If the error is `:server_side_but_stored_externally`, the simple viewer will show the same error,
...
...
app/helpers/diff_helper.rb
View file @
04251829
...
@@ -8,8 +8,8 @@ module DiffHelper
...
@@ -8,8 +8,8 @@ module DiffHelper
[
marked_old_line
,
marked_new_line
]
[
marked_old_line
,
marked_new_line
]
end
end
def
expand_all_diffs
?
def
diffs_expanded
?
params
[
:expand
_all_diffs
].
present?
params
[
:expand
ed
].
present?
end
end
def
diff_view
def
diff_view
...
@@ -22,10 +22,10 @@ module DiffHelper
...
@@ -22,10 +22,10 @@ module DiffHelper
end
end
def
diff_options
def
diff_options
options
=
{
ignore_whitespace_change:
hide_whitespace?
,
no_collapse:
expand_all_diffs
?
}
options
=
{
ignore_whitespace_change:
hide_whitespace?
,
expanded:
diffs_expanded
?
}
if
action_name
==
'diff_for_path'
if
action_name
==
'diff_for_path'
options
[
:
no_collapse
]
=
true
options
[
:
expanded
]
=
true
options
[
:paths
]
=
params
.
values_at
(
:old_path
,
:new_path
)
options
[
:paths
]
=
params
.
values_at
(
:old_path
,
:new_path
)
end
end
...
...
app/models/blob.rb
View file @
04251829
...
@@ -102,10 +102,6 @@ class Blob < SimpleDelegator
...
@@ -102,10 +102,6 @@ class Blob < SimpleDelegator
raw_size
==
0
raw_size
==
0
end
end
def
too_large?
size
&&
truncated?
end
def
external_storage_error?
def
external_storage_error?
if
external_storage
==
:lfs
if
external_storage
==
:lfs
!
project
&
.
lfs_enabled?
!
project
&
.
lfs_enabled?
...
@@ -160,7 +156,7 @@ class Blob < SimpleDelegator
...
@@ -160,7 +156,7 @@ class Blob < SimpleDelegator
end
end
def
readable_text?
def
readable_text?
text?
&&
!
stored_externally?
&&
!
t
oo_large
?
text?
&&
!
stored_externally?
&&
!
t
runcated
?
end
end
def
simple_viewer
def
simple_viewer
...
@@ -187,9 +183,9 @@ class Blob < SimpleDelegator
...
@@ -187,9 +183,9 @@ class Blob < SimpleDelegator
rendered_as_text?
&&
rich_viewer
rendered_as_text?
&&
rich_viewer
end
end
def
override_max_size
!
def
expand
!
simple_viewer
&
.
override_max_size
=
true
simple_viewer
&
.
expanded
=
true
rich_viewer
&
.
override_max_size
=
true
rich_viewer
&
.
expanded
=
true
end
end
private
private
...
...
app/models/blob_viewer/auxiliary.rb
View file @
04251829
...
@@ -7,8 +7,8 @@ module BlobViewer
...
@@ -7,8 +7,8 @@ module BlobViewer
included
do
included
do
self
.
loading_partial_name
=
'loading_auxiliary'
self
.
loading_partial_name
=
'loading_auxiliary'
self
.
type
=
:auxiliary
self
.
type
=
:auxiliary
self
.
overridable_max_size
=
100
.
kilobytes
self
.
collapse_limit
=
100
.
kilobytes
self
.
max_size
=
100
.
kilobytes
self
.
size_limit
=
100
.
kilobytes
end
end
def
visible_to?
(
current_user
)
def
visible_to?
(
current_user
)
...
...
app/models/blob_viewer/base.rb
View file @
04251829
...
@@ -2,14 +2,14 @@ module BlobViewer
...
@@ -2,14 +2,14 @@ module BlobViewer
class
Base
class
Base
PARTIAL_PATH_PREFIX
=
'projects/blob/viewers'
.
freeze
PARTIAL_PATH_PREFIX
=
'projects/blob/viewers'
.
freeze
class_attribute
:partial_name
,
:loading_partial_name
,
:type
,
:extensions
,
:file_types
,
:load_async
,
:binary
,
:switcher_icon
,
:switcher_title
,
:
overridable_max_size
,
:max_size
class_attribute
:partial_name
,
:loading_partial_name
,
:type
,
:extensions
,
:file_types
,
:load_async
,
:binary
,
:switcher_icon
,
:switcher_title
,
:
collapse_limit
,
:size_limit
self
.
loading_partial_name
=
'loading'
self
.
loading_partial_name
=
'loading'
delegate
:partial_path
,
:loading_partial_path
,
:rich?
,
:simple?
,
:text?
,
:binary?
,
to: :class
delegate
:partial_path
,
:loading_partial_path
,
:rich?
,
:simple?
,
:text?
,
:binary?
,
to: :class
attr_reader
:blob
attr_reader
:blob
attr_accessor
:
override_max_size
attr_accessor
:
expanded
delegate
:project
,
to: :blob
delegate
:project
,
to: :blob
...
@@ -61,24 +61,16 @@ module BlobViewer
...
@@ -61,24 +61,16 @@ module BlobViewer
self
.
class
.
load_async?
&&
render_error
.
nil?
self
.
class
.
load_async?
&&
render_error
.
nil?
end
end
def
exceeds_overridable_max_size?
def
collapsed?
overridable_max_size
&&
blob
.
raw_size
>
overridable_max_size
return
@collapsed
if
defined?
(
@collapsed
)
end
def
exceeds_max_size?
max_size
&&
blob
.
raw_size
>
max_size
end
def
can_override_max_size?
@collapsed
=
!
expanded
&&
collapse_limit
&&
blob
.
raw_size
>
collapse_limit
exceeds_overridable_max_size?
&&
!
exceeds_max_size?
end
end
def
too_large?
def
too_large?
if
override_max_size
return
@too_large
if
defined?
(
@too_large
)
exceeds_max_size?
else
@too_large
=
size_limit
&&
blob
.
raw_size
>
size_limit
exceeds_overridable_max_size?
end
end
end
# This method is used on the server side to check whether we can attempt to
# This method is used on the server side to check whether we can attempt to
...
@@ -95,6 +87,8 @@ module BlobViewer
...
@@ -95,6 +87,8 @@ module BlobViewer
def
render_error
def
render_error
if
too_large?
if
too_large?
:too_large
:too_large
elsif
collapsed?
:collapsed
end
end
end
end
...
...
app/models/blob_viewer/client_side.rb
View file @
04251829
...
@@ -4,8 +4,8 @@ module BlobViewer
...
@@ -4,8 +4,8 @@ module BlobViewer
included
do
included
do
self
.
load_async
=
false
self
.
load_async
=
false
self
.
overridable_max_size
=
10
.
megabytes
self
.
collapse_limit
=
10
.
megabytes
self
.
max_size
=
50
.
megabytes
self
.
size_limit
=
50
.
megabytes
end
end
end
end
end
end
app/models/blob_viewer/server_side.rb
View file @
04251829
...
@@ -4,8 +4,8 @@ module BlobViewer
...
@@ -4,8 +4,8 @@ module BlobViewer
included
do
included
do
self
.
load_async
=
true
self
.
load_async
=
true
self
.
overridable_max_size
=
2
.
megabytes
self
.
collapse_limit
=
2
.
megabytes
self
.
max_size
=
5
.
megabytes
self
.
size_limit
=
5
.
megabytes
end
end
def
prepare!
def
prepare!
...
...
app/models/blob_viewer/text.rb
View file @
04251829
...
@@ -5,7 +5,7 @@ module BlobViewer
...
@@ -5,7 +5,7 @@ module BlobViewer
self
.
partial_name
=
'text'
self
.
partial_name
=
'text'
self
.
binary
=
false
self
.
binary
=
false
self
.
overridable_max_size
=
1
.
megabyte
self
.
collapse_limit
=
1
.
megabyte
self
.
max_size
=
10
.
megabytes
self
.
size_limit
=
10
.
megabytes
end
end
end
end
app/models/merge_request.rb
View file @
04251829
...
@@ -220,10 +220,10 @@ class MergeRequest < ActiveRecord::Base
...
@@ -220,10 +220,10 @@ class MergeRequest < ActiveRecord::Base
def
diffs
(
diff_options
=
{})
def
diffs
(
diff_options
=
{})
if
compare
if
compare
# When saving MR diffs, `
no_collapse
` is implicitly added (because we need
# When saving MR diffs, `
expanded
` is implicitly added (because we need
# to save the entire contents to the DB), so add that here for
# to save the entire contents to the DB), so add that here for
# consistency.
# consistency.
compare
.
diffs
(
diff_options
.
merge
(
no_collapse
:
true
))
compare
.
diffs
(
diff_options
.
merge
(
expanded
:
true
))
else
else
merge_request_diff
.
diffs
(
diff_options
)
merge_request_diff
.
diffs
(
diff_options
)
end
end
...
...
app/views/projects/diffs/_content.html.haml
View file @
04251829
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
.diff-content
.diff-content
-
if
diff_file
.
too_large?
-
if
diff_file
.
too_large?
.nothing-here-block
This diff could not be displayed because it is too large.
.nothing-here-block
This diff could not be displayed because it is too large.
-
elsif
blob
.
t
oo_large
?
-
elsif
blob
.
t
runcated
?
.nothing-here-block
The file could not be displayed because it is too large.
.nothing-here-block
The file could not be displayed because it is too large.
-
elsif
blob
.
readable_text?
-
elsif
blob
.
readable_text?
-
if
!
diff_file
.
repository
.
diffable?
(
blob
)
-
if
!
diff_file
.
repository
.
diffable?
(
blob
)
...
...
app/views/projects/diffs/_diffs.html.haml
View file @
04251829
...
@@ -5,8 +5,8 @@
...
@@ -5,8 +5,8 @@
.content-block.oneline-block.files-changed
.content-block.oneline-block.files-changed
.inline-parallel-buttons
.inline-parallel-buttons
-
if
!
expand_all_diffs
?
&&
diff_files
.
any?
{
|
diff_file
|
diff_file
.
collapsed?
}
-
if
!
diffs_expanded
?
&&
diff_files
.
any?
{
|
diff_file
|
diff_file
.
collapsed?
}
=
link_to
'Expand all'
,
url_for
(
params
.
merge
(
expand
_all_diffs
:
1
,
format:
nil
)),
class:
'btn btn-default'
=
link_to
'Expand all'
,
url_for
(
params
.
merge
(
expand
ed
:
1
,
format:
nil
)),
class:
'btn btn-default'
-
if
show_whitespace_toggle
-
if
show_whitespace_toggle
-
if
current_controller?
(
:commit
)
-
if
current_controller?
(
:commit
)
=
commit_diff_whitespace_link
(
diffs
.
project
,
@commit
,
class:
'hidden-xs'
)
=
commit_diff_whitespace_link
(
diffs
.
project
,
@commit
,
class:
'hidden-xs'
)
...
...
lib/api/commits.rb
View file @
04251829
...
@@ -176,7 +176,7 @@ module API
...
@@ -176,7 +176,7 @@ module API
}
}
if
params
[
:path
]
if
params
[
:path
]
commit
.
raw_diffs
(
all_diffs:
tru
e
).
each
do
|
diff
|
commit
.
raw_diffs
(
limits:
fals
e
).
each
do
|
diff
|
next
unless
diff
.
new_path
==
params
[
:path
]
next
unless
diff
.
new_path
==
params
[
:path
]
lines
=
Gitlab
::
Diff
::
Parser
.
new
.
parse
(
diff
.
diff
.
each_line
)
lines
=
Gitlab
::
Diff
::
Parser
.
new
.
parse
(
diff
.
diff
.
each_line
)
...
...
lib/api/entities.rb
View file @
04251829
...
@@ -331,7 +331,7 @@ module API
...
@@ -331,7 +331,7 @@ module API
class
MergeRequestChanges
<
MergeRequest
class
MergeRequestChanges
<
MergeRequest
expose
:diffs
,
as: :changes
,
using:
Entities
::
RepoDiff
do
|
compare
,
_
|
expose
:diffs
,
as: :changes
,
using:
Entities
::
RepoDiff
do
|
compare
,
_
|
compare
.
raw_diffs
(
all_diffs:
tru
e
).
to_a
compare
.
raw_diffs
(
limits:
fals
e
).
to_a
end
end
end
end
...
@@ -344,7 +344,7 @@ module API
...
@@ -344,7 +344,7 @@ module API
expose
:commits
,
using:
Entities
::
RepoCommit
expose
:commits
,
using:
Entities
::
RepoCommit
expose
:diffs
,
using:
Entities
::
RepoDiff
do
|
compare
,
_
|
expose
:diffs
,
using:
Entities
::
RepoDiff
do
|
compare
,
_
|
compare
.
raw_diffs
(
all_diffs:
tru
e
).
to_a
compare
.
raw_diffs
(
limits:
fals
e
).
to_a
end
end
end
end
...
@@ -548,7 +548,7 @@ module API
...
@@ -548,7 +548,7 @@ module API
end
end
expose
:diffs
,
using:
Entities
::
RepoDiff
do
|
compare
,
options
|
expose
:diffs
,
using:
Entities
::
RepoDiff
do
|
compare
,
options
|
compare
.
diffs
(
all_diffs:
tru
e
).
to_a
compare
.
diffs
(
limits:
fals
e
).
to_a
end
end
expose
:compare_timeout
do
|
compare
,
options
|
expose
:compare_timeout
do
|
compare
,
options
|
...
...
lib/api/v3/commits.rb
View file @
04251829
...
@@ -167,7 +167,7 @@ module API
...
@@ -167,7 +167,7 @@ module API
}
}
if
params
[
:path
]
if
params
[
:path
]
commit
.
raw_diffs
(
all_diffs:
tru
e
).
each
do
|
diff
|
commit
.
raw_diffs
(
limits:
fals
e
).
each
do
|
diff
|
next
unless
diff
.
new_path
==
params
[
:path
]
next
unless
diff
.
new_path
==
params
[
:path
]
lines
=
Gitlab
::
Diff
::
Parser
.
new
.
parse
(
diff
.
diff
.
each_line
)
lines
=
Gitlab
::
Diff
::
Parser
.
new
.
parse
(
diff
.
diff
.
each_line
)
...
...
lib/api/v3/entities.rb
View file @
04251829
...
@@ -226,7 +226,7 @@ module API
...
@@ -226,7 +226,7 @@ module API
class
MergeRequestChanges
<
MergeRequest
class
MergeRequestChanges
<
MergeRequest
expose
:diffs
,
as: :changes
,
using:
::
API
::
Entities
::
RepoDiff
do
|
compare
,
_
|
expose
:diffs
,
as: :changes
,
using:
::
API
::
Entities
::
RepoDiff
do
|
compare
,
_
|
compare
.
raw_diffs
(
all_diffs:
tru
e
).
to_a
compare
.
raw_diffs
(
limits:
fals
e
).
to_a
end
end
end
end
...
...
lib/gitlab/diff/file_collection/base.rb
View file @
04251829
...
@@ -7,7 +7,7 @@ module Gitlab
...
@@ -7,7 +7,7 @@ module Gitlab
delegate
:count
,
:size
,
:real_size
,
to: :diff_files
delegate
:count
,
:size
,
:real_size
,
to: :diff_files
def
self
.
default_options
def
self
.
default_options
::
Commit
.
max_diff_options
.
merge
(
ignore_whitespace_change:
false
,
no_collapse
:
false
)
::
Commit
.
max_diff_options
.
merge
(
ignore_whitespace_change:
false
,
expanded
:
false
)
end
end
def
initialize
(
diffable
,
project
:,
diff_options:
nil
,
diff_refs:
nil
,
fallback_diff_refs:
nil
)
def
initialize
(
diffable
,
project
:,
diff_options:
nil
,
diff_refs:
nil
,
fallback_diff_refs:
nil
)
...
...
lib/gitlab/email/message/repository_push.rb
View file @
04251829
...
@@ -42,7 +42,7 @@ module Gitlab
...
@@ -42,7 +42,7 @@ module Gitlab
return
unless
compare
return
unless
compare
# This diff is more moderated in number of files and lines
# This diff is more moderated in number of files and lines
@diffs
||=
compare
.
diffs
(
max_files:
30
,
max_lines:
5000
,
no_collapse
:
true
).
diff_files
@diffs
||=
compare
.
diffs
(
max_files:
30
,
max_lines:
5000
,
expanded
:
true
).
diff_files
end
end
def
diffs_count
def
diffs_count
...
...
lib/gitlab/git/blob.rb
View file @
04251829
...
@@ -88,6 +88,7 @@ module Gitlab
...
@@ -88,6 +88,7 @@ module Gitlab
new
(
new
(
id:
blob_entry
[
:oid
],
id:
blob_entry
[
:oid
],
name:
blob_entry
[
:name
],
name:
blob_entry
[
:name
],
size:
0
,
data:
''
,
data:
''
,
path:
path
,
path:
path
,
commit_id:
sha
commit_id:
sha
...
...
lib/gitlab/git/diff.rb
View file @
04251829
...
@@ -15,13 +15,16 @@ module Gitlab
...
@@ -15,13 +15,16 @@ module Gitlab
alias_method
:deleted_file?
,
:deleted_file
alias_method
:deleted_file?
,
:deleted_file
alias_method
:renamed_file?
,
:renamed_file
alias_method
:renamed_file?
,
:renamed_file
attr_accessor
:expanded
# We need this accessor because of `to_hash` and `init_from_hash`
attr_accessor
:too_large
attr_accessor
:too_large
# The maximum size of a diff to display.
# The maximum size of a diff to display.
DIFF_SIZE_LIMIT
=
102400
# 100 KB
SIZE_LIMIT
=
100
.
kilobytes
# The maximum size before a diff is collapsed.
# The maximum size before a diff is collapsed.
DIFF_COLLAPSE_LIMIT
=
10240
# 10 KB
COLLAPSE_LIMIT
=
10
.
kilobytes
class
<<
self
class
<<
self
def
between
(
repo
,
head
,
base
,
options
=
{},
*
paths
)
def
between
(
repo
,
head
,
base
,
options
=
{},
*
paths
)
...
@@ -152,7 +155,7 @@ module Gitlab
...
@@ -152,7 +155,7 @@ module Gitlab
:include_untracked_content
,
:skip_binary_check
,
:include_untracked_content
,
:skip_binary_check
,
:include_typechange
,
:include_typechange_trees
,
:include_typechange
,
:include_typechange_trees
,
:ignore_filemode
,
:recurse_ignored_dirs
,
:paths
,
:ignore_filemode
,
:recurse_ignored_dirs
,
:paths
,
:max_files
,
:max_lines
,
:
all_diffs
,
:no_collapse
]
:max_files
,
:max_lines
,
:
limits
,
:expanded
]
if
default_options
if
default_options
actual_defaults
=
default_options
.
dup
actual_defaults
=
default_options
.
dup
...
@@ -177,16 +180,18 @@ module Gitlab
...
@@ -177,16 +180,18 @@ module Gitlab
end
end
end
end
def
initialize
(
raw_diff
,
collapse:
false
)
def
initialize
(
raw_diff
,
expanded:
true
)
@expanded
=
expanded
case
raw_diff
case
raw_diff
when
Hash
when
Hash
init_from_hash
(
raw_diff
)
init_from_hash
(
raw_diff
)
prune_diff_if_eligible
(
collapse
)
prune_diff_if_eligible
when
Rugged
::
Patch
,
Rugged
::
Diff
::
Delta
when
Rugged
::
Patch
,
Rugged
::
Diff
::
Delta
init_from_rugged
(
raw_diff
,
collapse:
collapse
)
init_from_rugged
(
raw_diff
)
when
Gitaly
::
CommitDiffResponse
when
Gitaly
::
CommitDiffResponse
init_from_gitaly
(
raw_diff
)
init_from_gitaly
(
raw_diff
)
prune_diff_if_eligible
(
collapse
)
prune_diff_if_eligible
when
Gitaly
::
CommitDelta
when
Gitaly
::
CommitDelta
init_from_gitaly
(
raw_diff
)
init_from_gitaly
(
raw_diff
)
when
nil
when
nil
...
@@ -226,17 +231,13 @@ module Gitlab
...
@@ -226,17 +231,13 @@ module Gitlab
def
too_large?
def
too_large?
if
@too_large
.
nil?
if
@too_large
.
nil?
@too_large
=
@diff
.
bytesize
>=
DIFF_
SIZE_LIMIT
@too_large
=
@diff
.
bytesize
>=
SIZE_LIMIT
else
else
@too_large
@too_large
end
end
end
end
def
collapsible?
def
too_large!
@diff
.
bytesize
>=
DIFF_COLLAPSE_LIMIT
end
def
prune_large_diff!
@diff
=
''
@diff
=
''
@line_count
=
0
@line_count
=
0
@too_large
=
true
@too_large
=
true
...
@@ -244,10 +245,11 @@ module Gitlab
...
@@ -244,10 +245,11 @@ module Gitlab
def
collapsed?
def
collapsed?
return
@collapsed
if
defined?
(
@collapsed
)
return
@collapsed
if
defined?
(
@collapsed
)
false
@collapsed
=
!
expanded
&&
@diff
.
bytesize
>=
COLLAPSE_LIMIT
end
end
def
prune_collapsed_diff
!
def
collapse
!
@diff
=
''
@diff
=
''
@line_count
=
0
@line_count
=
0
@collapsed
=
true
@collapsed
=
true
...
@@ -255,9 +257,9 @@ module Gitlab
...
@@ -255,9 +257,9 @@ module Gitlab
private
private
def
init_from_rugged
(
rugged
,
collapse:
false
)
def
init_from_rugged
(
rugged
)
if
rugged
.
is_a?
(
Rugged
::
Patch
)
if
rugged
.
is_a?
(
Rugged
::
Patch
)
init_from_rugged_patch
(
rugged
,
collapse:
collapse
)
init_from_rugged_patch
(
rugged
)
d
=
rugged
.
delta
d
=
rugged
.
delta
else
else
d
=
rugged
d
=
rugged
...
@@ -272,10 +274,10 @@ module Gitlab
...
@@ -272,10 +274,10 @@ module Gitlab
@deleted_file
=
d
.
deleted?
@deleted_file
=
d
.
deleted?
end
end
def
init_from_rugged_patch
(
patch
,
collapse:
false
)
def
init_from_rugged_patch
(
patch
)
# Don't bother initializing diffs that are too large. If a diff is
# Don't bother initializing diffs that are too large. If a diff is
# binary we're not going to display anything so we skip the size check.
# binary we're not going to display anything so we skip the size check.
return
if
!
patch
.
delta
.
binary?
&&
prune_large_patch
(
patch
,
collapse
)
return
if
!
patch
.
delta
.
binary?
&&
prune_large_patch
(
patch
)
@diff
=
encode!
(
strip_diff_headers
(
patch
.
to_s
))
@diff
=
encode!
(
strip_diff_headers
(
patch
.
to_s
))
end
end
...
@@ -299,29 +301,32 @@ module Gitlab
...
@@ -299,29 +301,32 @@ module Gitlab
@deleted_file
=
msg
.
to_id
==
BLANK_SHA
@deleted_file
=
msg
.
to_id
==
BLANK_SHA
end
end
def
prune_diff_if_eligible
(
collapse
=
false
)
def
prune_diff_if_eligible
prune_large_diff!
if
too_large?
if
too_large?
prune_collapsed_diff!
if
collapse
&&
collapsible?
too_large!
elsif
collapsed?
collapse!
end
end
end
# If the patch surpasses any of the diff limits it calls the appropiate
# If the patch surpasses any of the diff limits it calls the appropiate
# prune method and returns true. Otherwise returns false.
# prune method and returns true. Otherwise returns false.
def
prune_large_patch
(
patch
,
collapse
)
def
prune_large_patch
(
patch
)
size
=
0
size
=
0
patch
.
each_hunk
do
|
hunk
|
patch
.
each_hunk
do
|
hunk
|
hunk
.
each_line
do
|
line
|
hunk
.
each_line
do
|
line
|
size
+=
line
.
content
.
bytesize
size
+=
line
.
content
.
bytesize
if
size
>=
DIFF_
SIZE_LIMIT
if
size
>=
SIZE_LIMIT
prune_large_diff
!
too_large
!
return
true
return
true
end
end
end
end
end
end
if
collapse
&&
size
>=
DIFF_
COLLAPSE_LIMIT
if
!
expanded
&&
size
>=
COLLAPSE_LIMIT
prune_collapsed_diff
!
collapse
!
return
true
return
true
end
end
...
...
lib/gitlab/git/diff_collection.rb
View file @
04251829
...
@@ -9,12 +9,12 @@ module Gitlab
...
@@ -9,12 +9,12 @@ module Gitlab
@iterator
=
iterator
@iterator
=
iterator
@max_files
=
options
.
fetch
(
:max_files
,
DEFAULT_LIMITS
[
:max_files
])
@max_files
=
options
.
fetch
(
:max_files
,
DEFAULT_LIMITS
[
:max_files
])
@max_lines
=
options
.
fetch
(
:max_lines
,
DEFAULT_LIMITS
[
:max_lines
])
@max_lines
=
options
.
fetch
(
:max_lines
,
DEFAULT_LIMITS
[
:max_lines
])
@max_bytes
=
@max_files
*
5
120
# Average 5 KB per file
@max_bytes
=
@max_files
*
5
.
kilobytes
# Average 5 KB per file
@safe_max_files
=
[
@max_files
,
DEFAULT_LIMITS
[
:max_files
]].
min
@safe_max_files
=
[
@max_files
,
DEFAULT_LIMITS
[
:max_files
]].
min
@safe_max_lines
=
[
@max_lines
,
DEFAULT_LIMITS
[
:max_lines
]].
min
@safe_max_lines
=
[
@max_lines
,
DEFAULT_LIMITS
[
:max_lines
]].
min
@safe_max_bytes
=
@safe_max_files
*
5
120
# Average 5 KB per file
@safe_max_bytes
=
@safe_max_files
*
5
.
kilobytes
# Average 5 KB per file
@
all_diffs
=
!!
options
.
fetch
(
:all_diffs
,
fals
e
)
@
enforce_limits
=
!!
options
.
fetch
(
:limits
,
tru
e
)
@
no_collapse
=
!!
options
.
fetch
(
:no_collapse
,
true
)
@
expanded
=
!!
options
.
fetch
(
:expanded
,
true
)
@line_count
=
0
@line_count
=
0
@byte_count
=
0
@byte_count
=
0
...
@@ -88,23 +88,23 @@ module Gitlab
...
@@ -88,23 +88,23 @@ module Gitlab
@iterator
.
each
do
|
raw
|
@iterator
.
each
do
|
raw
|
@empty
=
false
@empty
=
false
if
!
@all_diff
s
&&
i
>=
@max_files
if
@enforce_limit
s
&&
i
>=
@max_files
@overflow
=
true
@overflow
=
true
break
break
end
end
collapse
=
!
@all_diffs
&&
!
@no_collapse
expanded
=
!
@enforce_limits
||
@expanded
diff
=
Gitlab
::
Git
::
Diff
.
new
(
raw
,
collapse:
collapse
)
diff
=
Gitlab
::
Git
::
Diff
.
new
(
raw
,
expanded:
expanded
)
if
collapse
&&
over_safe_limits?
(
i
)
if
!
expanded
&&
over_safe_limits?
(
i
)
diff
.
prune_collapsed_diff
!
diff
.
collapse
!
end
end
@line_count
+=
diff
.
line_count
@line_count
+=
diff
.
line_count
@byte_count
+=
diff
.
diff
.
bytesize
@byte_count
+=
diff
.
diff
.
bytesize
if
!
@all_diff
s
&&
(
@line_count
>=
@max_lines
||
@byte_count
>=
@max_bytes
)
if
@enforce_limit
s
&&
(
@line_count
>=
@max_lines
||
@byte_count
>=
@max_bytes
)
# This last Diff instance pushes us over the lines limit. We stop and
# This last Diff instance pushes us over the lines limit. We stop and
# discard it.
# discard it.
@overflow
=
true
@overflow
=
true
...
...
spec/helpers/blob_helper_spec.rb
View file @
04251829
...
@@ -118,8 +118,8 @@ describe BlobHelper do
...
@@ -118,8 +118,8 @@ describe BlobHelper do
Class
.
new
(
BlobViewer
::
Base
)
do
Class
.
new
(
BlobViewer
::
Base
)
do
include
BlobViewer
::
ServerSide
include
BlobViewer
::
ServerSide
self
.
overridable_max_size
=
1
.
megabyte
self
.
collapse_limit
=
1
.
megabyte
self
.
max_size
=
5
.
megabytes
self
.
size_limit
=
5
.
megabytes
self
.
type
=
:rich
self
.
type
=
:rich
end
end
end
end
...
@@ -129,7 +129,7 @@ describe BlobHelper do
...
@@ -129,7 +129,7 @@ describe BlobHelper do
describe
'#blob_render_error_reason'
do
describe
'#blob_render_error_reason'
do
context
'for error :too_large'
do
context
'for error :too_large'
do
context
'when the blob size is larger than the absolute
max size
'
do
context
'when the blob size is larger than the absolute
size limit
'
do
let
(
:blob
)
{
fake_blob
(
size:
10
.
megabytes
)
}
let
(
:blob
)
{
fake_blob
(
size:
10
.
megabytes
)
}
it
'returns an error message'
do
it
'returns an error message'
do
...
@@ -137,7 +137,7 @@ describe BlobHelper do
...
@@ -137,7 +137,7 @@ describe BlobHelper do
end
end
end
end
context
'when the blob size is larger than the
max size
'
do
context
'when the blob size is larger than the
size limit
'
do
let
(
:blob
)
{
fake_blob
(
size:
2
.
megabytes
)
}
let
(
:blob
)
{
fake_blob
(
size:
2
.
megabytes
)
}
it
'returns an error message'
do
it
'returns an error message'
do
...
@@ -168,8 +168,7 @@ describe BlobHelper do
...
@@ -168,8 +168,7 @@ describe BlobHelper do
controller
.
params
[
:id
]
=
File
.
join
(
'master'
,
blob
.
path
)
controller
.
params
[
:id
]
=
File
.
join
(
'master'
,
blob
.
path
)
end
end
context
'for error :too_large'
do
context
'for error :collapsed'
do
context
'when the max size can be overridden'
do
let
(
:blob
)
{
fake_blob
(
size:
2
.
megabytes
)
}
let
(
:blob
)
{
fake_blob
(
size:
2
.
megabytes
)
}
it
'includes a "load it anyway" link'
do
it
'includes a "load it anyway" link'
do
...
@@ -177,13 +176,12 @@ describe BlobHelper do
...
@@ -177,13 +176,12 @@ describe BlobHelper do
end
end
end
end
context
'when the max size cannot be overridden
'
do
context
'for error :too_large
'
do
let
(
:blob
)
{
fake_blob
(
size:
10
.
megabytes
)
}
let
(
:blob
)
{
fake_blob
(
size:
10
.
megabytes
)
}
it
'does not include a "load it anyway" link'
do
it
'does not include a "load it anyway" link'
do
expect
(
helper
.
blob_render_error_options
(
viewer
)).
not_to
include
(
/load it anyway/
)
expect
(
helper
.
blob_render_error_options
(
viewer
)).
not_to
include
(
/load it anyway/
)
end
end
end
context
'when the viewer is rich'
do
context
'when the viewer is rich'
do
context
'the blob is rendered as text'
do
context
'the blob is rendered as text'
do
...
...
spec/helpers/diff_helper_spec.rb
View file @
04251829
...
@@ -33,17 +33,17 @@ describe DiffHelper do
...
@@ -33,17 +33,17 @@ describe DiffHelper do
describe
'diff_options'
do
describe
'diff_options'
do
it
'returns no collapse false'
do
it
'returns no collapse false'
do
expect
(
diff_options
).
to
include
(
no_collapse
:
false
)
expect
(
diff_options
).
to
include
(
expanded
:
false
)
end
end
it
'returns no collapse true if expand
_all_diffs
'
do
it
'returns no collapse true if expand
ed
'
do
allow
(
controller
).
to
receive
(
:params
)
{
{
expand
_all_diffs
:
true
}
}
allow
(
controller
).
to
receive
(
:params
)
{
{
expand
ed
:
true
}
}
expect
(
diff_options
).
to
include
(
no_collapse
:
true
)
expect
(
diff_options
).
to
include
(
expanded
:
true
)
end
end
it
'returns no collapse true if action name diff_for_path'
do
it
'returns no collapse true if action name diff_for_path'
do
allow
(
controller
).
to
receive
(
:action_name
)
{
'diff_for_path'
}
allow
(
controller
).
to
receive
(
:action_name
)
{
'diff_for_path'
}
expect
(
diff_options
).
to
include
(
no_collapse
:
true
)
expect
(
diff_options
).
to
include
(
expanded
:
true
)
end
end
it
'returns paths if action name diff_for_path and param old path'
do
it
'returns paths if action name diff_for_path and param old path'
do
...
...
spec/lib/gitlab/git/diff_collection_spec.rb
View file @
04251829
...
@@ -6,8 +6,8 @@ describe Gitlab::Git::DiffCollection, seed_helper: true do
...
@@ -6,8 +6,8 @@ describe Gitlab::Git::DiffCollection, seed_helper: true do
iterator
,
iterator
,
max_files:
max_files
,
max_files:
max_files
,
max_lines:
max_lines
,
max_lines:
max_lines
,
all_diffs:
all_diff
s
,
limits:
limit
s
,
no_collapse:
no_collapse
expanded:
expanded
)
)
end
end
let
(
:iterator
)
{
MutatingConstantIterator
.
new
(
file_count
,
fake_diff
(
line_length
,
line_count
))
}
let
(
:iterator
)
{
MutatingConstantIterator
.
new
(
file_count
,
fake_diff
(
line_length
,
line_count
))
}
...
@@ -16,8 +16,8 @@ describe Gitlab::Git::DiffCollection, seed_helper: true do
...
@@ -16,8 +16,8 @@ describe Gitlab::Git::DiffCollection, seed_helper: true do
let
(
:line_count
)
{
1
}
let
(
:line_count
)
{
1
}
let
(
:max_files
)
{
10
}
let
(
:max_files
)
{
10
}
let
(
:max_lines
)
{
100
}
let
(
:max_lines
)
{
100
}
let
(
:
all_diffs
)
{
fals
e
}
let
(
:
limits
)
{
tru
e
}
let
(
:
no_collapse
)
{
true
}
let
(
:
expanded
)
{
true
}
describe
'#to_a'
do
describe
'#to_a'
do
subject
{
super
().
to_a
}
subject
{
super
().
to_a
}
...
@@ -75,7 +75,7 @@ describe Gitlab::Git::DiffCollection, seed_helper: true do
...
@@ -75,7 +75,7 @@ describe Gitlab::Git::DiffCollection, seed_helper: true do
end
end
context
'when limiting is disabled'
do
context
'when limiting is disabled'
do
let
(
:
all_diffs
)
{
tru
e
}
let
(
:
limits
)
{
fals
e
}
describe
'#overflow?'
do
describe
'#overflow?'
do
subject
{
super
().
overflow?
}
subject
{
super
().
overflow?
}
...
@@ -123,7 +123,7 @@ describe Gitlab::Git::DiffCollection, seed_helper: true do
...
@@ -123,7 +123,7 @@ describe Gitlab::Git::DiffCollection, seed_helper: true do
it
{
expect
(
subject
.
size
).
to
eq
(
0
)
}
it
{
expect
(
subject
.
size
).
to
eq
(
0
)
}
context
'when limiting is disabled'
do
context
'when limiting is disabled'
do
let
(
:
all_diffs
)
{
tru
e
}
let
(
:
limits
)
{
fals
e
}
describe
'#overflow?'
do
describe
'#overflow?'
do
subject
{
super
().
overflow?
}
subject
{
super
().
overflow?
}
...
@@ -167,7 +167,7 @@ describe Gitlab::Git::DiffCollection, seed_helper: true do
...
@@ -167,7 +167,7 @@ describe Gitlab::Git::DiffCollection, seed_helper: true do
it
{
expect
(
subject
.
size
).
to
eq
(
10
)
}
it
{
expect
(
subject
.
size
).
to
eq
(
10
)
}
context
'when limiting is disabled'
do
context
'when limiting is disabled'
do
let
(
:
all_diffs
)
{
tru
e
}
let
(
:
limits
)
{
fals
e
}
describe
'#overflow?'
do
describe
'#overflow?'
do
subject
{
super
().
overflow?
}
subject
{
super
().
overflow?
}
...
@@ -207,7 +207,7 @@ describe Gitlab::Git::DiffCollection, seed_helper: true do
...
@@ -207,7 +207,7 @@ describe Gitlab::Git::DiffCollection, seed_helper: true do
it
{
expect
(
subject
.
size
).
to
eq
(
3
)
}
it
{
expect
(
subject
.
size
).
to
eq
(
3
)
}
context
'when limiting is disabled'
do
context
'when limiting is disabled'
do
let
(
:
all_diffs
)
{
tru
e
}
let
(
:
limits
)
{
fals
e
}
describe
'#overflow?'
do
describe
'#overflow?'
do
subject
{
super
().
overflow?
}
subject
{
super
().
overflow?
}
...
@@ -273,7 +273,7 @@ describe Gitlab::Git::DiffCollection, seed_helper: true do
...
@@ -273,7 +273,7 @@ describe Gitlab::Git::DiffCollection, seed_helper: true do
it
{
expect
(
subject
.
size
).
to
eq
(
9
)
}
it
{
expect
(
subject
.
size
).
to
eq
(
9
)
}
context
'when limiting is disabled'
do
context
'when limiting is disabled'
do
let
(
:
all_diffs
)
{
tru
e
}
let
(
:
limits
)
{
fals
e
}
describe
'#overflow?'
do
describe
'#overflow?'
do
subject
{
super
().
overflow?
}
subject
{
super
().
overflow?
}
...
@@ -344,7 +344,7 @@ describe Gitlab::Git::DiffCollection, seed_helper: true do
...
@@ -344,7 +344,7 @@ describe Gitlab::Git::DiffCollection, seed_helper: true do
let
(
:iterator
)
{
[{
diff:
'a'
*
20480
}]
}
let
(
:iterator
)
{
[{
diff:
'a'
*
20480
}]
}
context
'when no collapse is set'
do
context
'when no collapse is set'
do
let
(
:
no_collapse
)
{
true
}
let
(
:
expanded
)
{
true
}
it
'yields Diff instances even when they are quite big'
do
it
'yields Diff instances even when they are quite big'
do
expect
{
|
b
|
subject
.
each
(
&
b
)
}.
expect
{
|
b
|
subject
.
each
(
&
b
)
}.
...
@@ -363,7 +363,7 @@ describe Gitlab::Git::DiffCollection, seed_helper: true do
...
@@ -363,7 +363,7 @@ describe Gitlab::Git::DiffCollection, seed_helper: true do
end
end
context
'when no collapse is unset'
do
context
'when no collapse is unset'
do
let
(
:
no_collapse
)
{
false
}
let
(
:
expanded
)
{
false
}
it
'yields Diff instances even when they are quite big'
do
it
'yields Diff instances even when they are quite big'
do
expect
{
|
b
|
subject
.
each
(
&
b
)
}.
expect
{
|
b
|
subject
.
each
(
&
b
)
}.
...
@@ -450,7 +450,7 @@ describe Gitlab::Git::DiffCollection, seed_helper: true do
...
@@ -450,7 +450,7 @@ describe Gitlab::Git::DiffCollection, seed_helper: true do
end
end
context
'when limiting is disabled'
do
context
'when limiting is disabled'
do
let
(
:
all_diffs
)
{
tru
e
}
let
(
:
limits
)
{
fals
e
}
it
'yields Diff instances even when they are quite big'
do
it
'yields Diff instances even when they are quite big'
do
expect
{
|
b
|
subject
.
each
(
&
b
)
}.
expect
{
|
b
|
subject
.
each
(
&
b
)
}.
...
...
spec/lib/gitlab/git/diff_spec.rb
View file @
04251829
...
@@ -85,12 +85,12 @@ EOT
...
@@ -85,12 +85,12 @@ EOT
# The patch total size is 200, with lines between 21 and 54.
# The patch total size is 200, with lines between 21 and 54.
# This is a quick-and-dirty way to test this. Ideally, a new patch is
# This is a quick-and-dirty way to test this. Ideally, a new patch is
# added to the test repo with a size that falls between the real limits.
# added to the test repo with a size that falls between the real limits.
stub_const
(
"
#{
described_class
}
::
DIFF_
SIZE_LIMIT"
,
150
)
stub_const
(
"
#{
described_class
}
::SIZE_LIMIT"
,
150
)
stub_const
(
"
#{
described_class
}
::
DIFF_
COLLAPSE_LIMIT"
,
100
)
stub_const
(
"
#{
described_class
}
::COLLAPSE_LIMIT"
,
100
)
end
end
it
'prunes the diff as a large diff instead of as a collapsed diff'
do
it
'prunes the diff as a large diff instead of as a collapsed diff'
do
diff
=
described_class
.
new
(
@rugged_diff
,
collapse:
tru
e
)
diff
=
described_class
.
new
(
@rugged_diff
,
expanded:
fals
e
)
expect
(
diff
.
diff
).
to
be_empty
expect
(
diff
.
diff
).
to
be_empty
expect
(
diff
).
to
be_too_large
expect
(
diff
).
to
be_too_large
...
@@ -269,7 +269,7 @@ EOT
...
@@ -269,7 +269,7 @@ EOT
it
'returns true for a diff that was explicitly marked as being too large'
do
it
'returns true for a diff that was explicitly marked as being too large'
do
diff
=
described_class
.
new
(
diff:
'a'
)
diff
=
described_class
.
new
(
diff:
'a'
)
diff
.
prune_large_diff
!
diff
.
too_large
!
expect
(
diff
.
too_large?
).
to
eq
(
true
)
expect
(
diff
.
too_large?
).
to
eq
(
true
)
end
end
...
@@ -291,31 +291,31 @@ EOT
...
@@ -291,31 +291,31 @@ EOT
it
'returns true for a diff that was explicitly marked as being collapsed'
do
it
'returns true for a diff that was explicitly marked as being collapsed'
do
diff
=
described_class
.
new
(
diff:
'a'
)
diff
=
described_class
.
new
(
diff:
'a'
)
diff
.
prune_collapsed_diff
!
diff
.
collapse
!
expect
(
diff
).
to
be_collapsed
expect
(
diff
).
to
be_collapsed
end
end
end
end
describe
'#collaps
ible
?'
do
describe
'#collaps
ed
?'
do
it
'returns true for a diff that is quite large'
do
it
'returns true for a diff that is quite large'
do
diff
=
described_class
.
new
(
diff:
'a'
*
20480
)
diff
=
described_class
.
new
(
{
diff:
'a'
*
20480
},
expanded:
false
)
expect
(
diff
).
to
be_collaps
ible
expect
(
diff
).
to
be_collaps
ed
end
end
it
'returns false for a diff that is small enough'
do
it
'returns false for a diff that is small enough'
do
diff
=
described_class
.
new
(
diff:
'a'
)
diff
=
described_class
.
new
(
{
diff:
'a'
},
expanded:
false
)
expect
(
diff
).
not_to
be_collaps
ible
expect
(
diff
).
not_to
be_collaps
ed
end
end
end
end
describe
'#
prune_collapsed_diff
!'
do
describe
'#
collapse
!'
do
it
'prunes the diff'
do
it
'prunes the diff'
do
diff
=
described_class
.
new
(
diff:
"foo
\n
bar"
)
diff
=
described_class
.
new
(
diff:
"foo
\n
bar"
)
diff
.
prune_collapsed_diff
!
diff
.
collapse
!
expect
(
diff
.
diff
).
to
eq
(
''
)
expect
(
diff
.
diff
).
to
eq
(
''
)
expect
(
diff
.
line_count
).
to
eq
(
0
)
expect
(
diff
.
line_count
).
to
eq
(
0
)
...
...
spec/models/blob_viewer/base_spec.rb
View file @
04251829
...
@@ -11,8 +11,8 @@ describe BlobViewer::Base, model: true do
...
@@ -11,8 +11,8 @@ describe BlobViewer::Base, model: true do
self
.
extensions
=
%w(pdf)
self
.
extensions
=
%w(pdf)
self
.
binary
=
true
self
.
binary
=
true
self
.
overridable_max_size
=
1
.
megabyte
self
.
collapse_limit
=
1
.
megabyte
self
.
max_size
=
5
.
megabytes
self
.
size_limit
=
5
.
megabytes
end
end
end
end
...
@@ -69,77 +69,49 @@ describe BlobViewer::Base, model: true do
...
@@ -69,77 +69,49 @@ describe BlobViewer::Base, model: true do
end
end
end
end
describe
'#
exceeds_overridable_max_size
?'
do
describe
'#
collapsed
?'
do
context
'when the blob size is larger than the
overridable max size
'
do
context
'when the blob size is larger than the
collapse limit
'
do
let
(
:blob
)
{
fake_blob
(
path:
'file.pdf'
,
size:
2
.
megabytes
)
}
let
(
:blob
)
{
fake_blob
(
path:
'file.pdf'
,
size:
2
.
megabytes
)
}
it
'returns true'
do
it
'returns true'
do
expect
(
viewer
.
exceeds_overridable_max_size
?
).
to
be_truthy
expect
(
viewer
.
collapsed
?
).
to
be_truthy
end
end
end
end
context
'when the blob size is smaller than the
overridable max size
'
do
context
'when the blob size is smaller than the
collapse limit
'
do
let
(
:blob
)
{
fake_blob
(
path:
'file.pdf'
,
size:
10
.
kilobytes
)
}
let
(
:blob
)
{
fake_blob
(
path:
'file.pdf'
,
size:
10
.
kilobytes
)
}
it
'returns false'
do
it
'returns false'
do
expect
(
viewer
.
exceeds_overridable_max_size
?
).
to
be_falsey
expect
(
viewer
.
collapsed
?
).
to
be_falsey
end
end
end
end
end
end
describe
'#
exceeds_max_siz
e?'
do
describe
'#
too_larg
e?'
do
context
'when the blob size is larger than the
max size
'
do
context
'when the blob size is larger than the
size limit
'
do
let
(
:blob
)
{
fake_blob
(
path:
'file.pdf'
,
size:
10
.
megabytes
)
}
let
(
:blob
)
{
fake_blob
(
path:
'file.pdf'
,
size:
10
.
megabytes
)
}
it
'returns true'
do
it
'returns true'
do
expect
(
viewer
.
exceeds_max_siz
e?
).
to
be_truthy
expect
(
viewer
.
too_larg
e?
).
to
be_truthy
end
end
end
end
context
'when the blob size is smaller than the
max size
'
do
context
'when the blob size is smaller than the
size limit
'
do
let
(
:blob
)
{
fake_blob
(
path:
'file.pdf'
,
size:
2
.
megabytes
)
}
let
(
:blob
)
{
fake_blob
(
path:
'file.pdf'
,
size:
2
.
megabytes
)
}
it
'returns false'
do
it
'returns false'
do
expect
(
viewer
.
exceeds_max_size?
).
to
be_falsey
expect
(
viewer
.
too_large?
).
to
be_falsey
end
end
end
describe
'#can_override_max_size?'
do
context
'when the blob size is larger than the overridable max size'
do
context
'when the blob size is larger than the max size'
do
let
(
:blob
)
{
fake_blob
(
path:
'file.pdf'
,
size:
10
.
megabytes
)
}
it
'returns false'
do
expect
(
viewer
.
can_override_max_size?
).
to
be_falsey
end
end
context
'when the blob size is smaller than the max size'
do
let
(
:blob
)
{
fake_blob
(
path:
'file.pdf'
,
size:
2
.
megabytes
)
}
it
'returns true'
do
expect
(
viewer
.
can_override_max_size?
).
to
be_truthy
end
end
end
context
'when the blob size is smaller than the overridable max size'
do
let
(
:blob
)
{
fake_blob
(
path:
'file.pdf'
,
size:
10
.
kilobytes
)
}
it
'returns false'
do
expect
(
viewer
.
can_override_max_size?
).
to
be_falsey
end
end
end
end
end
end
describe
'#render_error'
do
describe
'#render_error'
do
context
'when
the max size is overridden
'
do
context
'when
expanded
'
do
before
do
before
do
viewer
.
override_max_size
=
true
viewer
.
expanded
=
true
end
end
context
'when the blob size is larger than the
max size
'
do
context
'when the blob size is larger than the
size limit
'
do
let
(
:blob
)
{
fake_blob
(
path:
'file.pdf'
,
size:
10
.
megabytes
)
}
let
(
:blob
)
{
fake_blob
(
path:
'file.pdf'
,
size:
10
.
megabytes
)
}
it
'returns :too_large'
do
it
'returns :too_large'
do
...
@@ -147,7 +119,7 @@ describe BlobViewer::Base, model: true do
...
@@ -147,7 +119,7 @@ describe BlobViewer::Base, model: true do
end
end
end
end
context
'when the blob size is smaller than the
max size
'
do
context
'when the blob size is smaller than the
size limit
'
do
let
(
:blob
)
{
fake_blob
(
path:
'file.pdf'
,
size:
2
.
megabytes
)
}
let
(
:blob
)
{
fake_blob
(
path:
'file.pdf'
,
size:
2
.
megabytes
)
}
it
'returns nil'
do
it
'returns nil'
do
...
@@ -156,16 +128,16 @@ describe BlobViewer::Base, model: true do
...
@@ -156,16 +128,16 @@ describe BlobViewer::Base, model: true do
end
end
end
end
context
'when
the max size is not overridden
'
do
context
'when
not expanded
'
do
context
'when the blob size is larger than the
overridable max size
'
do
context
'when the blob size is larger than the
collapse limit
'
do
let
(
:blob
)
{
fake_blob
(
path:
'file.pdf'
,
size:
2
.
megabytes
)
}
let
(
:blob
)
{
fake_blob
(
path:
'file.pdf'
,
size:
2
.
megabytes
)
}
it
'returns :
too_large
'
do
it
'returns :
collapsed
'
do
expect
(
viewer
.
render_error
).
to
eq
(
:
too_large
)
expect
(
viewer
.
render_error
).
to
eq
(
:
collapsed
)
end
end
end
end
context
'when the blob size is smaller than the
overridable max size
'
do
context
'when the blob size is smaller than the
collapse limit
'
do
let
(
:blob
)
{
fake_blob
(
path:
'file.pdf'
,
size:
10
.
kilobytes
)
}
let
(
:blob
)
{
fake_blob
(
path:
'file.pdf'
,
size:
10
.
kilobytes
)
}
it
'returns nil'
do
it
'returns nil'
do
...
...
spec/models/merge_request_spec.rb
View file @
04251829
...
@@ -238,10 +238,10 @@ describe MergeRequest, models: true do
...
@@ -238,10 +238,10 @@ describe MergeRequest, models: true do
end
end
context
'when there are no MR diffs'
do
context
'when there are no MR diffs'
do
it
'delegates to the compare object, setting
no_collapse
: true'
do
it
'delegates to the compare object, setting
expanded
: true'
do
merge_request
.
compare
=
double
(
:compare
)
merge_request
.
compare
=
double
(
:compare
)
expect
(
merge_request
.
compare
).
to
receive
(
:diffs
).
with
(
options
.
merge
(
no_collapse
:
true
))
expect
(
merge_request
.
compare
).
to
receive
(
:diffs
).
with
(
options
.
merge
(
expanded
:
true
))
merge_request
.
diffs
(
options
)
merge_request
.
diffs
(
options
)
end
end
...
...
spec/views/projects/blob/_viewer.html.haml_spec.rb
View file @
04251829
...
@@ -10,8 +10,8 @@ describe 'projects/blob/_viewer.html.haml', :view do
...
@@ -10,8 +10,8 @@ describe 'projects/blob/_viewer.html.haml', :view do
include
BlobViewer
::
Rich
include
BlobViewer
::
Rich
self
.
partial_name
=
'text'
self
.
partial_name
=
'text'
self
.
overridable_max_size
=
1
.
megabyte
self
.
collapse_limit
=
1
.
megabyte
self
.
max_size
=
5
.
megabytes
self
.
size_limit
=
5
.
megabytes
self
.
load_async
=
true
self
.
load_async
=
true
end
end
end
end
...
...
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