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
2cf80107
Commit
2cf80107
authored
May 30, 2012
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #868 from SaitoWu/bugfix/encoding
Bugfix/encoding
parents
af226ae9
e851cb07
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
38 additions
and
29 deletions
+38
-29
app/helpers/commits_helper.rb
app/helpers/commits_helper.rb
+2
-2
app/views/refs/_tree.html.haml
app/views/refs/_tree.html.haml
+2
-2
app/views/refs/_tree_file.html.haml
app/views/refs/_tree_file.html.haml
+1
-1
config/initializers/gitlabhq/20_grit_ext.rb
config/initializers/gitlabhq/20_grit_ext.rb
+12
-11
lib/gitlab/encode.rb
lib/gitlab/encode.rb
+19
-11
lib/graph_commit.rb
lib/graph_commit.rb
+2
-2
No files found.
app/helpers/commits_helper.rb
View file @
2cf80107
...
@@ -58,7 +58,7 @@ module CommitsHelper
...
@@ -58,7 +58,7 @@ module CommitsHelper
next
if
line
.
match
(
/^\-\-\- a/
)
next
if
line
.
match
(
/^\-\-\- a/
)
next
if
line
.
match
(
/^\+\+\+ b/
)
next
if
line
.
match
(
/^\+\+\+ b/
)
full_line
=
html_escape
(
line
.
gsub
(
/\n/
,
''
))
.
force_encoding
(
"UTF-8"
)
full_line
=
html_escape
(
line
.
gsub
(
/\n/
,
''
))
if
line
.
match
(
/^@@ -/
)
if
line
.
match
(
/^@@ -/
)
type
=
"match"
type
=
"match"
...
...
app/views/refs/_tree.html.haml
View file @
2cf80107
...
@@ -42,9 +42,9 @@
...
@@ -42,9 +42,9 @@
.readme
.readme
-
if
content
.
name
=~
/\.(md|markdown)$/i
-
if
content
.
name
=~
/\.(md|markdown)$/i
=
preserve
do
=
preserve
do
=
markdown
(
content
.
data
.
detect_encoding!
)
=
markdown
(
content
.
data
)
-
else
-
else
=
simple_format
(
content
.
data
.
detect_encoding!
)
=
simple_format
(
content
.
data
)
-
if
params
[
:path
]
-
if
params
[
:path
]
-
history_path
=
tree_file_project_ref_path
(
@project
,
@ref
,
params
[
:path
])
-
history_path
=
tree_file_project_ref_path
(
@project
,
@ref
,
params
[
:path
])
...
...
app/views/refs/_tree_file.html.haml
View file @
2cf80107
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
#tree-readme-holder
#tree-readme-holder
.readme
.readme
=
preserve
do
=
preserve
do
=
markdown
(
file
.
data
.
detect_encoding!
)
=
markdown
(
file
.
data
)
-
else
-
else
.view_file_content
.view_file_content
-
unless
file
.
empty?
-
unless
file
.
empty?
...
...
config/initializers/gitlabhq/20_grit_ext.rb
View file @
2cf80107
require
'grit'
require
'grit'
require
'pygments'
require
'pygments'
Grit
::
Git
.
git_timeout
=
GIT_OPTS
[
"git_timeout"
]
Grit
::
Git
.
git_max_size
=
GIT_OPTS
[
"git_max_size"
]
Grit
::
Blob
.
class_eval
do
Grit
::
Blob
.
class_eval
do
include
Linguist
::
BlobHelper
include
Linguist
::
BlobHelper
end
#monkey patch raw_object from string
def
data
Grit
::
GitRuby
::
Internal
::
RawObject
.
class_eval
do
@data
||=
@repo
.
git
.
cat_file
({
:p
=>
true
},
id
)
def
content
Gitlab
::
Encode
.
utf8
@data
@content
end
end
end
end
Grit
::
Diff
.
class_eval
do
Grit
::
Diff
.
class_eval
do
def
old_path
def
old_path
Gitlab
::
Encode
.
utf8
a_path
Gitlab
::
Encode
.
utf8
@
a_path
end
end
def
new_path
def
new_path
Gitlab
::
Encode
.
utf8
b_path
Gitlab
::
Encode
.
utf8
@
b_path
end
end
end
Grit
::
Git
.
git_timeout
=
GIT_OPTS
[
"git_timeout"
]
def
diff
Grit
::
Git
.
git_max_size
=
GIT_OPTS
[
"git_max_size"
]
Gitlab
::
Encode
.
utf8
@diff
end
end
lib/gitlab/encode.rb
View file @
2cf80107
...
@@ -5,21 +5,29 @@ module Gitlab
...
@@ -5,21 +5,29 @@ module Gitlab
extend
self
extend
self
def
utf8
message
def
utf8
message
# return nil if message is nil
return
nil
unless
message
return
nil
unless
message
detect
=
CharlockHolmes
::
EncodingDetector
.
detect
(
message
)
rescue
{}
message
.
force_encoding
(
"utf-8"
)
# return message if message type is binary
detect
=
CharlockHolmes
::
EncodingDetector
.
detect
(
message
)
return
message
if
detect
[
:type
]
==
:binary
# It's better to default to UTF-8 as sometimes it's wrongly detected as another charset
# if message is utf-8 encoding, just return it
if
detect
[
:encoding
]
&&
detect
[
:confidence
]
==
100
return
message
if
message
.
valid_encoding?
CharlockHolmes
::
Converter
.
convert
(
message
,
detect
[
:encoding
],
'UTF-8'
)
else
message
end
.
force_encoding
(
"utf-8"
)
# Prevent app from crash cause of
# if message is not utf-8 encoding, convert it
# encoding errors
if
detect
[
:encoding
]
message
.
force_encoding
(
detect
[
:encoding
])
message
.
encode!
(
"utf-8"
,
detect
[
:encoding
],
:undef
=>
:replace
,
:replace
=>
""
,
:invalid
=>
:replace
)
end
# ensure message encoding is utf8
message
.
valid_encoding?
?
message
:
raise
# Prevent app from crash cause of encoding errors
rescue
rescue
"--broken encoding:
#{
encoding
}
"
"--broken encoding:
#{
detect
[
:encoding
]
}
"
end
end
def
detect_encoding
message
def
detect_encoding
message
...
...
lib/graph_commit.rb
View file @
2cf80107
...
@@ -96,13 +96,13 @@ class GraphCommit
...
@@ -96,13 +96,13 @@ class GraphCommit
h
[
:parents
]
=
self
.
parents
.
collect
do
|
p
|
h
[
:parents
]
=
self
.
parents
.
collect
do
|
p
|
[
p
.
id
,
0
,
0
]
[
p
.
id
,
0
,
0
]
end
end
h
[
:author
]
=
author
.
name
.
force_encoding
(
"UTF-8"
)
h
[
:author
]
=
Gitlab
::
Encode
.
utf8
(
author
.
name
)
h
[
:time
]
=
time
h
[
:time
]
=
time
h
[
:space
]
=
space
h
[
:space
]
=
space
h
[
:refs
]
=
refs
.
collect
{
|
r
|
r
.
name
}.
join
(
" "
)
unless
refs
.
nil?
h
[
:refs
]
=
refs
.
collect
{
|
r
|
r
.
name
}.
join
(
" "
)
unless
refs
.
nil?
h
[
:id
]
=
sha
h
[
:id
]
=
sha
h
[
:date
]
=
date
h
[
:date
]
=
date
h
[
:message
]
=
message
.
force_encoding
(
"UTF-8"
)
h
[
:message
]
=
Gitlab
::
Encode
.
utf8
(
message
)
h
[
:login
]
=
author
.
email
h
[
:login
]
=
author
.
email
h
h
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