BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
e9002222
Commit
e9002222
authored
Jun 08, 2017
by
Sean McGivern
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dm-diff-file-diffable' into 'master'
Move diffable? method from Repository to Diff::File See merge request !11980
parents
9ea883fb
ffbbd411
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
43 additions
and
66 deletions
+43
-66
_content.html.haml
app/views/projects/diffs/_content.html.haml
+1
-1
file.rb
lib/gitlab/diff/file.rb
+12
-0
merge_request_diff.rb
lib/gitlab/diff/file_collection/merge_request_diff.rb
+1
-4
repository.rb
lib/gitlab/git/repository.rb
+0
-5
merge_request_diff_spec.rb
...ib/gitlab/diff/file_collection/merge_request_diff_spec.rb
+2
-10
file_spec.rb
spec/lib/gitlab/diff/file_spec.rb
+25
-3
repository_spec.rb
spec/lib/gitlab/git/repository_spec.rb
+0
-41
merge_request_diff_cache_service_spec.rb
...s/merge_requests/merge_request_diff_cache_service_spec.rb
+2
-2
No files found.
app/views/projects/diffs/_content.html.haml
View file @
e9002222
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
-
elsif
blob
.
truncated?
-
elsif
blob
.
truncated?
.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
.
diffable?
.nothing-here-block
This diff was suppressed by a .gitattributes entry.
.nothing-here-block
This diff was suppressed by a .gitattributes entry.
-
elsif
diff_file
.
collapsed?
-
elsif
diff_file
.
collapsed?
-
url
=
url_for
(
params
.
merge
(
action: :diff_for_path
,
old_path:
diff_file
.
old_path
,
new_path:
diff_file
.
new_path
,
file_identifier:
diff_file
.
file_identifier
))
-
url
=
url_for
(
params
.
merge
(
action: :diff_for_path
,
old_path:
diff_file
.
old_path
,
new_path:
diff_file
.
new_path
,
file_identifier:
diff_file
.
file_identifier
))
...
...
lib/gitlab/diff/file.rb
View file @
e9002222
...
@@ -165,6 +165,18 @@ module Gitlab
...
@@ -165,6 +165,18 @@ module Gitlab
def
file_identifier
def
file_identifier
"
#{
file_path
}
-
#{
new_file?
}
-
#{
deleted_file?
}
-
#{
renamed_file?
}
"
"
#{
file_path
}
-
#{
new_file?
}
-
#{
deleted_file?
}
-
#{
renamed_file?
}
"
end
end
def
diffable?
repository
.
attributes
(
file_path
).
fetch
(
'diff'
)
{
true
}
end
def
binary?
old_blob
&
.
binary?
||
new_blob
&
.
binary?
end
def
text?
!
binary?
end
end
end
end
end
end
end
lib/gitlab/diff/file_collection/merge_request_diff.rb
View file @
e9002222
...
@@ -66,10 +66,7 @@ module Gitlab
...
@@ -66,10 +66,7 @@ module Gitlab
end
end
def
cacheable?
(
diff_file
)
def
cacheable?
(
diff_file
)
@merge_request_diff
.
present?
&&
@merge_request_diff
.
present?
&&
diff_file
.
text?
&&
diff_file
.
diffable?
diff_file
.
blob
&&
diff_file
.
blob
.
text?
&&
@project
.
repository
.
diffable?
(
diff_file
.
blob
)
end
end
def
cache_key
def
cache_key
...
...
lib/gitlab/git/repository.rb
View file @
e9002222
...
@@ -962,11 +962,6 @@ module Gitlab
...
@@ -962,11 +962,6 @@ module Gitlab
end
end
end
end
# Checks if the blob should be diffable according to its attributes
def
diffable?
(
blob
)
attributes
(
blob
.
path
).
fetch
(
'diff'
)
{
blob
.
text?
}
end
# Returns the Git attributes for the given file path.
# Returns the Git attributes for the given file path.
#
#
# See `Gitlab::Git::Attributes` for more information.
# See `Gitlab::Git::Attributes` for more information.
...
...
spec/lib/gitlab/diff/file_collection/merge_request_diff_spec.rb
View file @
e9002222
...
@@ -5,15 +5,7 @@ describe Gitlab::Diff::FileCollection::MergeRequestDiff do
...
@@ -5,15 +5,7 @@ describe Gitlab::Diff::FileCollection::MergeRequestDiff do
let
(
:diff_files
)
{
described_class
.
new
(
merge_request
.
merge_request_diff
,
diff_options:
nil
).
diff_files
}
let
(
:diff_files
)
{
described_class
.
new
(
merge_request
.
merge_request_diff
,
diff_options:
nil
).
diff_files
}
it
'does not highlight binary files'
do
it
'does not highlight binary files'
do
allow_any_instance_of
(
Gitlab
::
Diff
::
File
).
to
receive
(
:blob
).
and_return
(
double
(
"text?"
=>
false
))
allow_any_instance_of
(
Gitlab
::
Diff
::
File
).
to
receive
(
:text?
).
and_return
(
false
)
expect_any_instance_of
(
Gitlab
::
Diff
::
File
).
not_to
receive
(
:highlighted_diff_lines
)
diff_files
end
it
'does not highlight file if blob is not accessable'
do
allow_any_instance_of
(
Gitlab
::
Diff
::
File
).
to
receive
(
:blob
).
and_return
(
nil
)
expect_any_instance_of
(
Gitlab
::
Diff
::
File
).
not_to
receive
(
:highlighted_diff_lines
)
expect_any_instance_of
(
Gitlab
::
Diff
::
File
).
not_to
receive
(
:highlighted_diff_lines
)
...
@@ -21,7 +13,7 @@ describe Gitlab::Diff::FileCollection::MergeRequestDiff do
...
@@ -21,7 +13,7 @@ describe Gitlab::Diff::FileCollection::MergeRequestDiff do
end
end
it
'does not files marked as undiffable in .gitattributes'
do
it
'does not files marked as undiffable in .gitattributes'
do
allow_any_instance_of
(
Repository
).
to
receive
(
:diffable?
).
and_return
(
false
)
allow_any_instance_of
(
Gitlab
::
Diff
::
File
).
to
receive
(
:diffable?
).
and_return
(
false
)
expect_any_instance_of
(
Gitlab
::
Diff
::
File
).
not_to
receive
(
:highlighted_diff_lines
)
expect_any_instance_of
(
Gitlab
::
Diff
::
File
).
not_to
receive
(
:highlighted_diff_lines
)
...
...
spec/lib/gitlab/diff/file_spec.rb
View file @
e9002222
...
@@ -6,7 +6,7 @@ describe Gitlab::Diff::File, lib: true do
...
@@ -6,7 +6,7 @@ describe Gitlab::Diff::File, lib: true do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:commit
)
{
project
.
commit
(
sample_commit
.
id
)
}
let
(
:commit
)
{
project
.
commit
(
sample_commit
.
id
)
}
let
(
:diff
)
{
commit
.
raw_diffs
.
first
}
let
(
:diff
)
{
commit
.
raw_diffs
.
first
}
let
(
:diff_file
)
{
Gitlab
::
Diff
::
File
.
new
(
diff
,
diff_refs:
commit
.
diff_refs
,
repository:
project
.
repository
)
}
let
(
:diff_file
)
{
described_class
.
new
(
diff
,
diff_refs:
commit
.
diff_refs
,
repository:
project
.
repository
)
}
describe
'#diff_lines'
do
describe
'#diff_lines'
do
let
(
:diff_lines
)
{
diff_file
.
diff_lines
}
let
(
:diff_lines
)
{
diff_file
.
diff_lines
}
...
@@ -63,11 +63,33 @@ describe Gitlab::Diff::File, lib: true do
...
@@ -63,11 +63,33 @@ describe Gitlab::Diff::File, lib: true do
end
end
end
end
describe
'#blob'
do
describe
'#
new_
blob'
do
it
'returns blob of new commit'
do
it
'returns blob of new commit'
do
data
=
diff_file
.
blob
.
data
data
=
diff_file
.
new_
blob
.
data
expect
(
data
).
to
include
(
'raise RuntimeError, "System commands must be given as an array of strings"'
)
expect
(
data
).
to
include
(
'raise RuntimeError, "System commands must be given as an array of strings"'
)
end
end
end
end
describe
'#diffable?'
do
let
(
:commit
)
{
project
.
commit
(
'1a0b36b3cdad1d2ee32457c102a8c0b7056fa863'
)
}
let
(
:diffs
)
{
commit
.
diffs
}
before
do
info_dir_path
=
File
.
join
(
project
.
repository
.
path_to_repo
,
'info'
)
FileUtils
.
mkdir
(
info_dir_path
)
unless
File
.
exist?
(
info_dir_path
)
File
.
write
(
File
.
join
(
info_dir_path
,
'attributes'
),
"*.md -diff
\n
"
)
end
it
"returns true for files that do not have attributes"
do
diff_file
=
diffs
.
diff_file_with_new_path
(
'LICENSE'
)
expect
(
diff_file
.
diffable?
).
to
be_truthy
end
it
"returns false for files that have been marked as not being diffable in attributes"
do
diff_file
=
diffs
.
diff_file_with_new_path
(
'README.md'
)
expect
(
diff_file
.
diffable?
).
to
be_falsey
end
end
end
end
spec/lib/gitlab/git/repository_spec.rb
View file @
e9002222
...
@@ -1235,47 +1235,6 @@ describe Gitlab::Git::Repository, seed_helper: true do
...
@@ -1235,47 +1235,6 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
end
end
end
describe
'#diffable'
do
info_dir_path
=
attributes_path
=
File
.
join
(
SEED_STORAGE_PATH
,
TEST_REPO_PATH
,
'info'
)
attributes_path
=
File
.
join
(
info_dir_path
,
'attributes'
)
before
(
:all
)
do
FileUtils
.
mkdir
(
info_dir_path
)
unless
File
.
exist?
(
info_dir_path
)
File
.
write
(
attributes_path
,
"*.md -diff
\n
"
)
end
it
"should return true for files which are text and do not have attributes"
do
blob
=
Gitlab
::
Git
::
Blob
.
find
(
repository
,
'33bcff41c232a11727ac6d660bd4b0c2ba86d63d'
,
'LICENSE'
)
expect
(
repository
.
diffable?
(
blob
)).
to
be_truthy
end
it
"should return false for binary files which do not have attributes"
do
blob
=
Gitlab
::
Git
::
Blob
.
find
(
repository
,
'33bcff41c232a11727ac6d660bd4b0c2ba86d63d'
,
'files/images/logo-white.png'
)
expect
(
repository
.
diffable?
(
blob
)).
to
be_falsey
end
it
"should return false for text files which have been marked as not being diffable in attributes"
do
blob
=
Gitlab
::
Git
::
Blob
.
find
(
repository
,
'33bcff41c232a11727ac6d660bd4b0c2ba86d63d'
,
'README.md'
)
expect
(
repository
.
diffable?
(
blob
)).
to
be_falsey
end
after
(
:all
)
do
FileUtils
.
rm_rf
(
info_dir_path
)
end
end
describe
'#tag_exists?'
do
describe
'#tag_exists?'
do
it
'returns true for an existing tag'
do
it
'returns true for an existing tag'
do
tag
=
repository
.
tag_names
.
first
tag
=
repository
.
tag_names
.
first
...
...
spec/services/merge_requests/merge_request_diff_cache_service_spec.rb
View file @
e9002222
...
@@ -10,8 +10,8 @@ describe MergeRequests::MergeRequestDiffCacheService do
...
@@ -10,8 +10,8 @@ describe MergeRequests::MergeRequestDiffCacheService do
expect
(
Rails
.
cache
).
to
receive
(
:read
).
with
(
cache_key
).
and_return
({})
expect
(
Rails
.
cache
).
to
receive
(
:read
).
with
(
cache_key
).
and_return
({})
expect
(
Rails
.
cache
).
to
receive
(
:write
).
with
(
cache_key
,
anything
)
expect
(
Rails
.
cache
).
to
receive
(
:write
).
with
(
cache_key
,
anything
)
allow_any_instance_of
(
Gitlab
::
Diff
::
File
).
to
receive
(
:
blob
).
and_return
(
double
(
"text?"
=>
true
)
)
allow_any_instance_of
(
Gitlab
::
Diff
::
File
).
to
receive
(
:
text?
).
and_return
(
true
)
allow_any_instance_of
(
Repository
).
to
receive
(
:diffable?
).
and_return
(
true
)
allow_any_instance_of
(
Gitlab
::
Diff
::
File
).
to
receive
(
:diffable?
).
and_return
(
true
)
subject
.
execute
(
merge_request
)
subject
.
execute
(
merge_request
)
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