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
b73b1679
Commit
b73b1679
authored
Apr 24, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small code tweaks
parent
0b3ff9c8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
16 deletions
+18
-16
blob.rb
app/models/blob.rb
+18
-12
blob.rb
lib/gitlab/git/blob.rb
+0
-4
No files found.
app/models/blob.rb
View file @
b73b1679
...
...
@@ -60,6 +60,9 @@ class Blob < SimpleDelegator
size
&&
truncated?
end
# Returns the size of the file that this blob represents. If this blob is an
# LFS pointer, this is the size of the file stored in LFS. Otherwise, this is
# the size of the blob itself.
def
raw_size
if
valid_lfs_pointer?
lfs_size
...
...
@@ -68,6 +71,10 @@ class Blob < SimpleDelegator
end
end
# Returns whether the file that this blob represents is binary. If this blob is
# an LFS pointer, we assume the file stored in LFS is binary, unless a
# text-based rich blob viewer matched on the file's extension. Otherwise, this
# depends on the type of the blob itself.
def
raw_binary?
if
valid_lfs_pointer?
if
rich_viewer
...
...
@@ -107,7 +114,7 @@ class Blob < SimpleDelegator
def
rich_viewer
return
@rich_viewer
if
defined?
(
@rich_viewer
)
@rich_viewer
||
=
rich_viewer_class
&
.
new
(
self
)
@rich_viewer
=
rich_viewer_class
&
.
new
(
self
)
end
def
rendered_as_text?
(
ignore_errors:
true
)
...
...
@@ -135,19 +142,18 @@ class Blob < SimpleDelegator
end
end
def
rich_viewers_classes
if
valid_lfs_pointer?
RICH_VIEWERS
elsif
binary?
RICH_VIEWERS
.
select
(
&
:binary?
)
else
# text
RICH_VIEWERS
.
select
(
&
:text?
)
end
end
def
rich_viewer_class
return
if
invalid_lfs_pointer?
||
empty?
rich_viewers_classes
.
find
{
|
viewer_class
|
viewer_class
.
can_render?
(
self
)
}
classes
=
if
valid_lfs_pointer?
RICH_VIEWERS
elsif
binary?
RICH_VIEWERS
.
select
(
&
:binary?
)
else
# text
RICH_VIEWERS
.
select
(
&
:text?
)
end
classes
.
find
{
|
viewer_class
|
viewer_class
.
can_render?
(
self
)
}
end
end
lib/gitlab/git/blob.rb
View file @
b73b1679
...
...
@@ -109,10 +109,6 @@ module Gitlab
@binary
.
nil?
?
super
:
@binary
==
true
end
def
empty?
!
data
||
data
==
''
end
def
data
encode!
@data
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