2014-09-02 18:07:02 +05:30
|
|
|
class Tree
|
2015-09-11 14:41:01 +05:30
|
|
|
include Gitlab::MarkupHelper
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
attr_accessor :repository, :sha, :path, :entries
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
def initialize(repository, sha, path = '/')
|
|
|
|
path = '/' if path.blank?
|
2015-09-11 14:41:01 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
@repository = repository
|
|
|
|
@sha = sha
|
|
|
|
@path = path
|
|
|
|
|
|
|
|
git_repo = @repository.raw_repository
|
|
|
|
@entries = Gitlab::Git::Tree.where(git_repo, @sha, @path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def readme
|
|
|
|
return @readme if defined?(@readme)
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-01-14 18:37:52 +05:30
|
|
|
# Take the first previewable readme, or return nil if none is available or
|
|
|
|
# we can't preview any of them
|
|
|
|
readme_tree = blobs.find do |blob|
|
|
|
|
blob.readme? && (previewable?(blob.name) || plain?(blob.name))
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2016-01-14 18:37:52 +05:30
|
|
|
if readme_tree.nil?
|
2015-09-11 14:41:01 +05:30
|
|
|
return @readme = nil
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
readme_path = path == '/' ? readme_tree.name : File.join(path, readme_tree.name)
|
|
|
|
|
|
|
|
git_repo = repository.raw_repository
|
|
|
|
@readme = Gitlab::Git::Blob.find(git_repo, sha, readme_path)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def trees
|
|
|
|
@entries.select(&:dir?)
|
|
|
|
end
|
|
|
|
|
|
|
|
def blobs
|
|
|
|
@entries.select(&:file?)
|
|
|
|
end
|
|
|
|
|
|
|
|
def submodules
|
|
|
|
@entries.select(&:submodule?)
|
|
|
|
end
|
|
|
|
|
|
|
|
def sorted_entries
|
|
|
|
trees + blobs + submodules
|
|
|
|
end
|
|
|
|
end
|