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
bca72f59
Commit
bca72f59
authored
Sep 03, 2017
by
micael.bergeron
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip: fake its a binary diff
parent
b97f9629
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
7 deletions
+30
-7
commits.rb
lib/api/commits.rb
+1
-1
entities.rb
lib/api/entities.rb
+2
-1
encoding_helper.rb
lib/gitlab/encoding_helper.rb
+12
-4
diff.rb
lib/gitlab/git/diff.rb
+15
-1
No files found.
lib/api/commits.rb
View file @
bca72f59
...
...
@@ -104,7 +104,7 @@ module API
not_found!
'Commit'
unless
commit
commit
.
raw_diffs
.
to_a
present
commit
.
raw_diffs
.
to_a
,
with:
Entities
::
RepoDiff
end
desc
"Get a commit's comments"
do
...
...
lib/api/entities.rb
View file @
bca72f59
...
...
@@ -291,10 +291,11 @@ module API
end
class
RepoDiff
<
Grape
::
Entity
expose
:old_path
,
:new_path
,
:a_mode
,
:b_mode
,
:diff
expose
:old_path
,
:new_path
,
:a_mode
,
:b_mode
expose
:new_file?
,
as: :new_file
expose
:renamed_file?
,
as: :renamed_file
expose
:deleted_file?
,
as: :deleted_file
expose
:diff
end
class
ProtectedRefAccess
<
Grape
::
Entity
...
...
lib/gitlab/encoding_helper.rb
View file @
bca72f59
...
...
@@ -13,6 +13,8 @@ module Gitlab
# https://gitlab.com/gitlab-org/gitlab_git/merge_requests/77#note_4754193
ENCODING_CONFIDENCE_THRESHOLD
=
50
#
#
def
encode!
(
message
)
return
nil
unless
message
.
respond_to?
:force_encoding
...
...
@@ -22,20 +24,26 @@ module Gitlab
# return message if message type is binary
detect
=
CharlockHolmes
::
EncodingDetector
.
detect
(
message
)
return
message
.
force_encoding
(
"BINARY"
)
if
detect
&&
detect
[
:type
]
==
:binary
return
message
.
force_encoding
(
"BINARY"
)
if
binary?
(
message
,
detect
)
# force detected encoding if we have sufficient confidence.
if
detect
&&
detect
[
:encoding
]
&&
detect
[
:confidence
]
>
ENCODING_CONFIDENCE_THRESHOLD
# force detected encoding if we have sufficient confidence.
message
.
force_encoding
(
detect
[
:encoding
])
end
# encode and clean the bad chars
message
.
replace
clean
(
message
)
rescue
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
end
def
encode_utf8
(
message
)
detect
=
CharlockHolmes
::
EncodingDetector
.
detect
(
message
)
if
detect
&&
detect
[
:encoding
]
...
...
@@ -50,7 +58,7 @@ module Gitlab
clean
(
message
)
end
end
private
def
clean
(
message
)
...
...
lib/gitlab/git/diff.rb
View file @
bca72f59
...
...
@@ -116,6 +116,13 @@ module Gitlab
filtered_opts
end
# Return a binary diff message like:
#
# "Binary files a/file/path and b/file/path differ\n"
def
binary_message
(
old_path
,
new_path
)
"Binary files
#{
old_path
}
and
#{
new_path
}
differ
\n
"
end
end
def
initialize
(
raw_diff
,
expanded:
true
)
...
...
@@ -214,7 +221,14 @@ 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
=
encode!
(
strip_diff_headers
(
patch
.
to_s
))
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
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