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
a6af5522
Commit
a6af5522
authored
Sep 05, 2017
by
micael.bergeron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
renames ambiguous methods and add spec
parent
dbaed90c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
7 deletions
+15
-7
encoding_helper.rb
lib/gitlab/encoding_helper.rb
+5
-5
blob.rb
lib/gitlab/git/blob.rb
+1
-1
diff.rb
lib/gitlab/git/diff.rb
+3
-1
commits_spec.rb
spec/requests/api/commits_spec.rb
+6
-0
No files found.
lib/gitlab/encoding_helper.rb
View file @
a6af5522
...
@@ -24,7 +24,7 @@ module Gitlab
...
@@ -24,7 +24,7 @@ module Gitlab
# return message if message type is binary
# return message if message type is binary
detect
=
CharlockHolmes
::
EncodingDetector
.
detect
(
message
)
detect
=
CharlockHolmes
::
EncodingDetector
.
detect
(
message
)
return
message
.
force_encoding
(
"BINARY"
)
if
all
_binary?
(
message
,
detect
)
return
message
.
force_encoding
(
"BINARY"
)
if
detect
_binary?
(
message
,
detect
)
if
detect
&&
detect
[
:encoding
]
&&
detect
[
:confidence
]
>
ENCODING_CONFIDENCE_THRESHOLD
if
detect
&&
detect
[
:encoding
]
&&
detect
[
:confidence
]
>
ENCODING_CONFIDENCE_THRESHOLD
# force detected encoding if we have sufficient confidence.
# force detected encoding if we have sufficient confidence.
...
@@ -38,17 +38,17 @@ module Gitlab
...
@@ -38,17 +38,17 @@ module Gitlab
"--broken encoding:
#{
encoding
}
"
"--broken encoding:
#{
encoding
}
"
end
end
def
all
_binary?
(
data
,
detect
=
nil
)
def
detect
_binary?
(
data
,
detect
=
nil
)
detect
||=
CharlockHolmes
::
EncodingDetector
.
detect
(
data
)
detect
||=
CharlockHolmes
::
EncodingDetector
.
detect
(
data
)
detect
&&
detect
[
:type
]
==
:binary
detect
&&
detect
[
:type
]
==
:binary
&&
detect
[
:confidence
]
==
100
end
end
def
libgit2_binary?
(
data
)
def
detect_
libgit2_binary?
(
data
)
# EncodingDetector checks the first 1024 * 1024 bytes for NUL byte, libgit2 checks
# EncodingDetector checks the first 1024 * 1024 bytes for NUL byte, libgit2 checks
# only the first 8000 (https://github.com/libgit2/libgit2/blob/2ed855a9e8f9af211e7274021c2264e600c0f86b/src/filter.h#L15),
# only the first 8000 (https://github.com/libgit2/libgit2/blob/2ed855a9e8f9af211e7274021c2264e600c0f86b/src/filter.h#L15),
# which is what we use below to keep a consistent behavior.
# which is what we use below to keep a consistent behavior.
detect
=
CharlockHolmes
::
EncodingDetector
.
new
(
8000
).
detect
(
data
)
detect
=
CharlockHolmes
::
EncodingDetector
.
new
(
8000
).
detect
(
data
)
all_binary?
(
data
,
detect
)
detect
&&
detect
[
:type
]
==
:binary
end
end
def
encode_utf8
(
message
)
def
encode_utf8
(
message
)
...
...
lib/gitlab/git/blob.rb
View file @
a6af5522
...
@@ -58,7 +58,7 @@ module Gitlab
...
@@ -58,7 +58,7 @@ module Gitlab
end
end
def
binary?
(
data
)
def
binary?
(
data
)
EncodingHelper
.
libgit2_binary?
(
data
)
EncodingHelper
.
detect_
libgit2_binary?
(
data
)
end
end
private
private
...
...
lib/gitlab/git/diff.rb
View file @
a6af5522
...
@@ -120,6 +120,8 @@ module Gitlab
...
@@ -120,6 +120,8 @@ module Gitlab
# Return a binary diff message like:
# Return a binary diff message like:
#
#
# "Binary files a/file/path and b/file/path differ\n"
# "Binary files a/file/path and b/file/path differ\n"
# This is used when we detect that a diff is binary
# using CharlockHolmes when Rugged treats it as text.
def
binary_message
(
old_path
,
new_path
)
def
binary_message
(
old_path
,
new_path
)
"Binary files
#{
old_path
}
and
#{
new_path
}
differ
\n
"
"Binary files
#{
old_path
}
and
#{
new_path
}
differ
\n
"
end
end
...
@@ -198,7 +200,7 @@ module Gitlab
...
@@ -198,7 +200,7 @@ module Gitlab
end
end
def
json_safe_diff
def
json_safe_diff
return
@diff
unless
all
_binary?
(
@diff
)
return
@diff
unless
detect
_binary?
(
@diff
)
# the diff is binary, let's make a message for it
# the diff is binary, let's make a message for it
Diff
.
binary_message
(
@old_path
,
@new_path
)
Diff
.
binary_message
(
@old_path
,
@new_path
)
...
...
spec/requests/api/commits_spec.rb
View file @
a6af5522
...
@@ -673,6 +673,12 @@ describe API::Commits do
...
@@ -673,6 +673,12 @@ describe API::Commits do
it_behaves_like
'ref diff'
it_behaves_like
'ref diff'
end
end
end
end
context
'when binary diff are treated as text'
do
let
(
:commit_id
)
{
TestEnv
::
BRANCH_SHA
[
'add-pdf-text-binary'
]
}
it_behaves_like
'ref diff'
end
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