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
iv
gitlab-ce
Commits
ad99404d
Commit
ad99404d
authored
Apr 14, 2016
by
Zeger-Jan van de Weg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Properly handle bigger files
parent
3fd0f537
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
44 additions
and
16 deletions
+44
-16
CHANGELOG
CHANGELOG
+1
-0
app/helpers/blob_helper.rb
app/helpers/blob_helper.rb
+2
-2
app/models/blob.rb
app/models/blob.rb
+8
-0
app/models/snippet.rb
app/models/snippet.rb
+4
-0
app/views/projects/blob/_text.html.haml
app/views/projects/blob/_text.html.haml
+17
-8
app/views/shared/_file_highlight.html.haml
app/views/shared/_file_highlight.html.haml
+3
-2
lib/gitlab/highlight.rb
lib/gitlab/highlight.rb
+9
-4
No files found.
CHANGELOG
View file @
ad99404d
...
@@ -11,6 +11,7 @@ v 8.8.0 (unreleased)
...
@@ -11,6 +11,7 @@ v 8.8.0 (unreleased)
- Allow "NEWS" and "CHANGES" as alternative names for CHANGELOG. !3768 (Connor Shea)
- Allow "NEWS" and "CHANGES" as alternative names for CHANGELOG. !3768 (Connor Shea)
- Added button to toggle whitespaces changes on diff view
- Added button to toggle whitespaces changes on diff view
- Backport GitLab Enterprise support from EE
- Backport GitLab Enterprise support from EE
- Files over 5MB can only be viewed in their raw form, files over 1MB without highlighting !3718
v 8.7.1 (unreleased)
v 8.7.1 (unreleased)
- Throttle the update of `project.last_activity_at` to 1 minute. !3848
- Throttle the update of `project.last_activity_at` to 1 minute. !3848
...
...
app/helpers/blob_helper.rb
View file @
ad99404d
...
@@ -3,8 +3,8 @@ module BlobHelper
...
@@ -3,8 +3,8 @@ module BlobHelper
Gitlab
::
Highlight
.
new
(
blob_name
,
blob_content
,
nowrap:
nowrap
)
Gitlab
::
Highlight
.
new
(
blob_name
,
blob_content
,
nowrap:
nowrap
)
end
end
def
highlight
(
blob_name
,
blob_content
,
nowrap:
false
)
def
highlight
(
blob_name
,
blob_content
,
nowrap:
false
,
plain:
false
)
Gitlab
::
Highlight
.
highlight
(
blob_name
,
blob_content
,
nowrap:
nowrap
)
Gitlab
::
Highlight
.
highlight
(
blob_name
,
blob_content
,
nowrap:
nowrap
,
plain:
plain
)
end
end
def
no_highlight_files
def
no_highlight_files
...
...
app/models/blob.rb
View file @
ad99404d
...
@@ -19,6 +19,14 @@ class Blob < SimpleDelegator
...
@@ -19,6 +19,14 @@ class Blob < SimpleDelegator
new
(
blob
)
new
(
blob
)
end
end
def
no_highlighting?
size
&&
size
>
1
.
megabyte
end
def
only_display_raw?
size
&&
size
>
5
.
megabytes
end
def
svg?
def
svg?
text?
&&
language
&&
language
.
name
==
'SVG'
text?
&&
language
&&
language
.
name
==
'SVG'
end
end
...
...
app/models/snippet.rb
View file @
ad99404d
...
@@ -112,6 +112,10 @@ class Snippet < ActiveRecord::Base
...
@@ -112,6 +112,10 @@ class Snippet < ActiveRecord::Base
visibility_level
visibility_level
end
end
def
no_highlighting?
content
.
lines
.
count
>
1000
end
class
<<
self
class
<<
self
# Searches for snippets with a matching title or file name.
# Searches for snippets with a matching title or file name.
#
#
...
...
app/views/projects/blob/_text.html.haml
View file @
ad99404d
-
blob
.
load_all_data!
(
@repository
)
-
if
blob
.
only_display_raw?
-
if
markup?
(
blob
.
name
)
.file-content.code
.file-content.wiki
.nothing-here-block
=
render_markup
(
blob
.
name
,
blob
.
data
)
File too large, you can
=
succeed
'.'
do
=
link_to
'view the raw file'
,
namespace_project_raw_path
(
@project
.
namespace
,
@project
,
@id
),
target:
'_blank'
-
else
-
else
-
unless
blob
.
empty?
-
blob
.
load_all_data!
(
@repository
)
=
render
'shared/file_highlight'
,
blob:
blob
-
if
markup?
(
blob
.
name
)
.file-content.wiki
=
render_markup
(
blob
.
name
,
blob
.
data
)
-
else
-
else
.file-content.code
-
if
blob
.
empty?
.nothing-here-block
Empty file
.file-content.code
.nothing-here-block
Empty file
-
else
=
render
'shared/file_highlight'
,
blob:
blob
app/views/shared/_file_highlight.html.haml
View file @
ad99404d
.file-content.code.js-syntax-highlight
.file-content.code.js-syntax-highlight
.line-numbers
.line-numbers
-
if
blob
.
data
.
present?
-
if
blob
.
data
.
present?
-
link_icon
=
icon
(
'link'
)
-
blob
.
data
.
each_line
.
each_with_index
do
|
_
,
index
|
-
blob
.
data
.
each_line
.
each_with_index
do
|
_
,
index
|
-
offset
=
defined?
(
first_line_number
)
?
first_line_number
:
1
-
offset
=
defined?
(
first_line_number
)
?
first_line_number
:
1
-
i
=
index
+
offset
-
i
=
index
+
offset
-# We're not using `link_to` because it is too slow once we get to thousands of lines.
-# We're not using `link_to` because it is too slow once we get to thousands of lines.
%a
.diff-line-num
{
href:
"#L#{i}"
,
id:
"L#{i}"
,
'data-line-number'
=>
i
}
%a
.diff-line-num
{
href:
"#L#{i}"
,
id:
"L#{i}"
,
'data-line-number'
=>
i
}
%i
.fa.fa-link
=
link_icon
=
i
=
i
.blob-content
{
data:
{
blob_id:
blob
.
id
}}
.blob-content
{
data:
{
blob_id:
blob
.
id
}}
=
highlight
(
blob
.
name
,
blob
.
data
)
=
highlight
(
blob
.
name
,
blob
.
data
,
plain:
blob
.
no_highlighting?
)
lib/gitlab/highlight.rb
View file @
ad99404d
module
Gitlab
module
Gitlab
class
Highlight
class
Highlight
def
self
.
highlight
(
blob_name
,
blob_content
,
nowrap:
true
)
def
self
.
highlight
(
blob_name
,
blob_content
,
nowrap:
true
,
plain:
false
)
new
(
blob_name
,
blob_content
,
nowrap:
nowrap
).
highlight
(
blob_content
,
continue:
false
)
new
(
blob_name
,
blob_content
,
nowrap:
nowrap
).
highlight
(
blob_content
,
continue:
false
,
plain:
plain
)
end
end
def
self
.
highlight_lines
(
repository
,
ref
,
file_name
)
def
self
.
highlight_lines
(
repository
,
ref
,
file_name
)
...
@@ -17,8 +18,12 @@ module Gitlab
...
@@ -17,8 +18,12 @@ module Gitlab
@lexer
=
Rouge
::
Lexer
.
guess
(
filename:
blob_name
,
source:
blob_content
).
new
rescue
Rouge
::
Lexers
::
PlainText
@lexer
=
Rouge
::
Lexer
.
guess
(
filename:
blob_name
,
source:
blob_content
).
new
rescue
Rouge
::
Lexers
::
PlainText
end
end
def
highlight
(
text
,
continue:
true
)
def
highlight
(
text
,
continue:
true
,
plain:
false
)
@formatter
.
format
(
@lexer
.
lex
(
text
,
continue:
continue
)).
html_safe
if
plain
@formatter
.
format
(
Rouge
::
Lexers
::
PlainText
.
lex
(
text
)).
html_safe
else
@formatter
.
format
(
@lexer
.
lex
(
text
,
continue:
continue
)).
html_safe
end
rescue
rescue
@formatter
.
format
(
Rouge
::
Lexers
::
PlainText
.
lex
(
text
)).
html_safe
@formatter
.
format
(
Rouge
::
Lexers
::
PlainText
.
lex
(
text
)).
html_safe
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