BigW Consortium Gitlab

tree.rb 654 Bytes
Newer Older
1
class Tree
2
  attr_accessor :entries, :readme
3

4 5 6 7 8 9
  def initialize(repository, sha, path = '/')
    path = '/' if path.blank?
    git_repo = repository.raw_repository
    @entries = Gitlab::Git::Tree.where(git_repo, sha, path)

    if readme_tree = @entries.find(&:readme?)
10 11
      readme_path = path == '/' ? readme_tree.name : File.join(path, readme_tree.name)
      @readme = Gitlab::Git::Blob.find(git_repo, sha, readme_path)
12
    end
13
  end
gitlabhq committed
14

15 16
  def trees
    @entries.select(&:dir?)
gitlabhq committed
17
  end
18

19 20 21
  def blobs
    @entries.select(&:file?)
  end
22

23 24
  def submodules
    @entries.select(&:submodule?)
25
  end
26 27 28 29

  def sorted_entries
    trees + blobs + submodules
  end
30
end