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
2c0a664a
Commit
2c0a664a
authored
Dec 10, 2019
by
Kerri Miller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow diff_files to return undecorated files
parent
01e2177a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
9 deletions
+37
-9
lib/gitlab/diff/file_collection/merge_request_diff_base.rb
lib/gitlab/diff/file_collection/merge_request_diff_base.rb
+17
-7
lib/gitlab/diff/highlight_cache.rb
lib/gitlab/diff/highlight_cache.rb
+12
-2
spec/lib/gitlab/diff/file_collection/merge_request_diff_spec.rb
...ib/gitlab/diff/file_collection/merge_request_diff_spec.rb
+8
-0
No files found.
lib/gitlab/diff/file_collection/merge_request_diff_base.rb
View file @
2c0a664a
...
...
@@ -16,13 +16,13 @@ module Gitlab
fallback_diff_refs:
merge_request_diff
.
fallback_diff_refs
)
end
def
diff_files
strong_memoize
(
:diff_files
)
do
d
iff_files
=
super
diff_files
.
each
{
|
diff_file
|
cache
.
decorate
(
diff_file
)
}
diff_files
def
diff_files
(
decorate_diff_files:
true
)
if
decorate_diff_files
d
ecorated_diff_files
else
strong_memoize
(
:undecorated_diff_files
)
do
super
()
end
end
end
...
...
@@ -46,6 +46,16 @@ module Gitlab
private
def
decorated_diff_files
strong_memoize
(
:diff_files
)
do
diff_files
=
diff_files
(
decorate_diff_files:
false
)
diff_files
.
each
{
|
diff_file
|
cache
.
decorate
(
diff_file
)
}
diff_files
end
end
def
cache
@cache
||=
if
Feature
.
enabled?
(
:hset_redis_diff_caching
,
project
)
Gitlab
::
Diff
::
HighlightCache
.
new
(
self
)
...
...
lib/gitlab/diff/highlight_cache.rb
View file @
2c0a664a
...
...
@@ -68,12 +68,17 @@ module Gitlab
end
end
<<<<<<<
HEAD
def
cacheable_files
strong_memoize
(
:cacheable_files
)
do
diff_files
=
@diff_collection
.
diff_files
diff_files
.
select
{
|
file
|
cacheable?
(
file
)
&&
read_file
(
file
).
nil?
}
end
=======
def
uncached_files
diff_files
.
select
{
|
file
|
read_cache
[
file
.
file_path
].
nil?
}
>>>>>>>
Allow
diff_files
to
return
undecorated
files
end
# Given a hash of:
...
...
@@ -112,10 +117,9 @@ module Gitlab
deprecated_cache
.
clear
end
#
def
file_paths
strong_memoize
(
:file_paths
)
do
@diff_collection
.
diff
s
.
collect
(
&
:file_path
)
diff_file
s
.
collect
(
&
:file_path
)
end
end
...
...
@@ -146,6 +150,12 @@ module Gitlab
def
cacheable?
(
diff_file
)
diffable
.
present?
&&
diff_file
.
text?
&&
diff_file
.
diffable?
end
def
diff_files
strong_memoize
(
:diff_files
)
do
@diff_collection
.
diff_files
(
decorate_diff_files:
true
)
end
end
end
end
end
spec/lib/gitlab/diff/file_collection/merge_request_diff_spec.rb
View file @
2c0a664a
...
...
@@ -9,6 +9,14 @@ describe Gitlab::Diff::FileCollection::MergeRequestDiff do
let
(
:diff_files
)
{
subject
.
diff_files
}
describe
'#diff_files'
do
context
'when decorate_diff_files is false'
do
it
'should not attempt to decorate diff files'
do
expect
(
subject
.
send
(
:cache
)).
not_to
receive
(
:decorate
)
subject
.
diff_files
(
decorate_diff_files:
false
)
end
end
it
'does not highlight binary files'
do
allow_next_instance_of
(
Gitlab
::
Diff
::
File
)
do
|
instance
|
allow
(
instance
).
to
receive
(
:text?
).
and_return
(
false
)
...
...
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