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
Jérome Perrin
gitlab-ce
Commits
c9aa7932
Commit
c9aa7932
authored
Sep 04, 2017
by
micael.bergeron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
revert to using a simple representation
parent
bca72f59
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
22 deletions
+25
-22
lib/api/entities.rb
lib/api/entities.rb
+1
-1
lib/gitlab/encoding_helper.rb
lib/gitlab/encoding_helper.rb
+12
-5
lib/gitlab/git/blob.rb
lib/gitlab/git/blob.rb
+4
-8
lib/gitlab/git/diff.rb
lib/gitlab/git/diff.rb
+8
-8
No files found.
lib/api/entities.rb
View file @
c9aa7932
...
...
@@ -295,7 +295,7 @@ module API
expose
:new_file?
,
as: :new_file
expose
:renamed_file?
,
as: :renamed_file
expose
:deleted_file?
,
as: :deleted_file
expose
:diff
expose
:
json_safe_diff
,
as: :
diff
end
class
ProtectedRefAccess
<
Grape
::
Entity
...
...
lib/gitlab/encoding_helper.rb
View file @
c9aa7932
...
...
@@ -24,7 +24,7 @@ module Gitlab
# return message if message type is binary
detect
=
CharlockHolmes
::
EncodingDetector
.
detect
(
message
)
return
message
.
force_encoding
(
"BINARY"
)
if
binary?
(
message
,
detect
)
return
message
.
force_encoding
(
"BINARY"
)
if
all_
binary?
(
message
,
detect
)
if
detect
&&
detect
[
:encoding
]
&&
detect
[
:confidence
]
>
ENCODING_CONFIDENCE_THRESHOLD
# force detected encoding if we have sufficient confidence.
...
...
@@ -34,14 +34,21 @@ module Gitlab
# encode and clean the bad chars
message
.
replace
clean
(
message
)
rescue
=>
e
byebug
encoding
=
detect
?
detect
[
:encoding
]
:
"unknown"
"--broken encoding:
#{
encoding
}
"
end
def
binary?
(
message
,
detect
=
nil
)
detect
||=
CharlockHolmes
::
EncodingDetector
.
detect
(
message
)
detect
&&
detect
[
:type
]
==
:binary
&&
detect
[
:confidence
]
==
100
def
all_binary?
(
data
,
detect
=
nil
)
detect
||=
CharlockHolmes
::
EncodingDetector
.
detect
(
data
)
detect
&&
detect
[
:type
]
==
:binary
end
def
libgit2_binary?
(
data
)
# 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),
# which is what we use below to keep a consistent behavior.
detect
=
CharlockHolmes
::
EncodingDetector
.
new
(
8000
).
detect
(
data
)
all_binary?
(
data
,
detect
)
end
def
encode_utf8
(
message
)
...
...
lib/gitlab/git/blob.rb
View file @
c9aa7932
...
...
@@ -42,14 +42,6 @@ module Gitlab
end
end
def
binary?
(
data
)
# 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),
# which is what we use below to keep a consistent behavior.
detect
=
CharlockHolmes
::
EncodingDetector
.
new
(
8000
).
detect
(
data
)
detect
&&
detect
[
:type
]
==
:binary
end
# Returns an array of Blob instances, specified in blob_references as
# [[commit_sha, path], [commit_sha, path], ...]. If blob_size_limit < 0 then the
# full blob contents are returned. If blob_size_limit >= 0 then each blob will
...
...
@@ -169,6 +161,10 @@ module Gitlab
end
end
end
def
binary?
(
data
)
EncodingHelper
.
libgit2_binary?
(
data
)
end
end
def
initialize
(
options
)
...
...
lib/gitlab/git/diff.rb
View file @
c9aa7932
...
...
@@ -197,6 +197,13 @@ module Gitlab
@collapsed
=
true
end
def
json_safe_diff
return
@diff
unless
all_binary?
(
@diff
)
# the diff is binary, let's make a message for it
Diff
::
binary_message
(
@old_path
,
@new_path
)
end
private
def
init_from_rugged
(
rugged
)
...
...
@@ -221,14 +228,7 @@ module Gitlab
# binary we're not going to display anything so we skip the size check.
return
if
!
patch
.
delta
.
binary?
&&
prune_large_patch
(
patch
)
diff
=
strip_diff_headers
(
patch
.
to_s
)
@diff
=
if
binary?
(
diff
)
# the diff is binary, let's make a message for it
Diff
::
binary_message
(
patch
.
delta
.
old_file
[
:path
],
patch
.
delta
.
new_file
[
:path
])
else
encode!
(
diff
)
end
@diff
=
encode!
(
strip_diff_headers
(
patch
.
to_s
))
end
def
init_from_hash
(
hash
)
...
...
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