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
31e48408
Commit
31e48408
authored
Mar 17, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Find tree readme lazily.
parent
88f9ed3d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
20 deletions
+19
-20
tree.rb
app/models/tree.rb
+19
-20
No files found.
app/models/tree.rb
View file @
31e48408
class
Tree
include
Gitlab
::
MarkdownHelper
attr_accessor
:entries
,
:readme
attr_accessor
:entries
def
initialize
(
repository
,
sha
,
path
=
'/'
)
path
=
'/'
if
path
.
blank?
git_repo
=
repository
.
raw_repository
@entries
=
Gitlab
::
Git
::
Tree
.
where
(
git_repo
,
sha
,
path
)
end
def
readme
return
@readme
if
defined?
(
@readme
)
available_readmes
=
@blobs
.
select
(
&
:readme?
)
available_readmes
=
@entries
.
select
(
&
:readme?
)
if
available_readmes
.
count
>
0
# If there is more than 1 readme in tree, find readme which is supported
# by markup renderer.
if
available_readmes
.
length
>
1
supported_readmes
=
available_readmes
.
select
do
|
readme
|
previewable?
(
readme
.
name
)
end
# Take the first supported readme, or the first available readme, if we
# don't support any of them
readme_tree
=
supported_readmes
.
first
||
available_readmes
.
first
else
readme_tree
=
available_readmes
.
first
end
readme_path
=
path
==
'/'
?
readme_tree
.
name
:
File
.
join
(
path
,
readme_tree
.
name
)
@readme
=
Gitlab
::
Git
::
Blob
.
find
(
git_repo
,
sha
,
readme_path
)
if
available_readmes
.
count
==
0
return
@readme
=
nil
end
# Take the first previewable readme, or the first available readme, if we
# can't preview any of them
readme_tree
=
available_readmes
.
find
do
|
readme
|
previewable?
(
readme
.
name
)
end
||
available_readmes
.
first
readme_path
=
path
==
'/'
?
readme_tree
.
name
:
File
.
join
(
path
,
readme_tree
.
name
)
@readme
=
Gitlab
::
Git
::
Blob
.
find
(
git_repo
,
sha
,
readme_path
)
end
def
trees
...
...
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