diff options
author | Rebeca Méndez <scullymb@gmail.com> | 2016-08-29 17:23:40 +0200 |
---|---|---|
committer | Rebeca Méndez <scullymb@gmail.com> | 2016-11-12 10:00:39 +0100 |
commit | 5c966f70fb218d6f4de0f888733604293f36c33e (patch) | |
tree | ecb15585624aaa4c266345e5e65d447f474b817a /app/models/tree.rb | |
parent | 6eeff67c6e03233d4480a55d05d4e0f1a88aef4c (diff) | |
download | gitlab-ce-5c966f70fb218d6f4de0f888733604293f36c33e.tar.gz |
Issue #4270: Recursive option for files through API
Diffstat (limited to 'app/models/tree.rb')
-rw-r--r-- | app/models/tree.rb | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/app/models/tree.rb b/app/models/tree.rb index 7c4ed6e393b..2d1d68dbd81 100644 --- a/app/models/tree.rb +++ b/app/models/tree.rb @@ -3,15 +3,16 @@ class Tree attr_accessor :repository, :sha, :path, :entries - def initialize(repository, sha, path = '/') + def initialize(repository, sha, path = '/', recursive: false) path = '/' if path.blank? @repository = repository @sha = sha @path = path + @recursive = recursive git_repo = @repository.raw_repository - @entries = Gitlab::Git::Tree.where(git_repo, @sha, @path) + @entries = get_entries(git_repo, @sha, @path, recursive: @recursive) end def readme @@ -58,4 +59,21 @@ class Tree def sorted_entries trees + blobs + submodules end + + private + + def get_entries(git_repo, sha, path, recursive: false) + current_path_entries = Gitlab::Git::Tree.where(git_repo, sha, path) + ordered_entries = [] + + current_path_entries.each do |entry| + ordered_entries << entry + + if recursive && entry.dir? + ordered_entries.concat(get_entries(git_repo, sha, entry.path, recursive: true)) + end + end + + ordered_entries + end end |